public class PathWatcher extends AbstractLifeCycle implements Runnable
Suitable replacement for the old Scanner implementation.
Allows for configured Excludes and Includes using FileSystem.getPathMatcher(String) syntax.
Reports activity via registered PathWatcher.Listeners
| Modifier and Type | Class and Description |
|---|---|
static class |
PathWatcher.Config |
static class |
PathWatcher.DirAction |
static interface |
PathWatcher.EventListListener
EventListListener
Listener that reports accumulated events in one shot
|
static interface |
PathWatcher.Listener
Listener for path change events
|
static class |
PathWatcher.PathMatcherSet |
class |
PathWatcher.PathWatchEvent
PathWatchEvent
Represents a file event.
|
static class |
PathWatcher.PathWatchEventType
PathWatchEventType
Type of an event
|
AbstractLifeCycle.AbstractLifeCycleListener| Constructor and Description |
|---|
PathWatcher()
Construct new PathWatcher
|
| Modifier and Type | Method and Description |
|---|---|
void |
addListener(EventListener listener)
Add a listener for changes the watcher notices.
|
Collection<PathWatcher.Config> |
getConfigs() |
Iterator<EventListener> |
getListeners()
Get an iterator over the listeners.
|
long |
getUpdateQuietTimeMillis()
Change the quiet time.
|
void |
handleWatchEvent(Path path,
PathWatcher.PathWatchEvent event)
Add an event reported by the WatchService to list of pending events
that will be sent after their quiet time has expired.
|
boolean |
isNotifyExistingOnStart() |
boolean |
removeListener(PathWatcher.Listener listener)
Delete a listener
|
void |
reset()
Remove all current configs and listeners.
|
void |
run()
Forever loop.
|
void |
setNotifyExistingOnStart(boolean notify)
Whether or not to issue notifications for directories and files that
already exist when the watcher starts.
|
void |
setUpdateQuietTime(long duration,
TimeUnit unit)
Set the quiet time.
|
String |
toString() |
void |
watch(Path file)
Request watch on a the given path (either file or dir)
using all Config defaults.
|
void |
watch(PathWatcher.Config config)
Request watch on a path with custom Config
provided.
|
addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, setStopTimeout, start, stoppublic Collection<PathWatcher.Config> getConfigs()
public void watch(Path file)
file - the path to watchpublic void watch(PathWatcher.Config config)
config - the configuration to watchpublic void addListener(EventListener listener)
listener - change listenerpublic void reset()
public Iterator<EventListener> getListeners()
public long getUpdateQuietTimeMillis()
public boolean removeListener(PathWatcher.Listener listener)
listener - the listener to removepublic void run()
run in interface RunnableRunnable.run()public void handleWatchEvent(Path path, PathWatcher.PathWatchEvent event)
path - the path to add to the pending listevent - the pending eventpublic void setNotifyExistingOnStart(boolean notify)
notify - true if existing paths should be notified or notpublic boolean isNotifyExistingOnStart()
public void setUpdateQuietTime(long duration,
TimeUnit unit)
duration - the quiet time durationunit - the quite time unitpublic String toString()
toString in class AbstractLifeCycleCopyright © 2010 - 2020 Adobe. All Rights Reserved