Class PathWatcher

  • All Implemented Interfaces:
    java.lang.Runnable, LifeCycle

    @Deprecated(since="2021-05-27")
    public class PathWatcher
    extends AbstractLifeCycle
    implements java.lang.Runnable
    Deprecated.
    The Eclipse Jetty and Apache Felix Http Jetty packages are no longer supported.
    Watch a Path (and sub directories) for Path changes.

    Suitable replacement for the old Scanner implementation.

    Allows for configured Excludes and Includes using FileSystem.getPathMatcher(String) syntax.

    Reports activity via registered PathWatcher.Listeners

    • Constructor Detail

      • PathWatcher

        public PathWatcher()
        Deprecated.
        Construct new PathWatcher
    • Method Detail

      • watch

        public void watch​(java.nio.file.Path file)
        Deprecated.
        Request watch on a the given path (either file or dir) using all Config defaults. In the case of a dir, the default is not to recurse into subdirs for watching.
        Parameters:
        file - the path to watch
      • watch

        public void watch​(PathWatcher.Config config)
        Deprecated.
        Request watch on a path with custom Config provided.
        Parameters:
        config - the configuration to watch
      • addListener

        public void addListener​(java.util.EventListener listener)
        Deprecated.
        Add a listener for changes the watcher notices.
        Parameters:
        listener - change listener
      • reset

        public void reset()
        Deprecated.
        Remove all current configs and listeners.
      • getListeners

        public java.util.Iterator<java.util.EventListener> getListeners()
        Deprecated.
        Get an iterator over the listeners.
        Returns:
        iterator over the listeners.
      • getUpdateQuietTimeMillis

        public long getUpdateQuietTimeMillis()
        Deprecated.
        Change the quiet time.
        Returns:
        the quiet time in millis
      • removeListener

        public boolean removeListener​(PathWatcher.Listener listener)
        Deprecated.
        Delete a listener
        Parameters:
        listener - the listener to remove
        Returns:
        true if the listener existed and was removed
      • run

        public void run()
        Deprecated.
        Forever loop. Wait for the WatchService to report some filesystem events for the watched paths. When an event for a path first occurs, it is subjected to a quiet time. Subsequent events that arrive for the same path during this quiet time are accumulated and the timer reset. Only when the quiet time has expired are the accumulated events sent. MODIFY events are handled slightly differently - multiple MODIFY events arriving within a quiet time are coalesced into a single MODIFY event. Both the accumulation of events and coalescing of MODIFY events reduce the number and frequency of event reporting for "noisy" files (ie those that are undergoing rapid change).
        Specified by:
        run in interface java.lang.Runnable
        See Also:
        Runnable.run()
      • handleWatchEvent

        public void handleWatchEvent​(java.nio.file.Path path,
                                     PathWatcher.PathWatchEvent event)
        Deprecated.
        Add an event reported by the WatchService to list of pending events that will be sent after their quiet time has expired.
        Parameters:
        path - the path to add to the pending list
        event - the pending event
      • setNotifyExistingOnStart

        public void setNotifyExistingOnStart​(boolean notify)
        Deprecated.
        Whether or not to issue notifications for directories and files that already exist when the watcher starts.
        Parameters:
        notify - true if existing paths should be notified or not
      • isNotifyExistingOnStart

        public boolean isNotifyExistingOnStart()
        Deprecated.
      • setUpdateQuietTime

        public void setUpdateQuietTime​(long duration,
                                       java.util.concurrent.TimeUnit unit)
        Deprecated.
        Set the quiet time.
        Parameters:
        duration - the quiet time duration
        unit - the quite time unit