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