Class DefaultFileMonitor
java.lang.Object
org.apache.commons.vfs.impl.DefaultFileMonitor
- All Implemented Interfaces:
Runnable, FileMonitor
A polling
The DefaultFileMonitor is a Thread based polling file system monitor with a 1 second delay.
Design: There is a Map of monitors known as FileMonitorAgents. With the thread running, each FileMonitorAgent object is asked to "check" on the file it is responsible for. To do this check, the cache is cleared.
New files are detected during each "check" as each file does a check for new children. If new children are found, create events are fired recursively if recursive descent is enabled. For performance reasons, added a delay that increases as the number of files monitored increases. The default is a delay of 1 second for every 1000 files processed.
Example usage:
FileMonitor implementation.The DefaultFileMonitor is a Thread based polling file system monitor with a 1 second delay.
Design: There is a Map of monitors known as FileMonitorAgents. With the thread running, each FileMonitorAgent object is asked to "check" on the file it is responsible for. To do this check, the cache is cleared.
- If the file existed before the refresh and it no longer exists, a delete event is fired.
- If the file existed before the refresh and it still exists, check the last modified timestamp to see if that has changed.
- If it has, fire a change event.
New files are detected during each "check" as each file does a check for new children. If new children are found, create events are fired recursively if recursive descent is enabled. For performance reasons, added a delay that increases as the number of files monitored increases. The default is a delay of 1 second for every 1000 files processed.
Example usage:
FileSystemManager fsManager = VFS.getManager();
FileObject listendir = fsManager.resolveFile("/home/username/monitored/");
DefaultFileMonitor fm = new DefaultFileMonitor(new CustomFileListener());
fm.setRecursive(true);
fm.addFile(listendir);
fm.start();
(where CustomFileListener is a class that implements the FileListener
interface.)- Version:
- $Revision: 484943 $ $Date: 2006-12-09 08:42:06 +0100 (Sat, 09 Dec 2006) $
- Author:
- Christopher Ottley
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddFile(FileObject file) Adds a file to be monitored.intget the number of files to check per runlonggetDelay()Get the delay between runsbooleanAccess method to get the recursive setting when adding files for monitoring.protected voidqueueAddFile(FileObject file) Queues a file for addition to be monitored.protected voidqueueRemoveFile(FileObject file) Queues a file for removal from being monitored.voidremoveFile(FileObject file) Removes a file from being monitored.voidrun()Asks the agent for each file being monitored to check its file for changes.voidsetChecksPerRun(int checksPerRun) set the number of files to check per run.voidsetDelay(long delay) Set the delay between runsvoidsetRecursive(boolean newRecursive) Access method to set the recursive setting when adding files for monitoring.voidstart()Starts monitoring the files that have been added.voidstop()Stops monitoring the files that have been added.
-
Constructor Details
-
DefaultFileMonitor
-
-
Method Details
-
isRecursive
public boolean isRecursive()Access method to get the recursive setting when adding files for monitoring. -
setRecursive
public void setRecursive(boolean newRecursive) Access method to set the recursive setting when adding files for monitoring. -
addFile
Adds a file to be monitored.- Specified by:
addFilein interfaceFileMonitor
-
removeFile
Removes a file from being monitored.- Specified by:
removeFilein interfaceFileMonitor
-
queueRemoveFile
Queues a file for removal from being monitored. -
getDelay
public long getDelay()Get the delay between runs -
setDelay
public void setDelay(long delay) Set the delay between runs -
getChecksPerRun
public int getChecksPerRun()get the number of files to check per run -
setChecksPerRun
public void setChecksPerRun(int checksPerRun) set the number of files to check per run. a additional delay will be added if there are more files to check- Parameters:
checksPerRun- a value less than 1 will disable this feature
-
queueAddFile
Queues a file for addition to be monitored. -
start
public void start()Starts monitoring the files that have been added. -
stop
public void stop()Stops monitoring the files that have been added. -
run
-