Top Description Inners Fields Constructors Methods
org.eclipse.jetty.util

public Class Scanner

extends ContainerLifeCycle
Class Inheritance
Imports
java.io.File, .FilenameFilter, .IOException, java.nio.file.FileVisitOption, .FileVisitResult, .FileVisitor, .Files, .LinkOption, .Path, .PathMatcher, java.nio.file.attribute.BasicFileAttributes, java.util.Collections, .EnumSet, .HashMap, .HashSet, .List, .Map, .Set, java.util.concurrent.ConcurrentHashMap, .CopyOnWriteArrayList, .TimeUnit, java.util.concurrent.atomic.AtomicInteger, java.util.function.Predicate, java.util.stream.Collectors, org.eclipse.jetty.util.component.ContainerLifeCycle, org.eclipse.jetty.util.thread.ScheduledExecutorScheduler, .Scheduler, org.slf4j.Logger, .LoggerFactory

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 and Inner Type Summary

Modifier and TypeClass and Description
public static interface
Scanner.BulkListener

Notification of files that changed in the last scan.

public static interface
Scanner.DiscreteListener

Notification of exact file changes in the last scan.

public static interface
Scanner.Listener

Listener Marker for notifications re file changes.

private static class
Scanner.MetaData

MetaData Metadata about a file: Last modified time, file size and last file status (ADDED, CHANGED, DELETED, STABLE)

pack-priv static enum
pack-priv static class
Scanner.PathMatcherSet

PathMatcherSet A set of PathMatchers for testing Paths against path matching patterns via

public static interface
Scanner.ScanCycleListener

Listener that notifies when a scan has started and when it has ended.

private class
private static enum
private class
Scanner.Visitor

Visitor A FileVisitor for walking a subtree of paths.

Field Summary

Modifier and TypeField and Description
private boolean
private FilenameFilter
private final LinkOption[]
private final List<Scanner.Listener>
private Map<Path, Scanner.MetaData>
private boolean
private boolean
private final AtomicInteger
private int
private int
private final Map<Path, IncludeExcludeSet<PathMatcher, Path>>
private boolean
private final Scheduler
private Scheduler.Task
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).

private static final Logger
public static final int
private static final AtomicInteger

Constructor Summary

AccessConstructor and Description
public
public
Scanner(Scheduler scheduler)

public
Scanner(Scheduler
The scheduler to use for scanning.
scheduler
,
boolean
If true, the Listeners are called with the real path of scanned files.
reportRealPaths
)

Method Summary

Modifier and TypeMethod and Description
public IncludeExcludeSet<PathMatcher, Path>

Returns:

an IncludeExcludeSet to which the caller can add PathMatcher patterns to match
addDirectory
(Path
the directory to scan.
p
)

Add a directory to be scanned.

public void
addFile(Path
the Path of the file to scan.
path
)

Add a file to be scanned.

public void
addListener(Scanner.Listener
the listener to add
listener
)

Add an added/removed/changed listener

public void
public void
public boolean
exists(String
tests if the path exists
path
)

Returns: true if the path exists in one of the scandirs

public FilenameFilter

Returns:

the filename filter
getFilenameFilter
()
Deprecated

Get any filter applied to files in the scan dir.

public boolean
public boolean
public int

Returns:

the scanDepth
getScanDepth
()

Get the scanDepth.

public int

Returns:

interval between scans in seconds
getScanInterval
()

Get the scan interval

public Set<Path>
public boolean

Returns:

true if scanning should start automatically, false to have scanning is deferred to a later manual call to startScanning()
isAutoStartScanning
()

Test if scanning should start automatically with Scanner.

public void
nudge()

Hint to the scanner to perform a scan cycle as soon as possible.

public void
removeListener(Scanner.Listener
the Listener to be removed
listener
)

Remove a registered listener

private void
reportAddition(Path
the path
path
)

Report a file addition to the registered FileAddedListeners

private void
reportBulkChanges(Set<Path>
The paths of all files added/changed/removed
paths
)

Report the list of filenames for which changes were detected.

private void
reportChange(Path
the path of the changed file
path
)

Report a file change to the FileChangedListeners

private void
reportDifferences(Map<Path, Scanner.MetaData>
the info from the most recent pass
currentScan
,
Map<Path, Scanner.MetaData>
info from the previous pass
oldScan
)

Report the adds/changes/removes to the registered listeners Only report an add or change once a file has stablilized in size.

private void
reportRemoval(Path
the path of the removed filename
path
)

Report a file removal to the FileRemovedListeners

private void
reportScanEnd(int
scan count
cycle
)

Call ScanCycleListeners with end of scan.

private void
reportScanStart(int
scan count
cycle
)

Call ScanCycleListeners with start of scan

public void
reset()

Clear the list of scannables.

public void
scan(Callback
called when the scan cycle finishes or fails.
complete
)

Get the scanner to perform a scan cycle as soon as possible and call the Callback when the scan is finished or failed.

pack-priv void
scan()

Perform a pass of the scanner and report changes

private Map<Path, Scanner.MetaData>
scanFiles()

Scan all the given paths.

private void
public void
setAutoStartScanning(boolean
true if scanning should start automatically, false to defer start of scanning to a later call to startScanning()
autostart
)

Flag to control scanning auto start feature.

public void
setFilenameFilter(FilenameFilter
the filename filter to use
filter
)
Deprecated

Apply a filter to files found in the scan directory.

public void
setReportDirs(boolean
true to report directory changes as well
dirs
)

Set if found directories should be reported.

public void
setReportExistingFilesOnStartup(boolean
if true, all files found on initial scan will be reported as being added, otherwise not
reportExisting
)

Whether or not an initial scan will report all files as being added.

public void
setScanDepth(int
the scanDepth to set
scanDepth
)

Set the scanDepth.

public void
public void
setScanInterval(int
pause between scans in seconds, or 0 for no scan after the initial scan.
scanInterval
)

Set the scan interval

public void
startScanning()

Start scanning.

private void
warn(Object listener, Path path, Throwable th)

Inherited from org.eclipse.jetty.util.component.ContainerLifeCycle:
addBeanaddBeanaddEventListeneraddManagedcontainsdestroydumpdumpdumpdumpObjectsdumpStdErrgetBeangetBeansgetBeansgetContainedBeansgetContainedBeansisAutoisManagedisUnmanagedmanageremoveBeanremoveBeansremoveEventListenersetBeansstartstopunmanageupdateBeanupdateBeanupdateBeansupdateBeans