Class FileSystemWatcher

All Implemented Interfaces:

public final class FileSystemWatcher extends Object implements ChangeWatcher<Path>
This change watcher is backed by WatchService to fire a polling event with every change on monitored Path.

When a parent directory of the path is not available, or becomes unavailable later, a new attempt to register WatchService is scheduled again and again until the directory finally exists and the registration is successful.

This ChangeWatcher might be initialized with a custom executor or the Executors.newSingleThreadScheduledExecutor() is used if none is explicitly configured.

This watcher notifies with appropriate change event in the following cases:

  • The watched directory is gone
  • The watched directory appears
  • A file in the watched directory is deleted, created or modified

A single file system watcher may be used to watch multiple targets. In such a case, if stop() is invoked, it stops watching all of these targets.

See Also: