WatchService
Johannes.Lichtenberger
Johannes.Lichtenberger at uni-konstanz.de
Tue Jan 24 15:51:56 PST 2012
Hello,
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.
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 just realized that I have to check for DELETES that a file really
doesn't exist anymore, but I'm furthermore not sure how to check if a
file has really been create as checking for type == ENTRY_CREATE &&
Files.exists(pPath) doesn't work. I suppose the file hasn't been "fully"
created and the event is sometimes fired too early. I just want to keep
the directory and the database I'm building in synch.
Thanks for any suggestions.
kind regards,
Johannes
More information about the nio-discuss
mailing list