private int countDescendants(String node) throws InterruptedException, KeeperException { List<String> children = zk.getChildren(node, false); int count = 0; for (String child : children) { count += countDescendants(ZkPath.append(node, child)); } return 1 + count; }
public WatchedEnum(final Class<E> clazz, final ZooKeeperPlus zk, final String nodePath, boolean waitForCreation) throws KeeperException, InterruptedException { this.clazz = clazz; this.watchedString = new WatchedString(zk, nodePath, waitForCreation); this.watchedString.addListener(this); onWatchedNodeChange(watchedString.get()); }
@Override public WatchedThriftNode<ConnectedServerMetadata> load(ZooKeeperPlus zk, String basePath, String relPath) throws KeeperException, InterruptedException, IOException { return new WatchedThriftNode<>(zk, ZkPath.append(basePath, relPath), true, null, null, emptyConnectedServerMetadata); } });
public void deleteNodeRecursively(String path) throws InterruptedException, KeeperException { try { delete(path, -1); } catch (KeeperException.NotEmptyException e) { List<String> children = getChildren(path, null); for (String child : children) { deleteNodeRecursively(ZkPath.append(path, child)); } delete(path, -1); } catch (KeeperException.NoNodeException e) { // Silently return if the node has already been deleted. return; } }
@Override public void detectCompletion(ZooKeeperPlus zk, String basePath, String relPath, CompletionAwaiter awaiter) throws KeeperException, InterruptedException { if (zk.exists(ZkPath.append(basePath, relPath, NODE_NAME), new CreationWatcher(relPath, awaiter)) != null) { awaiter.completed(relPath); } } }
@Override public void setWatch() throws KeeperException, InterruptedException { zk.getChildren(ZkPath.append(path, COMMAND_QUEUE_PATH), this); }
public void ensureCreated(CreateMode createMode) throws InterruptedException, KeeperException { zk.ensureCreated(nodePath, encode(initialValue), createMode); } }
public static Integer get(ZooKeeperPlus zk, String nodePath) throws InterruptedException, KeeperException { return decodeValue(zk.getData(nodePath, null, null)); }
public static Boolean get(ZooKeeperPlus zk, String nodePath) throws InterruptedException, KeeperException { return decodeValue(zk.getData(nodePath, null, null)); }
@Override public void onWatchedNodeChange(String value) { cachedValue = getEnumValue(value); synchronized (listeners) { for (WatchedNodeListener<E> listener : listeners) { listener.onWatchedNodeChange(cachedValue); } } }
@Override public void detectCompletion(ZooKeeperPlus zk, String basePath, String relPath, CompletionAwaiter awaiter) throws KeeperException, InterruptedException { awaiter.completed(relPath); } };
protected void notifyCurrentCommandChangeListeners() { for (WatchedNodeListener<HostCommand> listener : currentCommandChangeListeners) { listener.onWatchedNodeChange(currentCommand); } }
@Override public HostState getState() throws IOException { HostState stateValue = state.get(); if (stateValue == null) { return HostState.OFFLINE; } else { return stateValue; } }
@Override protected byte[] encode(Boolean v) { return encodeValue(v); } }
private void fireListeners() { synchronized (listeners) { for (WatchedMapListener<T> listener : listeners) { listener.onWatchedMapChange(this); } } }
@Override public WatchedThriftNode<ClientMetadata> load(ZooKeeperPlus zk, String basePath, String relPath) throws KeeperException, InterruptedException, IOException { return new WatchedThriftNode<ClientMetadata>(zk, ZkPath.append(basePath, relPath), true, null, null, emptyClientMetadata); } });
private void notifyHostStateChangeListeners() { for (WatchedNodeListener<HostState> listener : hostStateChangeListeners) { listener.onWatchedNodeChange(state); } }