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 interfaceScanner.BulkListenerstatic interfaceScanner.DiscreteListenerstatic interfaceScanner.ListenerListener Marker for notifications re file changes.static classScanner.Notificationstatic interfaceScanner.ScanCycleListenerListener that notifies when a scan has started and when it has ended.static interfaceScanner.ScanListener-
Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
AbstractLifeCycle.AbstractLifeCycleListener
-
-
Constructor Summary
Constructors Constructor Description Scanner()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddListener(Scanner.Listener listener)Add an added/removed/changed listenervoidaddScanDir(java.io.File dir)voiddoStart()Start the scanning action.voiddoStop()Stop the scanning.booleanexists(java.lang.String path)java.io.FilenameFiltergetFilenameFilter()Get any filter applied to files in the scan dir.booleangetRecursive()booleangetReportDirs()booleangetReportExistingFilesOnStartup()intgetScanDepth()Get the scanDepth.java.util.List<java.io.File>getScanDirs()intgetScanInterval()Get the scan intervaljava.util.TimernewTimer()java.util.TimerTasknewTimerTask()voidremoveListener(Scanner.Listener listener)Remove a registered listenervoidreportDifferences(java.util.Map<java.lang.String,org.eclipse.jetty.util.Scanner.TimeNSize> currentScan, java.util.Map<java.lang.String,org.eclipse.jetty.util.Scanner.TimeNSize> oldScan)Report the adds/changes/removes to the registered listenersvoidscan()Perform a pass of the scanner and report changesvoidscanFiles()Recursively scan all files in the designated directories.voidschedule()voidsetFilenameFilter(java.io.FilenameFilter filter)Apply a filter to files found in the scan directory.voidsetRecursive(boolean recursive)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(java.util.List<java.io.File> dirs)voidsetScanInterval(int scanInterval)Set the scan interval-
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
-
-
-
-
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
public void addScanDir(java.io.File dir)
-
getScanDirs
public java.util.List<java.io.File> getScanDirs()
-
setRecursive
public void setRecursive(boolean recursive)
- Parameters:
recursive- True if scanning is recursive- See Also:
setScanDepth(int)
-
getRecursive
public boolean getRecursive()
- Returns:
- True if scanning is fully recursive (scandepth==-1)
- 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
public void setFilenameFilter(java.io.FilenameFilter filter)
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
public java.io.FilenameFilter getFilenameFilter()
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:
doStartin 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:
doStopin classAbstractLifeCycle
-
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()
Recursively scan all files in the designated directories.
-
reportDifferences
public void reportDifferences(java.util.Map<java.lang.String,org.eclipse.jetty.util.Scanner.TimeNSize> currentScan, java.util.Map<java.lang.String,org.eclipse.jetty.util.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
-
-