Class SingleFileChangeWatcher
java.lang.Object
de.s42.base.files.SingleFileChangeWatcher
Allows to watch changes on a given single normal file.
The easiest way to use it is:
Pair<SingleFileChangeWatcher, Thread> watcher = SingleFileChangeWatcher.startWatching(file, (file) -> {
// ... do something with changed file ...
});
- Author:
- Benjamin Schiller
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final PathFile to watch changes on.handler that will be called back on changes of file.protected booleanwill be set to true on cancel().protected WatchServiceFS integration for watching changes -
Constructor Summary
ConstructorsConstructorDescriptionSingleFileChangeWatcher(Path file, Consumer<Path> handler) Create a watcher for the given file and given a callback that will be called whenever the file has changed in the filesystem -
Method Summary
Modifier and TypeMethodDescriptionvoidcancel()Allows to cancel the running watcherStarts this watcher creating a virtual thread.static Pair<SingleFileChangeWatcher, Thread> startWatching(Path file, Consumer<Path> handler) Creates and starts the watcher.voidCan be called by a worker directly.
-
Field Details
-
file
File to watch changes on. -
handler
-
watcher
FS integration for watching changes -
terminated
protected boolean terminatedwill be set to true on cancel().
-
-
Constructor Details
-
SingleFileChangeWatcher
-
-
Method Details
-
startWatching
-
cancel
-
startWatching
Starts this watcher creating a virtual thread.- Returns:
- Throws:
RuntimeException
-
watchImmediate
-