Class WatchManager
- java.lang.Object
-
- org.apache.logging.log4j.core.AbstractLifeCycle
-
- org.apache.logging.log4j.core.util.WatchManager
-
- All Implemented Interfaces:
LifeCycle,LifeCycle2
public class WatchManager extends AbstractLifeCycle
ManagesFileWatchers.- See Also:
FileWatcher,ConfigurationScheduler
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classWatchManager.ConfigurationMonitorprivate static classWatchManager.LocalUUIDprivate classWatchManager.WatchRunnable-
Nested classes/interfaces inherited from interface org.apache.logging.log4j.core.LifeCycle
LifeCycle.State
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<WatchEventService>eventServiceListprivate java.util.concurrent.ScheduledFuture<?>futureprivate java.util.UUIDidprivate intintervalSecondsprivate static Loggerloggerprivate ConfigurationSchedulerschedulerprivate java.util.concurrent.ConcurrentMap<Source,WatchManager.ConfigurationMonitor>watchers-
Fields inherited from class org.apache.logging.log4j.core.AbstractLifeCycle
DEFAULT_STOP_TIMEOUT, DEFAULT_STOP_TIMEUNIT, LOGGER
-
-
Constructor Summary
Constructors Constructor Description WatchManager(ConfigurationScheduler scheduler)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidcheckFiles()java.util.Map<Source,Watcher>getConfigurationWatchers()Return the ConfigurationWaatchers.java.util.UUIDgetId()intgetIntervalSeconds()Gets how often this manager checks for file modifications.java.util.Map<java.io.File,FileWatcher>getWatchers()Deprecated.use getConfigurationWatchers.booleanhasEventListeners()private java.lang.StringmillisToString(long millis)voidreset()Resets all file monitors to their current last modified time.voidreset(java.io.File file)Resets the file monitor for the given file being watched to its current last modified time.voidreset(Source source)Resets the configuration monitor for the given file being watched to its current last modified time.voidsetIntervalSeconds(int intervalSeconds)voidstart()booleanstop(long timeout, java.util.concurrent.TimeUnit timeUnit)Blocks until all tasks have completed execution after a shutdown request, or the timeout occurs, or the current thread is interrupted, whichever happens first.java.lang.StringtoString()voidunwatch(Source source)Unwatches the given file.voidunwatchFile(java.io.File file)Unwatches the given file.voidwatch(Source source, Watcher watcher)Watches the given file.voidwatchFile(java.io.File file, FileWatcher fileWatcher)Watches the given file.-
Methods inherited from class org.apache.logging.log4j.core.AbstractLifeCycle
equalsImpl, getState, getStatusLogger, hashCodeImpl, initialize, isInitialized, isStarted, isStarting, isStopped, isStopping, setStarted, setStarting, setState, setStopped, setStopping, stop, stop
-
-
-
-
Field Detail
-
logger
private static Logger logger
-
watchers
private final java.util.concurrent.ConcurrentMap<Source,WatchManager.ConfigurationMonitor> watchers
-
intervalSeconds
private int intervalSeconds
-
future
private java.util.concurrent.ScheduledFuture<?> future
-
scheduler
private final ConfigurationScheduler scheduler
-
eventServiceList
private final java.util.List<WatchEventService> eventServiceList
-
id
private final java.util.UUID id
-
-
Constructor Detail
-
WatchManager
public WatchManager(ConfigurationScheduler scheduler)
-
-
Method Detail
-
checkFiles
public void checkFiles()
-
getConfigurationWatchers
public java.util.Map<Source,Watcher> getConfigurationWatchers()
Return the ConfigurationWaatchers.- Returns:
- the ConfigurationWatchers.
- Since:
- 2.11.2
-
getId
public java.util.UUID getId()
-
getIntervalSeconds
public int getIntervalSeconds()
Gets how often this manager checks for file modifications.- Returns:
- how often, in seconds, this manager checks for file modifications.
-
getWatchers
@Deprecated public java.util.Map<java.io.File,FileWatcher> getWatchers()
Deprecated.use getConfigurationWatchers.Returns a Map of the file watchers.- Returns:
- A Map of the file watchers.
-
hasEventListeners
public boolean hasEventListeners()
-
millisToString
private java.lang.String millisToString(long millis)
-
reset
public void reset()
Resets all file monitors to their current last modified time. If this manager does not watch any file, nothing happens.This allows you to start, stop, reset and start again a manager, without triggering file modified events if the a watched file has changed during the period of time when the manager was stopped.
- Since:
- 2.11.0
-
reset
public void reset(java.io.File file)
Resets the file monitor for the given file being watched to its current last modified time. If this manager does not watch the given file, nothing happens.This allows you to start, stop, reset and start again a manager, without triggering file modified events if the given watched file has changed during the period of time when the manager was stopped.
- Parameters:
file- the file for the monitor to reset.- Since:
- 2.11.0
-
reset
public void reset(Source source)
Resets the configuration monitor for the given file being watched to its current last modified time. If this manager does not watch the given configuration, nothing happens.This allows you to start, stop, reset and start again a manager, without triggering file modified events if the given watched configuration has changed during the period of time when the manager was stopped.
- Parameters:
source- the Source for the monitor to reset.- Since:
- 2.12.0
-
setIntervalSeconds
public void setIntervalSeconds(int intervalSeconds)
-
start
public void start()
- Specified by:
startin interfaceLifeCycle- Overrides:
startin classAbstractLifeCycle
-
stop
public boolean stop(long timeout, java.util.concurrent.TimeUnit timeUnit)Description copied from interface:LifeCycle2Blocks until all tasks have completed execution after a shutdown request, or the timeout occurs, or the current thread is interrupted, whichever happens first.- Specified by:
stopin interfaceLifeCycle2- Overrides:
stopin classAbstractLifeCycle- Parameters:
timeout- the maximum time to waittimeUnit- the time unit of the timeout argument- Returns:
- true if the receiver was stopped cleanly and normally, false otherwise.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
unwatch
public void unwatch(Source source)
Unwatches the given file.- Parameters:
source- the Source to stop watching. the file to stop watching.- Since:
- 2.12.0
-
unwatchFile
public void unwatchFile(java.io.File file)
Unwatches the given file.- Parameters:
file- the file to stop watching.- Since:
- 2.11.0
-
watch
public void watch(Source source, Watcher watcher)
Watches the given file.- Parameters:
source- the source to watch.watcher- the watcher to notify of file changes.
-
watchFile
public void watchFile(java.io.File file, FileWatcher fileWatcher)Watches the given file.- Parameters:
file- the file to watch.fileWatcher- the watcher to notify of file changes.
-
-