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  package org.apache.logging.log4j.core.util;
18  
19  import java.util.List;
20  
21  import org.apache.logging.log4j.core.config.Configuration;
22  import org.apache.logging.log4j.core.config.ConfigurationListener;
23  import org.apache.logging.log4j.core.config.Reconfigurable;
24  
25  /**
26   * Watches for changes in a Source and performs an action when it is modified.
27   *
28   * @see WatchManager
29   */
30  public interface Watcher {
31  
32      String CATEGORY = "Watcher";
33      String ELEMENT_TYPE = "watcher";
34  
35      /**
36       * Returns the list of listeners for this configuration.
37       * @return The list of listeners.
38       */
39      List<ConfigurationListener> getListeners();
40  
41      /**
42       * Called when the configuration has been modified.
43       * @param source The location of the configuration that was modified.
44       */
45      void modified();
46  
47      /**
48       * Periodically called to determine if the configuration has been modified.
49       * @return true if the configuration was modified, false otherwise.
50       */
51      boolean isModified();
52  
53      /**
54       * Returns the time the source was last modified or 0 if it is not available.
55       * @return the time the soruce was last modified.
56       */
57      long getLastModified();
58  
59      /**
60       * Called when the Watcher is registered.
61       * @param source the Source that is being watched.
62       */
63      void watching(Source source);
64  
65      /**
66       * Returns the Source being monitored.
67       * @return the Source.
68       */
69      Source getSource();
70  
71      /**
72       * Creates a new Watcher by copying the original and using the new Reconfigurable and listeners.
73       * @param reconfigurable The Reconfigurable.
74       * @param listeners the listeners.
75       * @param lastModifiedMillis The time the resource was last modified in milliseconds.
76       * @return A new Watcher.
77       */
78      Watcher newWatcher(Reconfigurable reconfigurable, List<ConfigurationListener> listeners, long lastModifiedMillis);
79  }