public class PathWatcher extends AbstractLifeCycle implements java.lang.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(java.util.EventListener listener)
Add a listener for changes the watcher notices.
|
protected static <T> java.nio.file.WatchEvent<T> |
cast(java.nio.file.WatchEvent<?> event) |
protected void |
doStart() |
protected void |
doStop() |
java.util.Collection<PathWatcher.Config> |
getConfigs() |
java.util.Iterator<java.util.EventListener> |
getListeners()
Get an iterator over the listeners.
|
long |
getUpdateQuietTimeMillis()
Change the quiet time.
|
void |
handleWatchEvent(java.nio.file.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.
|
protected boolean |
isNotifiable()
Check to see if the watcher is in a state where it should generate
watch events to the listeners.
|
boolean |
isNotifyExistingOnStart() |
protected void |
register(java.nio.file.Path path,
PathWatcher.Config config) |
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,
java.util.concurrent.TimeUnit unit)
Set the quiet time.
|
java.lang.String |
toString() |
void |
watch(java.nio.file.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, stopprotected static <T> java.nio.file.WatchEvent<T> cast(java.nio.file.WatchEvent<?> event)
public java.util.Collection<PathWatcher.Config> getConfigs()
public void watch(java.nio.file.Path file)
file - the path to watchpublic void watch(PathWatcher.Config config)
config - the configuration to watchpublic void addListener(java.util.EventListener listener)
listener - change listenerprotected void doStart()
throws java.lang.Exception
doStart in class AbstractLifeCyclejava.lang.ExceptionAbstractLifeCycle.doStart()protected void doStop()
throws java.lang.Exception
doStop in class AbstractLifeCyclejava.lang.ExceptionAbstractLifeCycle.doStop()public void reset()
protected boolean isNotifiable()
public java.util.Iterator<java.util.EventListener> getListeners()
public long getUpdateQuietTimeMillis()
protected void register(java.nio.file.Path path,
PathWatcher.Config config)
throws java.io.IOException
java.io.IOExceptionpublic boolean removeListener(PathWatcher.Listener listener)
listener - the listener to removepublic void run()
run in interface java.lang.RunnableRunnable.run()public void handleWatchEvent(java.nio.file.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,
java.util.concurrent.TimeUnit unit)
duration - the quiet time durationunit - the quite time unitpublic java.lang.String toString()
toString in class AbstractLifeCycleCopyright © 1995–2023 Webtide. All rights reserved.