public class WatchDir extends Object implements AutoCloseable
WatchService
class.| Constructor and Description |
|---|
WatchDir(Path aDir,
boolean bRecursive)
Creates a WatchService and registers the given directory
|
| Modifier and Type | Method and Description |
|---|---|
CallbackList<IWatchDirCallback> |
callbacks() |
void |
close()
Close the watch directory service and stop processing.
|
static WatchDir |
createAsyncRunningWatchDir(Path aDir,
boolean bRecursive,
IWatchDirCallback aCallback)
Static factory method to create a simple
WatchDir instance that
already spawned an Thread to listen. |
Path |
getStartDirectory() |
boolean |
isProcessing()
Check if processing is active.
|
boolean |
isRecursive() |
void |
processEvents()
Process all events for keys queued to the watcher.
|
void |
stopProcessing()
Stop processing, if
processEvents() is active. |
public WatchDir(@Nonnull Path aDir, boolean bRecursive) throws IOException
aDir - The directory to be watched. May not be null.bRecursive - true to watch the directory recursive,
false to watch just this directory.IOException - In case something goes wrong.@Nonnull @ReturnsMutableObject(value="design") public CallbackList<IWatchDirCallback> callbacks()
null.@Nonnull public Path getStartDirectory()
null.public boolean isRecursive()
true if this is a recursive listener,
false if not.public void close()
throws IOException
close in interface AutoCloseableIOExceptionpublic void stopProcessing()
processEvents() is active. This method is
automatically called in close().public boolean isProcessing()
true if event processing is active, false
if not.processEvents(),
stopProcessing(),
close()public void processEvents()
stopProcessing() or close() to stop processing within a
reasonable time. This method should run in a separate thread, as it
contains an infinite loop!@Nonnull @ReturnsMutableCopy public static WatchDir createAsyncRunningWatchDir(@Nonnull Path aDir, boolean bRecursive, @Nonnull IWatchDirCallback aCallback) throws IOException
WatchDir instance that
already spawned an Thread to listen. To close the thread call the
close() method.aDir - The directory to be watched. May not be null.bRecursive - true to watch the directory recursive,
false to watch just this directory.aCallback - The callback to be invoked if something changed. May not be
null.WatchDir instance and never
null.IOException - In case something goes wrong.Copyright © 2014–2017 Philip Helger. All rights reserved.