Utility for scanning a directory for added, removed and changed
files and reporting these events via registered Listeners.
private volatile boolean _running = false;
public TimeNSize(long lastModified, long size)
Marker for notifications re file changes.
Listener that notifies when a scan has started and when it has ended.
Get the scan interval
- interval between scans in seconds
Set the scan interval
scanInterval pause between scans in seconds, or 0 for no scan after the initial scan.
Set the location of the directory to scan.
- use setScanDirs(List dirs) instead
Get the location of the directory to scan
- use getScanDirs() instead
- the first directory (of
- True if scanning is fully recursive (scandepth==-1)
- See also:
Set the scanDepth.
scanDepth the scanDepth to set
Apply a filter to files found in the scan directory.
Only files matching the filter will be reported as added/changed/removed.
Get any filter applied to files in the scan dir.
- the filename filter
Whether or not an initial scan will report all files as being
reportExisting if true, all files found on initial scan will be
reported as being added, otherwise not
Set if found directories should be reported.
Add an added/removed/changed listener
Remove a registered listener
listener the Listener to be removed
Start the scanning action.
public synchronized void doStop()
Perform a pass of the scanner and report changes
public synchronized void scan ()
Recursively scan all files in the designated directories.
if ((dir != null) && (dir.exists()))
LOG.warn("Error scanning files.", e);
Report the adds/changes/removes to the registered listeners
currentScan the info from the most recent pass
oldScan info from the previous pass
Get last modified time on a single file or recurse if
the file is a directory.
f file or directory
scanInfoMap map of filenames to last modified times
for (int i=0;i<files.length;i++)
LOG.warn("Error scanning watched files", e);
LOG.warn(listener+" failed on '"+filename, th);
Report a file addition to the registered FileAddedListeners
Report a file removal to the FileRemovedListeners
Report a file change to the FileChangedListeners
signal any scan cycle listeners that a scan has started
LOG.warn(listener + " failed on scan start for cycle " + cycle, e);
LOG.warn(listener + " failed on scan end for cycle " + cycle, e);