Class RecursiveWatcher

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.List<java.nio.file.Path> ignorePaths  
      protected static java.util.logging.Logger logger  
      protected java.nio.file.Path root  
    • Field Detail

      • logger

        protected static final java.util.logging.Logger logger
      • root

        protected java.nio.file.Path root
      • ignorePaths

        protected java.util.List<java.nio.file.Path> ignorePaths
    • Method Detail

      • start

        public void start()
                   throws java.lang.Exception
        Starts the watcher service and registers watches in all of the sub-folders of the given root folder.

        This method calls the beforeStart() method before everything else. Subclasses may execute their own commands there. Before the watch thread is started, beforePollEventLoop() is called. And in the watch thread loop, pollEvents() is called.

        Important: This method returns immediately, even though the watches might not be in place yet. For large file trees, it might take several seconds until all directories are being monitored. For normal cases (1-100 folders), this should not take longer than a few milliseconds.

        Throws:
        java.lang.Exception
      • stop

        public void stop()
        Stops the watch thread by interrupting it and subsequently calls the afterStop() template method (to be implemented by subclasses.
      • beforeStart

        protected abstract void beforeStart()
                                     throws java.lang.Exception
        Called before the start() method. This method is only called once.
        Throws:
        java.lang.Exception
      • beforePollEventLoop

        protected abstract void beforePollEventLoop()
        Called in the watch service polling thread, right before the pollEvents() loop. This method is only called once.
      • pollEvents

        protected abstract boolean pollEvents()
                                       throws java.lang.InterruptedException
        Called in the watch service polling thread, inside of the pollEvents() loop. This method is called multiple times.
        Throws:
        java.lang.InterruptedException
      • watchEventsOccurred

        protected abstract void watchEventsOccurred()
        Called in the watch service polling thread, whenever a file system event occurs. This may be used by subclasses to (re-)set watches on folders. This method is called multiple times.
      • afterStop

        protected abstract void afterStop()
                                   throws java.io.IOException
        Called after the stop() method. This method is only called once.
        Throws:
        java.io.IOException