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

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

Introduction

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

Prototype

AsyncCallback.StringCallback

Source Link

Usage

From source file:com.jbrisbin.vpc.zk.GroovyZooKeeperHelper.java

License:Apache License

/**
 * Create a ZooKeeper node asynchronously by specifying all parameters.
 *
 * @param path//from  www .  j  a  va 2  s . c o m
 * @param data
 * @param acls
 * @param mode
 * @param callback
 */
public void create(Object path, Object data, List<ACL> acls, CreateMode mode, final Closure callback) {
    zookeeper.create(getPathAsString(path), serialize(data), acls, mode, new AsyncCallback.StringCallback() {
        public void processResult(int rc, String path, Object ctx, String name) {
            callback.setProperty("returnCode", rc);
            callback.setProperty("path", path);
            callback.setDelegate(ctx);
            callback.call(name);
        }
    }, this);
}

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

License:Apache License

@Override
public void asyncAdd(String relativePath, final byte[] data, CreateMode mode, final DirectoryCallback.Add cb) {

    final String absPath = getAbsolutePath(relativePath);

    zk.getZooKeeper().create(absPath, data, acl, mode, new AsyncCallback.StringCallback() {

        @Override// w w w  .  j  a v a 2  s.c o  m
        public void processResult(int rc, String path, Object ctx, String name) {
            KeeperException.Code code = KeeperException.Code.get(rc);
            switch (code) {
            case OK:
                cb.onSuccess(name.substring(basePath.length()));
                break;
            default:
                cb.onError(KeeperException.create(code, path));
            }
        }
    }, null);
}

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

License:Apache License

@Override
public void asyncAdd(String relativePath, final byte[] data, CreateMode mode) {

    final String absPath = getAbsolutePath(relativePath);

    zk.getZooKeeper().create(absPath, data, acl, mode, new AsyncCallback.StringCallback() {
        @Override// w  ww. j a va  2 s  . c om
        public void processResult(int rc, String path, Object ctx, String name) {
        }
    }, null);
}

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

License:Apache License

public void create(final String groupName) {
    if (groupName == null)
        throw new IllegalArgumentException("groupName must not be null");
    String path = String.format("/%s", groupName);
    zooKeeper.create(path, null, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT,
            new AsyncCallback.StringCallback() {
                public void processResult(int rc, String createdPath, Object context, String name) {
                    if (KeeperException.Code.OK.equals(KeeperException.Code.get(rc))) {
                        logger.info("Created {}", createdPath);
                    } else {
                        logger.error("Unable to create {}, {}", createdPath, KeeperException.Code.get(rc));
                    }//from  w w  w  .j  a  va  2s . c  o m
                }
            }, null);
}

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

License:Apache License

public void join(final String groupName, final String memberName) {
    if (groupName == null)
        throw new IllegalArgumentException("groupName must not be null");
    if (memberName == null)
        throw new IllegalArgumentException("memberName must not be null");
    String path = String.format("/%s/%s", groupName, memberName);
    zooKeeper.create(path, null, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL,
            new AsyncCallback.StringCallback() {
                public void processResult(int rc, String createdPath, Object context, String name) {
                    if (KeeperException.Code.OK.equals(KeeperException.Code.get(rc))) {
                        logger.info("Created {}", createdPath);
                    } else {
                        logger.error("Unable to join group {}, {}", createdPath, KeeperException.Code.get(rc));
                    }//ww  w .j  av  a 2s  .co m
                }
            }, null);
}