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 a DirectoryWatcher.
  • Constructor Summary

    Constructors
    Constructor Description
    DirectoryWatcher​(java.util.List<java.nio.file.Path> paths, DirectoryChangeListener listener, java.nio.file.WatchService watchService, FileHasher fileHasher, org.slf4j.Logger logger)  
  • Method Summary

    Modifier and Type Method Description
    static DirectoryWatcher.Builder builder()
    Get a new builder for a DirectoryWatcher.
    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 using ForkJoinPool.commonPool() as the executor
    java.util.concurrent.CompletableFuture<java.lang.Void> watchAsync​(java.util.concurrent.Executor executor)
    Asynchronously watch the directories.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • DirectoryWatcher

      public DirectoryWatcher​(java.util.List<java.nio.file.Path> paths, DirectoryChangeListener listener, java.nio.file.WatchService watchService, FileHasher fileHasher, org.slf4j.Logger logger) throws java.io.IOException
      Throws:
      java.io.IOException
  • Method Details

    • builder

      public static DirectoryWatcher.Builder builder()
      Get a new builder for a DirectoryWatcher.
    • watchAsync

      public java.util.concurrent.CompletableFuture<java.lang.Void> watchAsync()
      Asynchronously watch the directories using ForkJoinPool.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.
    • getListener

      public DirectoryChangeListener getListener()
    • close

      public void close() throws java.io.IOException
      Throws:
      java.io.IOException
    • isClosed

      public boolean isClosed()