Package org.eclipse.jetty.util
Class Scanner
java.lang.Object
org.eclipse.jetty.util.component.AbstractLifeCycle
org.eclipse.jetty.util.Scanner
- All Implemented Interfaces:
LifeCycle
Scanner
Utility for scanning a directory for added, removed and changed
files and reporting these events via registered Listeners.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfacestatic interfacestatic interfaceListener Marker for notifications re file changes.static enum(package private) static classPathMatcherSet A set of PathMatchers for testing Paths against path matching patterns viastatic interfaceListener that notifies when a scan has started and when it has ended.static interface(package private) static classTimeNSize Metadata about a file: Last modified time and file size.(package private) classVisitor A FileVisitor for walking a subtree of paths.Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
AbstractLifeCycle.AbstractLifeCycleListener -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static intprivate final Map<String, Scanner.TimeNSize> private FilenameFilterprivate final List<Scanner.Listener> private final Map<String, Scanner.Notification> private final Map<String, Scanner.TimeNSize> private booleanprivate booleanprivate booleanprivate intprivate intprivate intprivate final Map<Path, IncludeExcludeSet<PathMatcher, Path>> private TimerTaskprivate Timerstatic final intWhen 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 final Loggerstatic final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddDirectory(Path p) Add a directory to be scanned.voidAdd a file to be scanned.voidaddListener(Scanner.Listener listener) Add an added/removed/changed listenervoidaddScanDir(File dir) Deprecated.voiddoStart()Start the scanning action.voiddoStop()Stop the scanning.booleanDeprecated.booleanDeprecated.booleanbooleanintGet the scanDepth.Deprecated.intGet the scan intervalnewTimer()voidremoveListener(Scanner.Listener listener) Remove a registered listenerprivate voidreportAddition(String filename) Report a file addition to the registered FileAddedListenersprivate voidreportBulkChanges(List<String> filenames) Report the list of filenames for which changes were detected.private voidreportChange(String filename) Report a file change to the FileChangedListenersprivate voidreportDifferences(Map<String, Scanner.TimeNSize> currentScan, Map<String, Scanner.TimeNSize> oldScan) Report the adds/changes/removes to the registered listenersprivate voidreportRemoval(String filename) Report a file removal to the FileRemovedListenersprivate voidreportScanEnd(int cycle) Call ScanCycleListeners with end of scan.private voidreportScanStart(int cycle) Call ScanCycleListeners with start of scanvoidreset()Clear the list of scannables.voidscan()Perform a pass of the scanner and report changesvoidScan all of the given paths.voidschedule()voidsetFilenameFilter(FilenameFilter filter) Deprecated.voidsetRecursive(boolean recursive) Deprecated.voidsetReportDirs(boolean dirs) Set if found directories should be reported.voidsetReportExistingFilesOnStartup(boolean reportExisting) Whether or not an initial scan will report all files as being added.voidsetScanDepth(int scanDepth) Set the scanDepth.voidsetScanDirs(List<File> dirs) voidsetScanInterval(int scanInterval) Set the scan intervalprivate voidMethods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, setStopTimeout, start, stop, toString
-
Field Details
-
DEFAULT_SCAN_DEPTH
public static final int DEFAULT_SCAN_DEPTHWhen walking a directory, a depth of 1 ensures that the directory's descendants are visited, not just the directory itself (as a file).- See Also:
-
MAX_SCAN_DEPTH
public static final int MAX_SCAN_DEPTH- See Also:
-
LOG
-
__scannerId
private static int __scannerId -
_scanInterval
private int _scanInterval -
_scanCount
private int _scanCount -
_listeners
-
_prevScan
-
_currentScan
-
_filter
-
_scannables
-
_running
private volatile boolean _running -
_reportExisting
private boolean _reportExisting -
_reportDirs
private boolean _reportDirs -
_timer
-
_task
-
_scanDepth
private int _scanDepth -
_notifications
-
-
Constructor Details
-
Scanner
public Scanner()
-
-
Method Details
-
getScanInterval
public int getScanInterval()Get the scan interval- Returns:
- interval between scans in seconds
-
setScanInterval
public void setScanInterval(int scanInterval) Set the scan interval- Parameters:
scanInterval- pause between scans in seconds, or 0 for no scan after the initial scan.
-
setScanDirs
-
addScanDir
Deprecated. -
addFile
Add a file to be scanned. The file must not be null, and must exist.- Parameters:
p- the Path of the file to scan.- Throws:
IOException
-
addDirectory
Add a directory to be scanned. The directory must not be null and must exist.- Parameters:
p- the directory to scan.- Returns:
- an IncludeExcludeSet to which the caller can add PathMatcher patterns to match
- Throws:
IOException
-
getScanDirs
Deprecated. -
getScannables
-
setRecursive
Deprecated.- Parameters:
recursive- True if scanning is recursive- See Also:
-
getRecursive
Deprecated.- Returns:
- True if scanning is recursive
- See Also:
-
getScanDepth
public int getScanDepth()Get the scanDepth.- Returns:
- the scanDepth
-
setScanDepth
public void setScanDepth(int scanDepth) Set the scanDepth.- Parameters:
scanDepth- the scanDepth to set
-
setFilenameFilter
Deprecated.Apply a filter to files found in the scan directory. Only files matching the filter will be reported as added/changed/removed.- Parameters:
filter- the filename filter to use
-
getFilenameFilter
Deprecated.Get any filter applied to files in the scan dir.- Returns:
- the filename filter
-
setReportExistingFilesOnStartup
public void setReportExistingFilesOnStartup(boolean reportExisting) Whether or not an initial scan will report all files as being added.- Parameters:
reportExisting- if true, all files found on initial scan will be reported as being added, otherwise not
-
getReportExistingFilesOnStartup
public boolean getReportExistingFilesOnStartup() -
setReportDirs
public void setReportDirs(boolean dirs) Set if found directories should be reported.- Parameters:
dirs- true to report directory changes as well
-
getReportDirs
public boolean getReportDirs() -
addListener
Add an added/removed/changed listener- Parameters:
listener- the listener to add
-
removeListener
Remove a registered listener- Parameters:
listener- the Listener to be removed
-
doStart
public void doStart()Start the scanning action.- Overrides:
doStartin classAbstractLifeCycle
-
newTimerTask
-
newTimer
-
schedule
public void schedule() -
doStop
public void doStop()Stop the scanning.- Overrides:
doStopin classAbstractLifeCycle
-
reset
public void reset()Clear the list of scannables. The scanner must first be in the stopped state. -
exists
- Parameters:
path- tests if the path exists- Returns:
- true if the path exists in one of the scandirs
-
scan
public void scan()Perform a pass of the scanner and report changes -
scanFiles
public void scanFiles()Scan all of the given paths. -
reportDifferences
private void reportDifferences(Map<String, Scanner.TimeNSize> currentScan, Map<String, Scanner.TimeNSize> oldScan) Report the adds/changes/removes to the registered listeners- Parameters:
currentScan- the info from the most recent passoldScan- info from the previous pass
-
warn
-
reportAddition
Report a file addition to the registered FileAddedListeners- Parameters:
filename- the filename
-
reportRemoval
Report a file removal to the FileRemovedListeners- Parameters:
filename- the filename
-
reportChange
Report a file change to the FileChangedListeners- Parameters:
filename- the filename
-
reportBulkChanges
Report the list of filenames for which changes were detected.- Parameters:
filenames- names of all files added/changed/removed
-
reportScanStart
private void reportScanStart(int cycle) Call ScanCycleListeners with start of scan -
reportScanEnd
private void reportScanEnd(int cycle) Call ScanCycleListeners with end of scan.
-