Interface WatchService


@NonNullByDefault public interface WatchService
The WatchService defines the interface for a general watch service. It allows registering listeners for subdirectories of the openHAB configuration directory. The reported path in the event is relative to the registered path. Watch services are created by WatchServiceFactory.createWatchService(String, Path). For files in the openHAB configuration folder a watch service with the name CONFIG_WATCHER_NAME is registered. For convenience, an OSGi target filter for referencing this watch service is provided CONFIG_WATCHER_FILTER.
Author:
Jan N. Klug - Initial contribution
  • Field Details

  • Method Details

    • registerListener

      default void registerListener(WatchService.WatchEventListener watchEventListener, Path path)
      Register a listener for this WatchService The given listener will be notified about all events related to files and directories (including subdirectories) in the given Path

      Listeners must unregister themselves before they are disposed

      Parameters:
      watchEventListener - the listener for this configuration
      path - a Path that the listener is interested in, relative to the base path of the watch service
    • registerListener

      default void registerListener(WatchService.WatchEventListener watchEventListener, List<Path> paths)
      Register a listener for this WatchService The given listener will be notified about all events related to files and directories (including subdirectories) in the given Path

      Listeners must unregister themselves before they are disposed

      Parameters:
      watchEventListener - the listener for this configuration
      paths - a list of Path that the listener is interested in, relative to the base path of the watch service
    • registerListener

      default void registerListener(WatchService.WatchEventListener watchEventListener, Path path, boolean withSubDirectories)
      Register a listener for this WatchService The given listener will be notified about all events related to files and directories in the given Path

      Listeners must unregister themselves before they are disposed

      Parameters:
      watchEventListener - the listener for this configuration
      path - thePath that the listener is interested in, relative to the base path of the watch service
      withSubDirectories - whether subdirectories of the given path should also be watched
    • registerListener

      void registerListener(WatchService.WatchEventListener watchEventListener, List<Path> paths, boolean withSubDirectories)
      Register a listener for this WatchService The given listener will be notified about all events related to files and directories in the given list of Path

      Listeners must unregister themselves before they are disposed

      Parameters:
      watchEventListener - the listener for this configuration
      paths - a list of Path that the listener is interested in, relative to the base path of the watch service
      withSubDirectories - whether subdirectories of the given paths should also be watched
    • unregisterListener

      void unregisterListener(WatchService.WatchEventListener watchEventListener)
      Unregister a listener from this WatchService The listener will no longer be notified of watch events
      Parameters:
      watchEventListener - the listener to unregister
    • getWatchPath

      Path getWatchPath()
      Get the base directory for this WatchService
      Returns:
      the Path that is the base path for all reported events