Package gw.fs.watcher
Class DirectoryWatcher
java.lang.Object
gw.fs.watcher.DirectoryWatcher
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionChecks all the watched directories (that are being kept in a map) for changes since the last call to this method.void
Close the watch service.private void
watchDirectory
(Path dir) void
watchDirectoryTree
(Path dir) Walk the directories under given path, and register a watcher for every directory.
-
Field Details
-
_watchService
-
_watchedDirectories
-
-
Constructor Details
-
DirectoryWatcher
public DirectoryWatcher()
-
-
Method Details
-
stopWatching
public void stopWatching()Close the watch service. Releases resources. After calling, this instance becomes invalid and can't be used any more. -
watchDirectoryTree
Walk the directories under given path, and register a watcher for every directory.- Parameters:
dir
- the starting point under which to listen for changes, if it doesn't exist, do nothing.
-
watchDirectory
- Throws:
IOException
-
getChangesSinceLastTime
Checks all the watched directories (that are being kept in a map) for changes since the last call to this method. If a file is already marked as CREATE, leave it as CREATE; if it's marked as DELETE, that's totally invalid, so just ignore that. If it's marked as MODIFY, no need to change it. So only put something in the map if it's not already in there. If a create follows a delete, it means the editor deleted and re-created the file, and who knows what the contents are now, so it should be treated as a modification. If the file was created, then deleted, then just ignore it entirely and remove the event.- Returns:
- FileEvent enum for each watched Path found, indicating the type of modification that happened.
-