@Override public void run() { logIfFailed(zkClient.delete(path, version)); } };
@Override public OperationFuture<Stat> exists(String path, @Nullable Watcher watcher) { return client.exists(path, watcher); }
@Override public OperationFuture<String> create(String path, @Nullable byte[] data, CreateMode createMode, boolean createParent, Iterable<ACL> acl) { return delegate.create(path, data, createMode, createParent, acl); }
@Override public OperationFuture<NodeData> exec(String path, Watcher watcher) { return zkClient.getData(path, watcher); } }, path, callback, cancelled);
private OperationFuture<String> removeLiveNode() { String liveNode = getLiveNodePath(); LOG.info("Remove live node {}{}", zkClient.getConnectString(), liveNode); return ZKOperations.ignoreError(zkClient.delete(liveNode), KeeperException.NoNodeException.class, liveNode); }
@Override public void onFailure(Throwable t) { // Just log LOG.error("Failed to getData on ZK node {}{}", zkClient.getConnectString(), path, t); } }), executor);
@Override protected void startUp() throws Exception { LOG.info("Creating container ZK path: {}{}", zkClient.getConnectString(), path); ZKOperations.ignoreError(zkClient.create(path, null, CreateMode.PERSISTENT), KeeperException.NodeExistsException.class, null).get(TIMEOUT_SECONDS, TimeUnit.SECONDS); }
@Override public OperationFuture<NodeChildren> exec(String path, Watcher watcher) { return zkClient.getChildren(path, watcher); } }, path, callback, cancelled);
watcherCancellable = zkClient.addConnectionWatcher(new Watcher() { private boolean expired = false; ZKOperations.ignoreError(zkClient.create(getZKPath("messages"), null, CreateMode.PERSISTENT), KeeperException.NodeExistsException.class, null).get();
/** * Update the live node for the service. * * @return A {@link OperationFuture} that will be completed when the update is done. */ protected final OperationFuture<?> updateLiveNode() { String liveNodePath = getLiveNodePath(); LOG.info("Update live node {}{}", zkClient.getConnectString(), liveNodePath); return zkClient.setData(liveNodePath, serializeLiveNode()); }
private long generateId(Type type) { idLock.get().lock(); try { NodeData nodeData = Futures.getUnchecked(zkClient.getData(type.path)); long counterVal = Longs.fromByteArray(nodeData.getData()); Futures.getUnchecked(zkClient.setData(type.path, Longs.toByteArray(counterVal + incrementBy))); return counterVal; } finally { idLock.get().unlock(); } }
@Override public Cancellable addConnectionWatcher(Watcher watcher) { return delegate.addConnectionWatcher(watcher); }
@Override public OperationFuture<Stat> setData(String dataPath, byte[] data, int version) { return delegate.setData(dataPath, data, version); }
public void init() throws InterruptedException { this.watcher = new ZKWatcher(); try { LOG.info("Initializing SharedResourceCache. Checking for parent znode {}", parentZnode); if (zookeeper.exists(parentZnode).get() == null) { // may be created in parallel by another instance // Also the child nodes are secure even without adding any ACLs to parent node. ZKOperations.ignoreError(zookeeper.create(parentZnode, null, CreateMode.PERSISTENT), KeeperException.NodeExistsException.class, null).get(); } } catch (ExecutionException ee) { // recheck if already created throw Throwables.propagate(ee.getCause()); } this.resources = reloadAll(); listeners.notifyUpdate(); }
@Override public OperationFuture<NodeData> exec(String path, Watcher watcher) { return zkClient.getData(path, watcher); } }, path, callback, cancelled);
private OperationFuture<String> removeLiveNode() { String liveNode = getLiveNodePath(); LOG.info("Remove live node {}{}", zkClient.getConnectString(), liveNode); return ZKOperations.ignoreError(zkClient.delete(liveNode), KeeperException.NoNodeException.class, liveNode); }
@Override public void onFailure(Throwable t) { // Something very wrong to have exists call failed. LOG.error("Failed to call exists on ZK node {}{}", zkClient.getConnectString(), CoordinationConstants.REQUIREMENTS_PATH, t); doNotifyFailed(t); } }), executor);
@Override protected void startUp() throws Exception { LOG.info("Creating container ZK path: {}{}", zkClient.getConnectString(), path); ZKOperations.ignoreError(zkClient.create(path, null, CreateMode.PERSISTENT), KeeperException.NodeExistsException.class, null).get(TIMEOUT_SECONDS, TimeUnit.SECONDS); }
@Override public OperationFuture<NodeChildren> exec(String path, Watcher watcher) { return zkClient.getChildren(path, watcher); } }, path, callback, cancelled);