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 enumstatic interfaceListener that notifies when a scan has started and when it has ended.static interfaceNested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
AbstractLifeCycle.AbstractLifeCycleListener -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic 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).static 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 listenervoidreset()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 intervalMethods 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:
-
-
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.
-