View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.commons.configuration2.reloading;
19  
20  import org.apache.commons.logging.Log;
21  import org.apache.commons.logging.LogFactory;
22  
23  /**
24   * A strategy to reload configuration based on management requests. Designed for JMX management.
25   */
26  public class ManagedReloadingDetector implements ReloadingDetector, ManagedReloadingDetectorMBean {
27      /** The logger. */
28      private final Log log = LogFactory.getLog(ManagedReloadingDetector.class);
29  
30      /** A flag whether a reload is required. */
31      private volatile boolean reloadingRequired;
32  
33      /**
34       * {@inheritDoc} This implementation resets the internal flag indicating that a reload should be performed.
35       */
36      @Override
37      public void reloadingPerformed() {
38          reloadingRequired = false;
39      }
40  
41      /**
42       * Checks whether reloading is required. This implementation checks whether the {@code refresh()} method has been
43       * invoked.
44       *
45       * @return a flag whether reloading is required
46       */
47      @Override
48      public boolean isReloadingRequired() {
49          return reloadingRequired;
50      }
51  
52      /**
53       * Tells this strategy that the monitored configuration file should be refreshed. This method will typically be called
54       * from outside (through an exposed MBean) on behalf of an administrator.
55       *
56       * @see org.apache.commons.configuration2.reloading.ManagedReloadingDetectorMBean#refresh()
57       */
58      @Override
59      public void refresh() {
60          log.info("Reloading configuration.");
61          reloadingRequired = true;
62      }
63  }