Package org.apache.commons.io.monitor
Class FileAlterationMonitor
- java.lang.Object
-
- org.apache.commons.io.monitor.FileAlterationMonitor
-
- All Implemented Interfaces:
java.lang.Runnable
public final class FileAlterationMonitor extends java.lang.Object implements java.lang.RunnableA runnable that spawns a monitoring thread triggering any registeredFileAlterationObserverat a specified interval.- Since:
- 2.0
- See Also:
FileAlterationObserver
-
-
Constructor Summary
Constructors Constructor Description FileAlterationMonitor()Constructs a monitor with a default interval of 10 seconds.FileAlterationMonitor(long interval)Constructs a monitor with the specified interval.FileAlterationMonitor(long interval, java.util.Collection<FileAlterationObserver> observers)Constructs a monitor with the specified interval and collection of observers.FileAlterationMonitor(long interval, FileAlterationObserver... observers)Constructs a monitor with the specified interval and set of observers.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddObserver(FileAlterationObserver observer)Adds a file system observer to this monitor.longgetInterval()Returns the interval.java.lang.Iterable<FileAlterationObserver>getObservers()Returns the set ofFileAlterationObserverregistered with this monitor.voidremoveObserver(FileAlterationObserver observer)Removes a file system observer from this monitor.voidrun()Runs this monitor.voidsetThreadFactory(java.util.concurrent.ThreadFactory threadFactory)Sets the thread factory.voidstart()Starts monitoring.voidstop()Stops monitoring.voidstop(long stopInterval)Stops monitoring.
-
-
-
Constructor Detail
-
FileAlterationMonitor
public FileAlterationMonitor()
Constructs a monitor with a default interval of 10 seconds.
-
FileAlterationMonitor
public FileAlterationMonitor(long interval)
Constructs a monitor with the specified interval.- Parameters:
interval- The amount of time in milliseconds to wait between checks of the file system.
-
FileAlterationMonitor
public FileAlterationMonitor(long interval, java.util.Collection<FileAlterationObserver> observers)Constructs a monitor with the specified interval and collection of observers.- Parameters:
interval- The amount of time in milliseconds to wait between checks of the file system.observers- The collection of observers to add to the monitor.- Since:
- 2.9.0
-
FileAlterationMonitor
public FileAlterationMonitor(long interval, FileAlterationObserver... observers)Constructs a monitor with the specified interval and set of observers.- Parameters:
interval- The amount of time in milliseconds to wait between checks of the file system.observers- The set of observers to add to the monitor.
-
-
Method Detail
-
getInterval
public long getInterval()
Returns the interval.- Returns:
- the interval
-
setThreadFactory
public void setThreadFactory(java.util.concurrent.ThreadFactory threadFactory)
Sets the thread factory.- Parameters:
threadFactory- the thread factory
-
addObserver
public void addObserver(FileAlterationObserver observer)
Adds a file system observer to this monitor.- Parameters:
observer- The file system observer to add
-
removeObserver
public void removeObserver(FileAlterationObserver observer)
Removes a file system observer from this monitor.- Parameters:
observer- The file system observer to remove
-
getObservers
public java.lang.Iterable<FileAlterationObserver> getObservers()
Returns the set ofFileAlterationObserverregistered with this monitor.- Returns:
- The set of
FileAlterationObserver
-
start
public void start() throws java.lang.ExceptionStarts monitoring.- Throws:
java.lang.Exception- if an error occurs initializing the observer
-
stop
public void stop() throws java.lang.ExceptionStops monitoring.- Throws:
java.lang.Exception- if an error occurs initializing the observer
-
stop
public void stop(long stopInterval) throws java.lang.ExceptionStops monitoring.- Parameters:
stopInterval- the amount of time in milliseconds to wait for the thread to finish. A value of zero will wait until the thread is finished (seeThread.join(long)).- Throws:
java.lang.Exception- if an error occurs initializing the observer- Since:
- 2.1
-
run
public void run()
Runs this monitor.- Specified by:
runin interfacejava.lang.Runnable
-
-