Recursive Watcher, Moved From/To

Asked by Philipp C. Heckel

Hey Nick,

thanks again for your great project. One of my projects strongly relies on it!
I wrote two classes that I think were missing in inotify-java.

1) RecursiveWatcher
In another question I asked you about a recursive watcher, i.e. a watcher that monitors newly created folders as well and dynamically adds/removes watches for all sub-folders. Since the given classes did not support that, I wrote a class called RecursiveWatcher that does exactly that.

EXAMPLE:
int wd = watcher.addRecursiveWatch("/home/user/Photos", ...);
watcher.addRecursiveListener(wd, new InotifyEventListener() {
  public void filesystemEventOccurred(InotifyEvent e) {
      System.out.println(e);
  }
  ...
});

The recursive watcher first indexes all sub-directories of the "Photos" folder, and then sets watches to each of them e.g. "Photos/Album1" and "Photos/Album2". When a new album is created, or sub-folders are added to "Photos/AlbumXX", it also registers watches for these folders. Hence events are thrown for all subfolders.

2) BufferedRecursiveWatcher: Match Moved_From/To events
A second thing I really needed for my application was to not only receive Move_From and Move_To events, but directly receiving Move_From_To events from the watcher. Since inotify throws these events separately, I wrote a little class called BufferedRecursiveWatcher (based on the RecursiveWatcher from above), that keeps a 200ms buffer for file system events and matches Moved_To/From events together. Instead of firing all events directly, it delays them and groups the Moved_From/To events.

Are you generally interested in adding my code to the project? Unfortunately it is based on the 2.0.1 version and needs some cleanup and testing. If you are interested, I could branch the 2.0.1 version and upload it to Launchpad...

Regards,
Philipp

Question information

Language:
English Edit question
Status:
Solved
For:
inotify-java Edit question
Assignee:
No assignee Edit question
Solved by:
Philipp C. Heckel
Solved:
Last query:
Last reply:
Revision history for this message
Nick Bargnesi (nbargnesi) said :
#1

Yes, either a patch against 2.0.1 or a branch to pull from would be fine.

I can take a look at integrating both pieces of functionality.

Thanks!

Revision history for this message
Philipp C. Heckel (binwiederhier) said :
#2

Hey Nick,

here's the branch: https://code.launchpad.net/~binwiederhier/inotify-java/recursive

I included a BufferedRecursiveWatcherTest class so you can test it. It works okay, but still has a lot of unclean code and flaws. I'd call its current state "functional" :-)

Regards,
Philipp

Revision history for this message
1x6PY78 (1x6py78) said :
#3

Hi!

Any news on this? Is this new function usable with inotify-java 2.0.2?

Thanks in advance for a reply