FolderWatchdog

A thin wrapper on top of java.nio.file.WatchService in the JDK to allow for easier controls with the maestro daemon in watching directory changes using a dedicated thread to avoid blocking.

A lot of the implementation is "inspired" from the official examples

Properties

Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
fun attachGlobalListener(listener: (path: Path, newFile: Path) -> Unit)
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
fun isSubscribed(folder: Path): Boolean
Link copied to clipboard
fun isWatching(path: Path): Boolean
Link copied to clipboard
fun register()

Initializes the service to start and prepares it for start to be called.

Link copied to clipboard
fun start()

Actually start polling for updates from the list of registered paths to watch in a separate thread.

Link copied to clipboard
fun stop()

Stops the service and the associated thread.

Link copied to clipboard
fun stopWatching(folder: Path)

The watch key and also any potential listeners are removed

Link copied to clipboard
fun subscribe(folder: Path, listener: (newFile: Path) -> Unit)
Link copied to clipboard
fun subscribeIfNot(folder: Path, listener: (newFile: Path) -> Unit)
Link copied to clipboard

Removes everything and should be called after stop

Link copied to clipboard
fun unsubscribe(folder: Path)

Removes the listener for folder if applicable.

Link copied to clipboard
fun watch(path: Path)

Schedules a new folder provided by path to be watched by this service.

Link copied to clipboard
fun watchIfNot(path: Path)

Calls watch on path if the watchdog isn't already watching path