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 */
017package org.apache.logging.log4j.core.util;
018
019import java.util.List;
020
021import org.apache.logging.log4j.core.config.Configuration;
022import org.apache.logging.log4j.core.config.ConfigurationListener;
023import org.apache.logging.log4j.core.config.Reconfigurable;
024
025/**
026 * Watches for changes in a Source and performs an action when it is modified.
027 *
028 * @see WatchManager
029 */
030public interface Watcher {
031
032    String CATEGORY = "Watcher";
033    String ELEMENT_TYPE = "watcher";
034
035    /**
036     * Returns the list of listeners for this configuration.
037     * @return The list of listeners.
038     */
039    List<ConfigurationListener> getListeners();
040
041    /**
042     * Called when the configuration has been modified.
043     * @param source The location of the configuration that was modified.
044     */
045    void modified();
046
047    /**
048     * Periodically called to determine if the configuration has been modified.
049     * @return true if the configuration was modified, false otherwise.
050     */
051    boolean isModified();
052
053    /**
054     * Returns the time the source was last modified or 0 if it is not available.
055     * @return the time the soruce was last modified.
056     */
057    long getLastModified();
058
059    /**
060     * Called when the Watcher is registered.
061     * @param source the Source that is being watched.
062     */
063    void watching(Source source);
064
065    /**
066     * Returns the Source being monitored.
067     * @return the Source.
068     */
069    Source getSource();
070
071    /**
072     * Creates a new Watcher by copying the original and using the new Reconfigurable and listeners.
073     * @param reconfigurable The Reconfigurable.
074     * @param listeners the listeners.
075     * @param lastModifiedMillis The time the resource was last modified in milliseconds.
076     * @return A new Watcher.
077     */
078    Watcher newWatcher(Reconfigurable reconfigurable, List<ConfigurationListener> listeners, long lastModifiedMillis);
079}