| A polling
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.
With each file delete, the FileMonitorAgent of the parent is asked to
re-build its
list of children, so that they can be accurately checked when there are new
children.
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.)
author: Christopher Ottley version: $Revision: 537938 $ $Date: 2007-05-14 11:26:40 -0700 (Mon, 14 May 2007) $ |