Class DirectoryWatcher


  • public class DirectoryWatcher
    extends Object
    High-level interface to the WatchService API for detecting filesystem change events.
    • Constructor Detail

      • DirectoryWatcher

        public DirectoryWatcher​(ScheduledExecutorService scheduledExecutorService,
                                WatchEvent.Modifier sensitivity)
                         throws IOException
        Initializes the directory watcher. The watcher will use the given executor service to execute a periodic task polling for filesystem changes. The watch service from the default filesystem will be used to wait for events.
        Parameters:
        scheduledExecutorService - the scheduled executor service (never null). A periodic task will be added that polls for filesystem events every second.
        sensitivity - how urgently events should be delivered. A higher value will result in more frequent polling of the filesystem in some implementations. The allowed values are JVM specific. On Hotspot use com.sun.nio.file.SensitivityWatchEventModifier. May be null.
        Throws:
        IOException - if an I/O error occurs when trying to construct the watch service.
      • DirectoryWatcher

        public DirectoryWatcher​(ScheduledExecutorService scheduledExecutorService)
                         throws IOException
        Initializes the directory watcher. The watcher will use the given executor service to execute a periodic task polling for filesystem changes. A default event sensitivity is used. The watch service from the default filesystem will be used to wait for events.
        Parameters:
        scheduledExecutorService - the scheduled executor service (never null). A periodic task will be added that polls for filesystem events every second.
        Throws:
        IOException - if an I/O error occurs when trying to construct the watch service.
    • Method Detail

      • shutdown

        public void shutdown()
        Shuts down the directory watcher, cancelling all registered watch tasks and closing the underlying watch service.