in twill-zookeeper/src/main/java/org/apache/twill/internal/zookeeper/RewatchOnExpireWatcher.java [128:172]
private void children() {
Futures.addCallback(client.getChildren(path, this), new FutureCallback<NodeChildren>() {
@Override
public void onSuccess(NodeChildren result) {
Object oldResult = lastResult.getReference();
lastResult.compareAndSet(oldResult, null, true, false);
if (result.equals(oldResult)) {
return;
}
if (!(oldResult instanceof NodeChildren)) {
// Something very wrong
LOG.error("The same watcher has been used for different event type.");
return;
}
NodeChildren oldNodeChildren = (NodeChildren) oldResult;
if (!result.getChildren().equals(oldNodeChildren.getChildren())) {
process(new WatchedEvent(Event.EventType.NodeChildrenChanged, Event.KeeperState.SyncConnected, path));
} else {
process(new WatchedEvent(Event.EventType.NodeDataChanged, Event.KeeperState.SyncConnected, path));
}
}
@Override
public void onFailure(Throwable t) {
if (RetryUtils.canRetry(t)) {
children();
return;
}
lastResult.set(null, false);
if (t instanceof KeeperException) {
KeeperException.Code code = ((KeeperException) t).code();
if (code == KeeperException.Code.NONODE) {
// Node deleted
process(new WatchedEvent(Event.EventType.NodeDeleted, Event.KeeperState.SyncConnected, path));
return;
}
}
LOG.error("Fail to re-set watch on getChildren for path " + path, t);
}
});
}