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 interface
static interface
static interface
Listener Marker for notifications re file changes.static enum
(package private) static class
PathMatcherSet A set of PathMatchers for testing Paths against path matching patterns viastatic interface
Listener that notifies when a scan has started and when it has ended.static interface
(package private) static class
TimeNSize Metadata about a file: Last modified time and file size.(package private) class
Visitor 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 int
private final Map<String,
Scanner.TimeNSize> private FilenameFilter
private final List<Scanner.Listener>
private final Map<String,
Scanner.Notification> private final Map<String,
Scanner.TimeNSize> private boolean
private boolean
private boolean
private int
private int
private int
private final Map<Path,
IncludeExcludeSet<PathMatcher, Path>> private TimerTask
private Timer
static final int
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 final Logger
static final int
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddDirectory
(Path p) Add a directory to be scanned.void
Add a file to be scanned.void
addListener
(Scanner.Listener listener) Add an added/removed/changed listenervoid
addScanDir
(File dir) Deprecated.void
doStart()
Start the scanning action.void
doStop()
Stop the scanning.boolean
Deprecated.boolean
Deprecated.boolean
boolean
int
Get the scanDepth.Deprecated.int
Get the scan intervalnewTimer()
void
removeListener
(Scanner.Listener listener) Remove a registered listenerprivate void
reportAddition
(String filename) Report a file addition to the registered FileAddedListenersprivate void
reportBulkChanges
(List<String> filenames) Report the list of filenames for which changes were detected.private void
reportChange
(String filename) Report a file change to the FileChangedListenersprivate void
reportDifferences
(Map<String, Scanner.TimeNSize> currentScan, Map<String, Scanner.TimeNSize> oldScan) Report the adds/changes/removes to the registered listenersprivate void
reportRemoval
(String filename) Report a file removal to the FileRemovedListenersprivate void
reportScanEnd
(int cycle) Call ScanCycleListeners with end of scan.private void
reportScanStart
(int cycle) Call ScanCycleListeners with start of scanvoid
reset()
Clear the list of scannables.void
scan()
Perform a pass of the scanner and report changesvoid
Scan all of the given paths.void
schedule()
void
setFilenameFilter
(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
(List<File> dirs) void
setScanInterval
(int scanInterval) Set the scan intervalprivate void
Methods 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). -
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:
doStart
in classAbstractLifeCycle
-
newTimerTask
-
newTimer
-
schedule
public void schedule() -
doStop
public void doStop()Stop the scanning.- Overrides:
doStop
in 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.
-