@Override public synchronized boolean reset(PathWatchKey pathWatchKey) { if (!pathWatchKey.isValid()) return false; if (pathWatchKey.hasPendingWatchEvents()) pendingWatchKeys.add(pathWatchKey); else signalledWatchKeys.remove(pathWatchKey); return true; }
private boolean cancelImpl(PathWatchKey pathWatchKey, boolean removeKey) { PathImpl pathImpl = (PathImpl) pathWatchKey.getPath(); String pathString = pathImpl.getFile().getPath(); Integer dirfdInteger = dirs.get(pathString); // check if the key that was passed in is ours if (dirfdInteger == null) return false; // FIXME: should throw an exception in this case PathWatchKey key = keys.get(dirfdInteger); if (key != pathWatchKey) return false; // FIXME: should throw an exception in this case boolean eventAdded = false; if ((key.getFlags() & FLAG_FILTER_KEY_INVALID) != 0) { key.addWatchEvent(new VoidWatchEvent(ExtendedWatchEventKind.KEY_INVALID)); eventAdded = true; } // if we get here, the key is ours, so we'll invalidate it and // remove it now. int dirfd = dirfdInteger.intValue(); kevent[] changelist = new kevent[] {new kevent()}; changelist[0].set_ident(dirfd); changelist[0].set_filter(EVFILT_VNODE); changelist[0].set_flags(EV_DELETE); int result = kevent(kqueuefd, changelist, null, null); assert (result == 0); key.invalidate(); if ((key.getFlags() & FLAG_FILTER_ENTRY_MODIFY) != 0) --numKeysRequiringPolling; if (removeKey) { keys.remove(dirfdInteger); } dirs.remove(pathString); return eventAdded; }