Class AbstractWatchService

  • public abstract class AbstractWatchService
    extends Object
    Base class for OSGI services that access to file system by Java WatchService.
    See the WatchService java docs for more details
    Fabio Marini - Initial contribution, Dimitar Ivanov - added javadoc; introduced WatchKey to directory mapping for the queue reader, Ana Dimova - reduce to a single watch thread for all class instances of AbstractWatchService
    • Field Detail

      • logger

        protected final org.slf4j.Logger logger
        Default logger for Watch Services
      • pathToWatch

        protected String pathToWatch
      • watchQueueReader

        protected WatchQueueReader watchQueueReader
        The queue reader
    • Constructor Detail

      • AbstractWatchService

        protected AbstractWatchService​(String pathToWatch)
    • Method Detail

      • activate

        public void activate()
        Method to call on service activation
      • deactivate

        public void deactivate()
        Method to call on service deactivation
      • watchSubDirectories

        protected abstract boolean watchSubDirectories()
        Determines whether the subdirectories of the source path (determined by the getSourcePath()) will be watched or not.
        true if the subdirectories will be watched and false if only the source path (determined by the getSourcePath()) will be watched
      • getWatchEventKinds

        protected abstract WatchEvent.Kind<?>[] getWatchEventKinds​(Path directory)
        Provides the WatchKeys for the registration of the directory, which will be registered in the watch service.
        directory - the directory, which will be registered in the watch service
        The array of WatchKeys for the registration or null if no registration has been done.
      • processWatchEvent

        protected abstract void processWatchEvent​(WatchEvent<?> event,
                                                  WatchEvent.Kind<?> kind,
                                                  Path path)
        Processes the given watch event. Note that the kind and the number of the events for the watched directory is a platform dependent (see the "Platform dependencies" sections of WatchService).
        event - the watch event to be handled
        kind - the event's kind
        path - the path of the event (resolved to the #baseWatchedDir)