WatchService

Johannes.Lichtenberger Johannes.Lichtenberger at uni-konstanz.de
Tue Jan 24 19:12:23 PST 2012


On 01/25/2012 12:51 AM, Johannes.Lichtenberger wrote:
> I'm currently watching a directory with all it's subdirectories for
> changes. Furthermore I'm registering newly inserted directories at the
> WatchService. I furthermore like to create the appropriate CREATE event
> right after the subdirectories are registered. Is this possible with the
> public API to create events? I don't think so.
> 
> for (int i = 0; i < ev.count(); i++) {
>   final Path name = ev.context();
>   final Path child = dir.resolve(name);
> 
>   if (kind == ENTRY_CREATE && Files.isDirectory(child, NOFOLLOW_LINKS)) {
>     Files.walkFileTree(child, fileVisitor);
>   }
> 
>   processEvent(ev, pVisitor, index, watcher, child);
> }
> 
> So I don't have to refactor processEvent(...) to use paths instead and
> to exclude it in another class for usage within the fileVisitor.

Ok forget about this part, I'm now using the Paths directly to insert
into the database instead of rushing through the events.

That is I'm invoking entryCreated(pVisitor, pIndex, pPath); directly in
the case of subsequent INSERTS through sub-directories/files.

> Furthermore I think this is incorrect or not sufficient in most cases
> (inside processEvent(...)):
> 
> if (type == ENTRY_CREATE) {
>   entryCreated(pVisitor, pIndex, pPath);
> } else if (type == ENTRY_DELETE && !Files.exists(pPath)) {
>   entryDeletes(pVisitor, pIndex, pPath);
> } else if (type == ENTRY_MODIFY) {
>   entryModified(pVisitor, pIndex, pPath);
> }

I'm still not sure about this code snippet. In case the permissions are
there to CREATE events it seems to work, however I have to test for
inserted files/directories, which can't be created, but I suppose the
events still show up.

kind regards,
Johannes




More information about the nio-discuss mailing list