public synchronized Stat exists(long sessionId, String path, Watcher watcher)
throws KeeperException {
try {
ZNode node =
isRootPath(path) ? root : root.findDescendant(stripRootFromPath(path));
if (watcher != null) {
node.addWatcher(sessionId, watcher, WatchTriggerPolicy.WatchType.EXISTS);
}
Stat stat = new Stat();
DataTree.copyStat(node.getStat(), stat);
return stat;
} catch (KeeperException.NoNodeException e) {
if (watcher != null) {
if (!creationWatchers.containsKey(path)) {
creationWatchers.put(path, new RetrieveableSet<ContextedWatcher>());
}
ContextedWatcher contextedWatcher =
new ContextedWatcher(
watcher,
sessionId,
WatchTriggerPolicy.WatchType.EXISTS
);
if (!creationWatchers.get(path).contains(contextedWatcher)) {
creationWatchers.get(path).add(contextedWatcher);
}
}
return null;
}
}