in curator-framework/src/main/java/org/apache/curator/framework/imps/RemoveWatchesBuilderImpl.java [218:262]
private void pathInForeground(final String path) throws Exception {
NamespaceWatcher namespaceWatcher = makeNamespaceWatcher(path);
// For the local case we don't want to use the normal retry loop and we don't want to block until a connection
// is available.
// We just execute the removeWatch, and if it fails, ZK will just remove local watches.
if (local) {
ZooKeeper zkClient = client.getZooKeeper();
if (namespaceWatcher != null) {
zkClient.removeWatches(path, namespaceWatcher, watcherType, local);
} else {
zkClient.removeAllWatches(path, watcherType, local);
}
} else {
final NamespaceWatcher finalNamespaceWatcher = namespaceWatcher;
RetryLoop.callWithRetry(client.getZookeeperClient(), new Callable<Void>() {
@Override
public Void call() throws Exception {
try {
ZooKeeper zkClient = client.getZookeeperClient().getZooKeeper();
if (finalNamespaceWatcher != null) {
zkClient.removeWatches(path, finalNamespaceWatcher, watcherType, false);
} else {
zkClient.removeAllWatches(path, watcherType, false);
}
} catch (Exception e) {
if (client.getZookeeperClient().getRetryPolicy().allowRetry(e) && guaranteed) {
// Setup the guaranteed handler
client.getFailedRemoveWatcherManager()
.addFailedOperation(new FailedRemoveWatchManager.FailedRemoveWatchDetails(
path, finalNamespaceWatcher));
throw e;
} else if (e instanceof KeeperException.NoWatcherException && quietly) {
// ignore
} else {
// Rethrow
throw e;
}
}
return null;
}
});
}
}