public class DefaultFileMonitor extends Object implements Runnable, FileMonitor
FileMonitor
implementation.
The DefaultFileMonitor is a Thread based polling file system monitor with a 1 second delay.
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.
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.)
Constructor and Description |
---|
DefaultFileMonitor(FileListener listener)
Creates a new instance with the given listener.
|
Modifier and Type | Method and Description |
---|---|
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.
|
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.
|
public DefaultFileMonitor(FileListener listener)
listener
- the listener.public boolean isRecursive()
public void setRecursive(boolean newRecursive)
newRecursive
- true if monitoring should be enabled for children.public void addFile(FileObject file)
addFile
in interface FileMonitor
file
- The FileObject to monitor.public void removeFile(FileObject file)
removeFile
in interface FileMonitor
file
- The FileObject to remove from monitoring.protected void queueRemoveFile(FileObject file)
file
- The FileObject to be removed from being monitored.public long getDelay()
public void setDelay(long delay)
delay
- The delay period.public int getChecksPerRun()
public void setChecksPerRun(int checksPerRun)
checksPerRun
- a value less than 1 will disable this featureprotected void queueAddFile(FileObject file)
file
- The FileObject to add.public void start()
public void stop()
Copyright © 2002–2020 The Apache Software Foundation. All rights reserved.