Example usage for org.apache.zookeeper AsyncCallback.Children2Callback AsyncCallback.Children2Callback

List of usage examples for org.apache.zookeeper AsyncCallback.Children2Callback AsyncCallback.Children2Callback

Introduction

In this page you can find the example usage for org.apache.zookeeper AsyncCallback.Children2Callback AsyncCallback.Children2Callback.

Prototype

AsyncCallback.Children2Callback

Source Link

Usage

From source file:org.midonet.midolman.state.ZkDirectory.java

License:Apache License

@Override
public void asyncGetChildren(String relativePath, final DirectoryCallback<Set<String>> cb,
        TypedWatcher watcher) {//w  w  w. ja v a  2 s . com
    zk.getZooKeeper().getChildren(getAbsolutePath(relativePath), wrapCallback(watcher),
            new AsyncCallback.Children2Callback() {
                @Override
                public void processResult(int rc, String path, Object ctx, List<String> children, Stat stat) {
                    if (rc == KeeperException.Code.OK.intValue()) {
                        cb.onSuccess(new HashSet<String>(children));
                    } else {
                        cb.onError(KeeperException.create(KeeperException.Code.get(rc), path));
                    }
                }
            }, null);
}

From source file:org.rioproject.zookeeper.client.GroupManagement.java

License:Apache License

public void delete(final String groupName) {
    if (groupName == null)
        throw new IllegalArgumentException("groupName must not be null");
    String path = String.format("/%s", groupName);
    zooKeeper.getChildren(path, false, new AsyncCallback.Children2Callback() {
        public void processResult(int rc, String path, Object context, List<String> children, Stat stat) {
            try {
                for (String child : children) {
                    zooKeeper.delete(String.format("%s/%s", path, child), -1);
                }//from  ww  w .jav  a 2  s . com
                zooKeeper.delete(path, -1);
            } catch (KeeperException.NoNodeException e) {
                logger.warn("Group {} does not exist", groupName);
            } catch (InterruptedException e) {
                logger.warn("Transaction was interrupted", e);
            } catch (KeeperException e) {
                logger.warn("Server error", e);
            }
        }
    }, null);
}

From source file:org.rioproject.zookeeper.watcher.ZooKeeperServiceWatcher.java

License:Apache License

/**
 * Add a service to watch.//from   ww  w  .  jav  a 2 s. com
 *
 * @param zNode The ZooKeeper node (zNode), must not be {@code null}.
 * @param listener The {@link FaultDetectionListener} to be notified if the service fails.
 *
 * @throws IllegalArgumentException if the {@code zNode} or {@code listener} is {@code null}.
 */
public void addService(final String zNode, final FaultDetectionListener<String> listener) {
    if (zNode == null)
        throw new IllegalArgumentException("zNode can not be null");
    if (listener == null)
        throw new IllegalArgumentException("listener can not be null");
    zooKeeper.getChildren(zNode, true, new AsyncCallback.Children2Callback() {
        public void processResult(int rc, String path, Object o, List<String> strings, Stat stat) {
            if (KeeperException.Code.OK.equals(KeeperException.Code.get(rc))) {
                services.put(zNode, listener);
            } else {
                logger.error("Unable to add watch for {}, {}", zNode, KeeperException.Code.get(rc));
            }
        }
    }, null);
}