Class WatcherService

java.lang.Object
com.activeviam.source.common.api.impl.WatcherService
All Implemented Interfaces:
IWatcherService, Closeable, AutoCloseable

public final class WatcherService extends Object implements IWatcherService
Standard implementation of the watcher service.
Author:
ActiveViam
  • Constructor Details

    • WatcherService

      public WatcherService()
      Default constructor, using the file system to have watchers.
    • WatcherService

      public WatcherService(WatchService watchService)
      Full constructor.
      Parameters:
      watchService - watch service to use.
  • Method Details

    • registerAll

      public void registerAll(IWatcher watcher, Path path)
      Description copied from interface: IWatcherService
      Register recursively all the directories.
      Specified by:
      registerAll in interface IWatcherService
      Parameters:
      watcher - the watcher
      path - the directory that may contain other subdirectories
    • register

      public WatchKey register(IWatcher watcher, Path path)
      Description copied from interface: IWatcherService
      Register a watcher of a path. When events related to this path are detected by the service, the watcher will be called back.
      Specified by:
      register in interface IWatcherService
      Parameters:
      watcher - The watcher to register.
      path - The path to watch.
      Returns:
      the watchKey
    • unregister

      public void unregister(IWatcher watcher)
      Description copied from interface: IWatcherService
      Unregisters the given watcher.
      Specified by:
      unregister in interface IWatcherService
      Parameters:
      watcher - The watcher to unregister from this watcher service.
    • getRegistry

      public Map<WatchKey,List<IWatcher>> getRegistry()
      Gets the list of watchers per watch key.
      Returns:
      The registry
    • setFollowSymbolicLinks

      public void setFollowSymbolicLinks(boolean followSymbolicLinks)
      Sets the flag for following symbolic links.

      This flag is used when registering a folder to watch. Switching the flag will not impact already registered folders.

      Parameters:
      followSymbolicLinks - true to follow links, false not to.
    • pauseWatcher

      public void pauseWatcher(IWatcher watcher)
      Description copied from interface: IWatcherService
      Pauses the processing of events for a given watcher.
      Specified by:
      pauseWatcher in interface IWatcherService
      Parameters:
      watcher - The watcher for which to stop processing events.
    • resumeWatcher

      public void resumeWatcher(IWatcher watcher)
      Description copied from interface: IWatcherService
      Resumes the processing of events for a given watcher.
      Specified by:
      resumeWatcher in interface IWatcherService
      Parameters:
      watcher - The watcher for which to resume processing events.
    • isWatcherPaused

      public boolean isWatcherPaused(IWatcher watcher)
      Description copied from interface: IWatcherService
      Says if the processing of events for a given watcher is paused.
      Specified by:
      isWatcherPaused in interface IWatcherService
      Parameters:
      watcher - The watcher of which to check the status.
      Returns:
      true if the processing of events of the given watcher is paused, false otherwise.
    • close

      public void close() throws IOException
      Stop the watcher thread.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getPausedTopics

      public Set<IWatcher> getPausedTopics()
      Gets the list of paused watchers.
      Returns:
      set of watchers marked as paused.