Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java 7 directory monitoring questions

I just saw an awesome feature with java 7, the directory watcher. It'll tell you when something changed in a directory without polling the directory.

1.) But it says it falls back to polling if the filesystem doesn't support registering for change events. Do all typical linux and windows filesystems(extX,ntfs,reiserXXX,jsf,zfs) support this feature?

2.) Is renaming a file inside a directory a create or a change event? Or is that one delete and one create? I can test it on one system, but will it then be the same for all filesystems?

like image 543
Franz Kafka Avatar asked Jun 11 '11 10:06

Franz Kafka


1 Answers

It looks like you're talking about the WatchService.

The wording of the ENTRY_CREATE event says that a new entry would be perceived if a new file is created or a file is renamed into the directory. It lacks specification of what events are fired if a file is renamed and remains in the same directory.

The wording also states that whether the service is based on the operating system or polling is implementation dependent. I suspect that's implementation by the JRE, so even if you know a particular OS supports it, it's not a guarantee that the service will use the OS-level functionality or resort to polling. In fact, the service does not provide any way to tell whether it is using polling or an OS-level feature at all.

The operations the API define also do not behave like a Listener. The WatchService does do automatic watching, but to acquire the list of events which happen, you still have to manually request the seen events from the service. It doesn't appear to provide any hooks to automatically get called when a new event is present.

like image 117
Atreys Avatar answered Oct 19 '22 11:10

Atreys