Package io.methvin.watcher
Class DirectoryWatcher
- java.lang.Object
-
- io.methvin.watcher.DirectoryWatcher
-
public class DirectoryWatcher extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DirectoryWatcher.Builder
A builder for aDirectoryWatcher
.
-
Constructor Summary
Constructors Constructor Description DirectoryWatcher(java.util.List<java.nio.file.Path> paths, DirectoryChangeListener listener, java.nio.file.WatchService watchService, FileHasher fileHasher, FileTreeVisitor fileTreeVisitor, org.slf4j.Logger logger)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static DirectoryWatcher.Builder
builder()
Get a new builder for aDirectoryWatcher
.void
close()
DirectoryChangeListener
getListener()
boolean
isClosed()
java.util.Map<java.nio.file.Path,FileHash>
pathHashes()
void
watch()
Watch the directories.java.util.concurrent.CompletableFuture<java.lang.Void>
watchAsync()
Asynchronously watch the directories usingForkJoinPool.commonPool()
as the executorjava.util.concurrent.CompletableFuture<java.lang.Void>
watchAsync(java.util.concurrent.Executor executor)
Asynchronously watch the directories.
-
-
-
Constructor Detail
-
DirectoryWatcher
public DirectoryWatcher(java.util.List<java.nio.file.Path> paths, DirectoryChangeListener listener, java.nio.file.WatchService watchService, FileHasher fileHasher, FileTreeVisitor fileTreeVisitor, org.slf4j.Logger logger) throws java.io.IOException
- Throws:
java.io.IOException
-
-
Method Detail
-
builder
public static DirectoryWatcher.Builder builder()
Get a new builder for aDirectoryWatcher
.
-
watchAsync
public java.util.concurrent.CompletableFuture<java.lang.Void> watchAsync()
Asynchronously watch the directories usingForkJoinPool.commonPool()
as the executor
-
watchAsync
public java.util.concurrent.CompletableFuture<java.lang.Void> watchAsync(java.util.concurrent.Executor executor)
Asynchronously watch the directories.- Parameters:
executor
- the executor to use to watch asynchronously
-
pathHashes
public java.util.Map<java.nio.file.Path,FileHash> pathHashes()
-
watch
public void watch()
Watch the directories. Block until either the listener stops watching or the DirectoryWatcher is closed.- Throws:
java.lang.IllegalStateException
- if the directory watcher is closed when watch() is called.
-
getListener
public DirectoryChangeListener getListener()
-
close
public void close() throws java.io.IOException
- Throws:
java.io.IOException
-
isClosed
public boolean isClosed()
-
-