001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018package org.apache.commons.configuration2.reloading;
019
020import org.apache.commons.logging.Log;
021import org.apache.commons.logging.LogFactory;
022
023/**
024 * A strategy to reload configuration based on management requests. Designed for
025 * JMX management.
026 *
027 * @author Nicolas De loof
028 * @version $Id: ManagedReloadingDetector.java 1624601 2014-09-12 18:04:36Z oheger $
029 */
030public class ManagedReloadingDetector implements ReloadingDetector,
031        ManagedReloadingDetectorMBean
032{
033    /** The logger. */
034    private final Log log = LogFactory.getLog(ManagedReloadingDetector.class);
035
036    /** A flag whether a reload is required. */
037    private volatile boolean reloadingRequired;
038
039    /**
040     * {@inheritDoc} This implementation resets the internal flag indicating
041     * that a reload should be performed.
042     */
043    @Override
044    public void reloadingPerformed()
045    {
046        reloadingRequired = false;
047    }
048
049    /**
050     * Checks whether reloading is required. This implementation checks whether
051     * the {@code refresh()} method has been invoked.
052     *
053     * @return a flag whether reloading is required
054     */
055    @Override
056    public boolean isReloadingRequired()
057    {
058        return reloadingRequired;
059    }
060
061    /**
062     * Tells this strategy that the monitored configuration file should be
063     * refreshed. This method will typically be called from outside (through an
064     * exposed MBean) on behalf of an administrator.
065     *
066     * @see org.apache.commons.configuration2.reloading.ManagedReloadingDetectorMBean#refresh()
067     */
068    @Override
069    public void refresh()
070    {
071        log.info("Reloading configuration.");
072        reloadingRequired = true;
073    }
074}