NIO Watch Service Feedback

Robert MacGrogan robertmacgrogan at yahoo.com
Thu Nov 12 08:26:50 PST 2009


First of all, I want to say how happy I am to have support for file system events in Java. And the sample WatchDir program provided with the early JDK 7 distribution was a huge help to me in understanding how this new API works.

That said, I have a couple of comments.

First of all, I believe I found a bug. If you rename a file or directory inside of a watched directory, a Create event will be generated for the new file/directory name. No Delete or Modify event will be created. It seems to me that it would be better to either have a rename generate a Modify event or a Delete on the old Path followed by a Create on the new Path.

Second, the Watch Service API is fairly tricky to use. To implement anything with it you are essentially required to spawn a thread to listen for events (unless I'm really missing something). It seems to me that there is a need for an additional layer of abstraction on top of the current API, something following the Listener pattern. Something like this would be nice:

Path.addPathEventListener(new PathEventAdapter() {
    public void childFileModified(WatchEvent<Path> event){
        System.out.println("File modified.");
    }
});

It may be too late to add anything like this to Java 7. If so, hopefully someone will write a little tool to make something close to the above possible and release it open-source.

Thanks again for this great addition. This is a life saver for me and the timing couldn't be better.

--Rob MacGrogan



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/nio-dev/attachments/20091112/8ea698a7/attachment.html 


More information about the nio-dev mailing list