@Override public void performBackgroundOperation(final OperationAndData<String> operationAndData) throws Exception { final TimeTrace trace = client.getZookeeperClient().startTracer("ExistsBuilderImpl-Background"); AsyncCallback.StatCallback callback = new AsyncCallback.StatCallback() { @Override public void processResult(int rc, String path, Object ctx, Stat stat) { trace.commit(); CuratorEvent event = new CuratorEventImpl( CuratorEventType.EXISTS, rc, path, null, ctx, stat, null, null, null, null); client.processBackgroundOperation(operationAndData, event); } }; if (watching.isWatched()) { client .getZooKeeper() .exists(operationAndData.getData(), true, callback, backgrounding.getContext()); } else { client .getZooKeeper() .exists( operationAndData.getData(), watching.getWatcher(), callback, backgrounding.getContext()); } }
@Override public Stat forPath(String path) throws Exception { path = client.fixForNamespace(path); Stat returnStat = null; if (backgrounding.inBackground()) { client.processBackgroundOperation( new OperationAndData<String>(this, path, backgrounding.getCallback()), null); } else { returnStat = pathInForeground(path); } return returnStat; }
private Stat pathInForeground(final String path) throws Exception { TimeTrace trace = client.getZookeeperClient().startTracer("ExistsBuilderImpl-Foreground"); Stat returnStat = RetryLoop.callWithRetry( client.getZookeeperClient(), new Callable<Stat>() { @Override public Stat call() throws Exception { Stat returnStat; if (watching.isWatched()) { returnStat = client.getZooKeeper().exists(path, true); } else { returnStat = client.getZooKeeper().exists(path, watching.getWatcher()); } return returnStat; } }); trace.commit(); return returnStat; }
Watching(CuratorFrameworkImpl client, CuratorWatcher watcher) { this.watcher = client.getNamespaceWatcherMap().getNamespaceWatcher(watcher); this.watched = false; }