Package com.swoval.files
Interface PathWatcher<T>
-
- All Superinterfaces:
java.lang.AutoCloseable,FileTreeViews.Observable<T>
- All Known Subinterfaces:
FileTreeRepository<T>
public interface PathWatcher<T> extends FileTreeViews.Observable<T>, java.lang.AutoCloseable
Watches directories for file changes. The api permits recursive watching of directories unlike the java.nio.file.WatchService. Some of the behavior may vary by platform due to fundamental differences in the underlying file event apis. For example, Linux doesn't support recursive directory monitoring via inotify, so it's possible in rare cases to miss file events for newly created files in newly created directories. On OSX, it is difficult to disambiguate file creation and modify events, so thePathWatchers.Event.Kindis best effort, but should not be relied upon to accurately reflect the state of the file.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidclose()Catch any exceptions in subclasses.Either<java.io.IOException,java.lang.Boolean>register(java.nio.file.Path path, int maxDepth)Register a path to monitor for file events.voidunregister(java.nio.file.Path path)Stop watching a path.-
Methods inherited from interface com.swoval.files.FileTreeViews.Observable
addObserver, removeObserver
-
-
-
-
Method Detail
-
register
Either<java.io.IOException,java.lang.Boolean> register(java.nio.file.Path path, int maxDepth)
Register a path to monitor for file events. The watcher will only watch child subdirectories up to maxDepth. For example, with a directory structure like /foo/bar/baz, if we register the path /foo/ with maxDepth 0, we will be notified for any files that are created, updated or deleted in foo, but not bar. If we increase maxDepth to 1, then the files in /foo/bar are monitored, but not the files in /foo/bar/baz.- Parameters:
path- the directory to watch for file eventsmaxDepth- the maximum maxDepth of subdirectories to watch- Returns:
- an
Eithercontaining the result of the registration or an IOException if registration fails. This method should be idempotent and return true the first time the directory is registered or when the depth is changed. Otherwise it should return false.
-
unregister
void unregister(java.nio.file.Path path)
Stop watching a path.- Parameters:
path- the path to remove from monitoring
-
close
void close()
Catch any exceptions in subclasses.- Specified by:
closein interfacejava.lang.AutoCloseable
-
-