org.apache.zookeeper.AsyncCallback.ChildrenCallback Java Examples

The following examples show how to use org.apache.zookeeper.AsyncCallback.ChildrenCallback. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MockZooKeeper.java    From pulsar with Apache License 2.0 4 votes vote down vote up
@Override
public void getChildren(final String path, final Watcher watcher, final ChildrenCallback cb, final Object ctx) {
    executor.execute(() -> {
        mutex.lock();
        Optional<KeeperException.Code> failure = programmedFailure(Op.GET_CHILDREN, path);
        if (failure.isPresent()) {
            mutex.unlock();
            cb.processResult(failure.get().intValue(), path, ctx, null);
            return;
        } else if (stopped) {
            mutex.unlock();
            cb.processResult(KeeperException.Code.ConnectionLoss, path, ctx, null);
            return;
        }

        if (!tree.containsKey(path)) {
            mutex.unlock();
            cb.processResult(KeeperException.Code.NoNode, path, ctx, null);
            return;
        }

        List<String> children = Lists.newArrayList();
        for (String item : tree.tailMap(path).keySet()) {
            if (!item.startsWith(path)) {
                break;
            } else {
                if (path.length() >= item.length()) {
                    continue;
                }

                String child = item.substring(path.length() + 1);
                if (item.charAt(path.length()) == '/' && !child.contains("/")) {
                    children.add(child);
                }
            }
        }

        if (watcher != null) {
            watchers.put(path, watcher);
        }
        mutex.unlock();

        cb.processResult(0, path, ctx, children);
    });
}
 
Example #2
Source File: ZooKeeperClient.java    From Mario with Apache License 2.0 4 votes vote down vote up
public void getChildren(String path, boolean watch, ChildrenCallback cb,
    Object ctx) {
    zk.getChildren(path, watch, cb, ctx);
}