|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.commons.vfs.impl.DefaultFileMonitor
public class DefaultFileMonitor
A polling FileMonitor
implementation.
The DefaultFileMonitor is a Thread based polling file system monitor with a 1
second delay.
Design:
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.)
Nested Class Summary | |
---|---|
private static class |
DefaultFileMonitor.FileMonitorAgent
File monitor agent. |
Field Summary | |
---|---|
private java.util.Stack |
addStack
File objects to be added to the monitor map. |
private int |
checksPerRun
Set the number of files to check until a delay will be inserted |
private long |
delay
Set the delay between checks |
private java.util.Stack |
deleteStack
File objects to be removed from the monitor map. |
private FileListener |
listener
A listener object that if set, is notified on file creation and deletion. |
private static org.apache.commons.logging.Log |
log
|
private java.util.Map |
monitorMap
Map from FileName to FileObject being monitored. |
private java.lang.Thread |
monitorThread
The low priority thread used for checking the files being monitored. |
private boolean |
recursive
A flag used to determine if adding files to be monitored should be recursive. |
private boolean |
shouldRun
A flag used to determine if the monitor thread should be running. |
Constructor Summary | |
---|---|
DefaultFileMonitor(FileListener listener)
|
Method Summary | |
---|---|
private void |
_addFile(FileObject file)
Adds a file to be monitored. |
void |
addFile(FileObject file)
Adds a file to be monitored. |
int |
getChecksPerRun()
get the number of files to check per run |
long |
getDelay()
Get the delay between runs |
(package private) FileListener |
getFileListener()
Access method to get the current FileListener object notified when there are changes with the files added. |
boolean |
isRecursive()
Access method to get the recursive setting when adding files for monitoring. |
protected void |
queueAddFile(FileObject file)
Queues a file for addition to be monitored. |
protected void |
queueRemoveFile(FileObject file)
Queues a file for removal from being monitored. |
void |
removeFile(FileObject file)
Removes a file from being monitored. |
void |
run()
Asks the agent for each file being monitored to check its file for changes. |
void |
setChecksPerRun(int checksPerRun)
set the number of files to check per run. |
void |
setDelay(long delay)
Set the delay between runs |
void |
setRecursive(boolean newRecursive)
Access method to set the recursive setting when adding files for monitoring. |
void |
start()
Starts monitoring the files that have been added. |
void |
stop()
Stops monitoring the files that have been added. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final org.apache.commons.logging.Log log
private final java.util.Map monitorMap
private java.lang.Thread monitorThread
private java.util.Stack deleteStack
private java.util.Stack addStack
private boolean shouldRun
private boolean recursive
private long delay
private int checksPerRun
private final FileListener listener
Constructor Detail |
---|
public DefaultFileMonitor(FileListener listener)
Method Detail |
---|
public boolean isRecursive()
public void setRecursive(boolean newRecursive)
FileListener getFileListener()
public void addFile(FileObject file)
addFile
in interface FileMonitor
private void _addFile(FileObject file)
public void removeFile(FileObject file)
removeFile
in interface FileMonitor
protected void queueRemoveFile(FileObject file)
public long getDelay()
public void setDelay(long delay)
public int getChecksPerRun()
public void setChecksPerRun(int checksPerRun)
checksPerRun
- a value less than 1 will disable this featureprotected void queueAddFile(FileObject file)
public void start()
public void stop()
public void run()
run
in interface java.lang.Runnable
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |