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... modifiers)
                         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.
        modifiers - 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. Leave unspecified to use the default sensitivity. Other modifiers may also be allowed depending on the platform.
        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.