public class Scanner extends AbstractLifeCycle
Modifier and Type | Class and Description |
---|---|
static interface |
Scanner.BulkListener |
static interface |
Scanner.DiscreteListener |
static interface |
Scanner.Listener
Listener
Marker for notifications re file changes.
|
static class |
Scanner.Notification |
(package private) static class |
Scanner.PathMatcherSet
PathMatcherSet
A set of PathMatchers for testing Paths against path matching patterns via
|
static interface |
Scanner.ScanCycleListener
Listener that notifies when a scan has started and when it has ended.
|
static interface |
Scanner.ScanListener |
(package private) static class |
Scanner.TimeNSize
TimeNSize
Metadata about a file: Last modified time and file size.
|
(package private) class |
Scanner.Visitor
Visitor
A FileVisitor for walking a subtree of paths.
|
AbstractLifeCycle.AbstractLifeCycleListener
Modifier and Type | Field and Description |
---|---|
private static int |
__scannerId |
private java.util.Map<java.lang.String,Scanner.TimeNSize> |
_currentScan |
private java.io.FilenameFilter |
_filter |
private java.util.List<Scanner.Listener> |
_listeners |
private java.util.Map<java.lang.String,Scanner.Notification> |
_notifications |
private java.util.Map<java.lang.String,Scanner.TimeNSize> |
_prevScan |
private boolean |
_reportDirs |
private boolean |
_reportExisting |
private boolean |
_running |
private int |
_scanCount |
private int |
_scanDepth |
private int |
_scanInterval |
private java.util.Map<java.nio.file.Path,IncludeExcludeSet<java.nio.file.PathMatcher,java.nio.file.Path>> |
_scannables |
private java.util.TimerTask |
_task |
private java.util.Timer |
_timer |
static int |
DEFAULT_SCAN_DEPTH
When walking a directory, a depth of 1 ensures that
the directory's descendants are visited, not just the
directory itself (as a file).
|
private static Logger |
LOG |
static int |
MAX_SCAN_DEPTH |
Constructor and Description |
---|
Scanner() |
Modifier and Type | Method and Description |
---|---|
IncludeExcludeSet<java.nio.file.PathMatcher,java.nio.file.Path> |
addDirectory(java.nio.file.Path p)
Add a directory to be scanned.
|
void |
addFile(java.nio.file.Path p)
Add a file to be scanned.
|
void |
addListener(Scanner.Listener listener)
Add an added/removed/changed listener
|
void |
addScanDir(java.io.File dir)
Deprecated.
|
void |
doStart()
Start the scanning action.
|
void |
doStop()
Stop the scanning.
|
boolean |
exists(java.lang.String path) |
java.io.FilenameFilter |
getFilenameFilter()
Deprecated.
|
boolean |
getRecursive()
Deprecated.
|
boolean |
getReportDirs() |
boolean |
getReportExistingFilesOnStartup() |
int |
getScanDepth()
Get the scanDepth.
|
java.util.List<java.io.File> |
getScanDirs()
Deprecated.
|
int |
getScanInterval()
Get the scan interval
|
java.util.Set<java.nio.file.Path> |
getScannables() |
java.util.Timer |
newTimer() |
java.util.TimerTask |
newTimerTask() |
void |
removeListener(Scanner.Listener listener)
Remove a registered listener
|
private void |
reportAddition(java.lang.String filename)
Report a file addition to the registered FileAddedListeners
|
private void |
reportBulkChanges(java.util.List<java.lang.String> filenames)
Report the list of filenames for which changes were detected.
|
private void |
reportChange(java.lang.String filename)
Report a file change to the FileChangedListeners
|
private void |
reportDifferences(java.util.Map<java.lang.String,Scanner.TimeNSize> currentScan,
java.util.Map<java.lang.String,Scanner.TimeNSize> oldScan)
Report the adds/changes/removes to the registered listeners
|
private void |
reportRemoval(java.lang.String filename)
Report a file removal to the FileRemovedListeners
|
private void |
reportScanEnd(int cycle)
Call ScanCycleListeners with end of scan.
|
private void |
reportScanStart(int cycle)
Call ScanCycleListeners with start of scan
|
void |
reset()
Clear the list of scannables.
|
void |
scan()
Perform a pass of the scanner and report changes
|
void |
scanFiles()
Scan all of the given paths.
|
void |
schedule() |
void |
setFilenameFilter(java.io.FilenameFilter filter)
Deprecated.
|
void |
setRecursive(boolean recursive)
Deprecated.
|
void |
setReportDirs(boolean dirs)
Set if found directories should be reported.
|
void |
setReportExistingFilesOnStartup(boolean reportExisting)
Whether or not an initial scan will report all files as being
added.
|
void |
setScanDepth(int scanDepth)
Set the scanDepth.
|
void |
setScanDirs(java.util.List<java.io.File> dirs) |
void |
setScanInterval(int scanInterval)
Set the scan interval
|
private void |
warn(java.lang.Object listener,
java.lang.String filename,
java.lang.Throwable th) |
addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, setStopTimeout, start, stop, toString
public static final int DEFAULT_SCAN_DEPTH
public static final int MAX_SCAN_DEPTH
private static final Logger LOG
private static int __scannerId
private int _scanInterval
private int _scanCount
private final java.util.List<Scanner.Listener> _listeners
private final java.util.Map<java.lang.String,Scanner.TimeNSize> _prevScan
private final java.util.Map<java.lang.String,Scanner.TimeNSize> _currentScan
private java.io.FilenameFilter _filter
private final java.util.Map<java.nio.file.Path,IncludeExcludeSet<java.nio.file.PathMatcher,java.nio.file.Path>> _scannables
private volatile boolean _running
private boolean _reportExisting
private boolean _reportDirs
private java.util.Timer _timer
private java.util.TimerTask _task
private int _scanDepth
private final java.util.Map<java.lang.String,Scanner.Notification> _notifications
public int getScanInterval()
public void setScanInterval(int scanInterval)
scanInterval
- pause between scans in seconds, or 0 for no scan after the initial scan.public void setScanDirs(java.util.List<java.io.File> dirs)
@Deprecated public void addScanDir(java.io.File dir)
public void addFile(java.nio.file.Path p) throws java.io.IOException
p
- the Path of the file to scan.java.io.IOException
public IncludeExcludeSet<java.nio.file.PathMatcher,java.nio.file.Path> addDirectory(java.nio.file.Path p) throws java.io.IOException
p
- the directory to scan.java.io.IOException
@Deprecated public java.util.List<java.io.File> getScanDirs()
public java.util.Set<java.nio.file.Path> getScannables()
@Deprecated public void setRecursive(boolean recursive)
recursive
- True if scanning is recursivesetScanDepth(int)
@Deprecated public boolean getRecursive()
getScanDepth()
public int getScanDepth()
public void setScanDepth(int scanDepth)
scanDepth
- the scanDepth to set@Deprecated public void setFilenameFilter(java.io.FilenameFilter filter)
filter
- the filename filter to use@Deprecated public java.io.FilenameFilter getFilenameFilter()
public void setReportExistingFilesOnStartup(boolean reportExisting)
reportExisting
- if true, all files found on initial scan will be
reported as being added, otherwise notpublic boolean getReportExistingFilesOnStartup()
public void setReportDirs(boolean dirs)
dirs
- true to report directory changes as wellpublic boolean getReportDirs()
public void addListener(Scanner.Listener listener)
listener
- the listener to addpublic void removeListener(Scanner.Listener listener)
listener
- the Listener to be removedpublic void doStart()
doStart
in class AbstractLifeCycle
public java.util.TimerTask newTimerTask()
public java.util.Timer newTimer()
public void schedule()
public void doStop()
doStop
in class AbstractLifeCycle
public void reset()
public boolean exists(java.lang.String path)
path
- tests if the path existspublic void scan()
public void scanFiles()
private void reportDifferences(java.util.Map<java.lang.String,Scanner.TimeNSize> currentScan, java.util.Map<java.lang.String,Scanner.TimeNSize> oldScan)
currentScan
- the info from the most recent passoldScan
- info from the previous passprivate void warn(java.lang.Object listener, java.lang.String filename, java.lang.Throwable th)
private void reportAddition(java.lang.String filename)
filename
- the filenameprivate void reportRemoval(java.lang.String filename)
filename
- the filenameprivate void reportChange(java.lang.String filename)
filename
- the filenameprivate void reportBulkChanges(java.util.List<java.lang.String> filenames)
filenames
- names of all files added/changed/removedprivate void reportScanStart(int cycle)
private void reportScanEnd(int cycle)