Package org.eclipse.jetty.util
Class Scanner
java.lang.Object
org.eclipse.jetty.util.component.AbstractLifeCycle
org.eclipse.jetty.util.component.ContainerLifeCycle
org.eclipse.jetty.util.Scanner
- All Implemented Interfaces:
Container
,Destroyable
,Dumpable
,Dumpable.DumpableContainer
,LifeCycle
Scanner
Utility for scanning a directory for added, removed and changed
files and reporting these events via registered Listeners.
The scanner operates on the
Path.toRealPath(LinkOption...)
of the files scanned and
can be configured to follow symlinks.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Notification of files that changed in the last scan.static interface
Notification of exact file changes in the last scan.static interface
Listener Marker for notifications re file changes.static interface
Listener that notifies when a scan has started and when it has ended.Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
AbstractLifeCycle.AbstractLifeCycleListener, AbstractLifeCycle.StopException
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Container
Container.InheritedListener
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Dumpable
Dumpable.DumpableContainer
-
Field Summary
Modifier and TypeFieldDescriptionstatic 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).static final int
-
Constructor Summary
-
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
doStart()
Start the scanning action.void
doStop()
Stop the scanning.boolean
Deprecated.boolean
boolean
int
Get the scanDepth.int
Get the scan intervalboolean
Test if scanning should start automatically withScanner
.AbstractLifeCycle.start()
void
nudge()
Hint to the scanner to perform a scan cycle as soon as possible.void
removeListener
(Scanner.Listener listener) Remove a registered listenervoid
reset()
Clear the list of scannables.void
Get the scanner to perform a scan cycle as soon as possible and call the Callback when the scan is finished or failed.void
setAutoStartScanning
(boolean autostart) Flag to control scanning auto start feature.void
setFilenameFilter
(FilenameFilter filter) 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 intervalvoid
Start scanning.Methods inherited from class org.eclipse.jetty.util.component.ContainerLifeCycle
addBean, addBean, addEventListener, addManaged, contains, destroy, dump, dump, dump, dumpObjects, dumpStdErr, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, removeEventListener, setBeans, start, stop, unmanage, updateBean, updateBean, updateBeans, updateBeans
Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
getEventListeners, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, setEventListeners, start, stop, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.eclipse.jetty.util.component.Container
getCachedBeans, getEventListeners
Methods inherited from interface org.eclipse.jetty.util.component.Dumpable.DumpableContainer
isDumpable
-
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:
-
-
Constructor Details
-
Scanner
public Scanner() -
Scanner
-
Scanner
- Parameters:
scheduler
- The scheduler to use for scanning.reportRealPaths
- If true, theScanner.Listener
s are called with the real path of scanned files.
-
-
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
-
addFile
Add a file to be scanned. The file must not be null, and must exist.- Parameters:
path
- the Path of the file to scan.
-
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
-
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
-
getScannables
-
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
-
isAutoStartScanning
public boolean isAutoStartScanning()Test if scanning should start automatically withScanner
.AbstractLifeCycle.start()
- Returns:
- true if scanning should start automatically, false to have scanning is deferred to a later manual call to
startScanning()
-
setAutoStartScanning
public void setAutoStartScanning(boolean autostart) Flag to control scanning auto start feature.true
- to have scanning automatically start with the Scanner.AbstractLifeCycle.start()
false
- to have scanning deferred until a future call tostartScanning()
If choosing to defer the automatic scanning, a future call to
startScanning()
is required to initiate this Scanner so that it can begin report files in thesetScanDirs(List)
- Parameters:
autostart
- true if scanning should start automatically, false to defer start of scanning to a later call tostartScanning()
-
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
Start the scanning action.- Overrides:
doStart
in classContainerLifeCycle
- Throws:
AbstractLifeCycle.StopException
- If thrown, the lifecycle will immediately be stopped.Exception
- If there was a problem starting. Will cause a transition to FAILED state
-
startScanning
public void startScanning()Start scanning.This will perform the initial scan of the directories
setScanDirs(List)
and schedule future scans, following all of the configuration of the scan (eg:setReportExistingFilesOnStartup(boolean)
) -
doStop
Stop the scanning.- Overrides:
doStop
in classContainerLifeCycle
- Throws:
Exception
- If there was a problem stopping. Will cause a transition to FAILED state
-
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
-
nudge
public void nudge()Hint to the scanner to perform a scan cycle as soon as possible. NOTE that the scan is not guaranteed to have happened by the time this method returns. -
scan
Get the scanner to perform a scan cycle as soon as possible and call the Callback when the scan is finished or failed.- Parameters:
complete
- called when the scan cycle finishes or fails.
-