Source code
Description: source: package: org.apache.commons.configuration2.reloading, class: ManagedReloadingDetector

    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 *     https://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 JMX management.
    025 */
    026public class ManagedReloadingDetector implements ReloadingDetector, ManagedReloadingDetectorMBean {
    027
    028    /** The logger. */
    029    private final Log log = LogFactory.getLog(ManagedReloadingDetector.class);
    030
    031    /** A flag whether a reload is required. */
    032    private volatile boolean reloadingRequired;
    033
    034    /**
    035     * Constructs a new instance.
    036     */
    037    public ManagedReloadingDetector() {
    038        // empty
    039    }
    040
    041    /**
    042     * Checks whether reloading is required. This implementation checks whether the {@code refresh()} method has been
    043     * invoked.
    044     *
    045     * @return a flag whether reloading is required
    046     */
    047    @Override
    048    public boolean isReloadingRequired() {
    049        return reloadingRequired;
    050    }
    051
    052    /**
    053     * Tells this strategy that the monitored configuration file should be refreshed. This method will typically be called
    054     * from outside (through an exposed MBean) on behalf of an administrator.
    055     *
    056     * @see org.apache.commons.configuration2.reloading.ManagedReloadingDetectorMBean#refresh()
    057     */
    058    @Override
    059    public void refresh() {
    060        log.info("Reloading configuration.");
    061        reloadingRequired = true;
    062    }
    063
    064    /**
    065     * {@inheritDoc} This implementation resets the internal flag indicating that a reload should be performed.
    066     */
    067    @Override
    068    public void reloadingPerformed() {
    069        reloadingRequired = false;
    070    }
    071}