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
public class Scanner extends AbstractLifeCycle
Scanner Utility for scanning a directory for added, removed and changed files and reporting these events via registered Listeners.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class 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 viastatic 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.-
Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
AbstractLifeCycle.AbstractLifeCycleListener
-
-
Field Summary
Fields Modifier and Type Field 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 Summary
Constructors Constructor Description Scanner()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method 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 listenervoid
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 intervaljava.util.Set<java.nio.file.Path>
getScannables()
java.util.Timer
newTimer()
java.util.TimerTask
newTimerTask()
void
removeListener(Scanner.Listener listener)
Remove a registered listenerprivate void
reportAddition(java.lang.String filename)
Report a file addition to the registered FileAddedListenersprivate 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 FileChangedListenersprivate 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 listenersprivate void
reportRemoval(java.lang.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
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 intervalprivate void
warn(java.lang.Object listener, java.lang.String filename, java.lang.Throwable th)
-
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 Detail
-
DEFAULT_SCAN_DEPTH
public static final 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).
-
MAX_SCAN_DEPTH
public static final int MAX_SCAN_DEPTH
- See Also:
- Constant Field Values
-
LOG
private static final Logger LOG
-
__scannerId
private static int __scannerId
-
_scanInterval
private int _scanInterval
-
_scanCount
private int _scanCount
-
_listeners
private final java.util.List<Scanner.Listener> _listeners
-
_prevScan
private final java.util.Map<java.lang.String,Scanner.TimeNSize> _prevScan
-
_currentScan
private final java.util.Map<java.lang.String,Scanner.TimeNSize> _currentScan
-
_filter
private java.io.FilenameFilter _filter
-
_scannables
private final java.util.Map<java.nio.file.Path,IncludeExcludeSet<java.nio.file.PathMatcher,java.nio.file.Path>> _scannables
-
_running
private volatile boolean _running
-
_reportExisting
private boolean _reportExisting
-
_reportDirs
private boolean _reportDirs
-
_timer
private java.util.Timer _timer
-
_task
private java.util.TimerTask _task
-
_scanDepth
private int _scanDepth
-
_notifications
private final java.util.Map<java.lang.String,Scanner.Notification> _notifications
-
-
Method Detail
-
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
public void setScanDirs(java.util.List<java.io.File> dirs)
-
addScanDir
@Deprecated public void addScanDir(java.io.File dir)
Deprecated.
-
addFile
public void addFile(java.nio.file.Path p) throws java.io.IOException
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:
java.io.IOException
-
addDirectory
public IncludeExcludeSet<java.nio.file.PathMatcher,java.nio.file.Path> addDirectory(java.nio.file.Path p) throws java.io.IOException
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:
java.io.IOException
-
getScanDirs
@Deprecated public java.util.List<java.io.File> getScanDirs()
Deprecated.
-
getScannables
public java.util.Set<java.nio.file.Path> getScannables()
-
setRecursive
@Deprecated public void setRecursive(boolean recursive)
Deprecated.- Parameters:
recursive
- True if scanning is recursive- See Also:
setScanDepth(int)
-
getRecursive
@Deprecated public boolean getRecursive()
Deprecated.- Returns:
- True if scanning is recursive
- See Also:
getScanDepth()
-
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 public void setFilenameFilter(java.io.FilenameFilter filter)
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 public java.io.FilenameFilter 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
public void addListener(Scanner.Listener listener)
Add an added/removed/changed listener- Parameters:
listener
- the listener to add
-
removeListener
public void removeListener(Scanner.Listener listener)
Remove a registered listener- Parameters:
listener
- the Listener to be removed
-
doStart
public void doStart()
Start the scanning action.- Overrides:
doStart
in classAbstractLifeCycle
-
newTimerTask
public java.util.TimerTask newTimerTask()
-
newTimer
public java.util.Timer 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
public boolean exists(java.lang.String path)
- 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(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- Parameters:
currentScan
- the info from the most recent passoldScan
- info from the previous pass
-
warn
private void warn(java.lang.Object listener, java.lang.String filename, java.lang.Throwable th)
-
reportAddition
private void reportAddition(java.lang.String filename)
Report a file addition to the registered FileAddedListeners- Parameters:
filename
- the filename
-
reportRemoval
private void reportRemoval(java.lang.String filename)
Report a file removal to the FileRemovedListeners- Parameters:
filename
- the filename
-
reportChange
private void reportChange(java.lang.String filename)
Report a file change to the FileChangedListeners- Parameters:
filename
- the filename
-
reportBulkChanges
private void reportBulkChanges(java.util.List<java.lang.String> filenames)
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.
-
-