Package org.syncany.operations.watch
Class DefaultRecursiveWatcher
- java.lang.Object
-
- org.syncany.operations.watch.RecursiveWatcher
-
- org.syncany.operations.watch.DefaultRecursiveWatcher
-
public class DefaultRecursiveWatcher extends RecursiveWatcher
The default recursive file watcher monitors a folder (and its sub-folders) by registering a watch on each of the sub-folders. This class is used on Linux/Unix-based operating systems and uses the Java 7WatchService
.The class walks through the file tree and registers to a watch to every sub-folder. For new folders, a new watch is registered, and stale watches are removed.
When a file event occurs, a timer is started to wait for the file operations to settle. It is reset whenever a new event occurs. When the timer times out, an event is thrown through the
RecursiveWatcher.WatchListener
.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.syncany.operations.watch.RecursiveWatcher
RecursiveWatcher.WatchListener
-
-
Field Summary
-
Fields inherited from class org.syncany.operations.watch.RecursiveWatcher
ignorePaths, logger, root
-
-
Constructor Summary
Constructors Constructor Description DefaultRecursiveWatcher(java.nio.file.Path root, java.util.List<java.nio.file.Path> ignorePaths, int settleDelay, RecursiveWatcher.WatchListener listener)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
afterStop()
Called after theRecursiveWatcher.stop()
method.protected void
beforePollEventLoop()
Called in the watch service polling thread, right before theRecursiveWatcher.pollEvents()
loop.void
beforeStart()
Called before theRecursiveWatcher.start()
method.protected boolean
pollEvents()
Called in the watch service polling thread, inside of theRecursiveWatcher.pollEvents()
loop.protected void
watchEventsOccurred()
Called in the watch service polling thread, whenever a file system event occurs.-
Methods inherited from class org.syncany.operations.watch.RecursiveWatcher
createRecursiveWatcher, start, stop
-
-
-
-
Constructor Detail
-
DefaultRecursiveWatcher
public DefaultRecursiveWatcher(java.nio.file.Path root, java.util.List<java.nio.file.Path> ignorePaths, int settleDelay, RecursiveWatcher.WatchListener listener)
-
-
Method Detail
-
beforeStart
public void beforeStart() throws java.lang.Exception
Description copied from class:RecursiveWatcher
Called before theRecursiveWatcher.start()
method. This method is only called once.- Specified by:
beforeStart
in classRecursiveWatcher
- Throws:
java.lang.Exception
-
beforePollEventLoop
protected void beforePollEventLoop()
Description copied from class:RecursiveWatcher
Called in the watch service polling thread, right before theRecursiveWatcher.pollEvents()
loop. This method is only called once.- Specified by:
beforePollEventLoop
in classRecursiveWatcher
-
pollEvents
protected boolean pollEvents() throws java.lang.InterruptedException
Description copied from class:RecursiveWatcher
Called in the watch service polling thread, inside of theRecursiveWatcher.pollEvents()
loop. This method is called multiple times.- Specified by:
pollEvents
in classRecursiveWatcher
- Throws:
java.lang.InterruptedException
-
watchEventsOccurred
protected void watchEventsOccurred()
Description copied from class:RecursiveWatcher
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.- Specified by:
watchEventsOccurred
in classRecursiveWatcher
-
afterStop
public void afterStop() throws java.io.IOException
Description copied from class:RecursiveWatcher
Called after theRecursiveWatcher.stop()
method. This method is only called once.- Specified by:
afterStop
in classRecursiveWatcher
- Throws:
java.io.IOException
-
-