Example usage for org.apache.zookeeper KeeperException code

List of usage examples for org.apache.zookeeper KeeperException code

Introduction

In this page you can find the example usage for org.apache.zookeeper KeeperException code.

Prototype

Code code

To view the source code for org.apache.zookeeper KeeperException code.

Click Source Link

Usage

From source file:com.linkedin.parseq.zk.client.ZKClient.java

License:Apache License

/**
 * Returns task that will create znode for the given path with the given data and acl.
 *
 * @param path  path of the znode./* w  w  w .  ja va  2 s. c  o  m*/
 * @param data  data of the znode.
 * @param acl   acl of the znode.
 * @param createMode create mode which specifies whether the znode is persistent
 *                   or ephemeral.
 * @return task to create znode.
 */
public Task<String> create(String path, byte[] data, List<ACL> acl, CreateMode createMode) {
    return Task.async("zkCreate: " + path, () -> {
        SettablePromise<String> promise = Promises.settable();
        _zkClient.create(path, data, acl, createMode, (int rc, String p, Object ctx, String name) -> {
            KeeperException.Code code = KeeperException.Code.get(rc);
            switch (code) {
            case OK:
                promise.done(name);
                break;
            default:
                promise.fail(KeeperException.create(code, p));
            }
        }, null);
        return promise;
    });
}

From source file:com.linkedin.parseq.zk.client.ZKClient.java

License:Apache License

/**
 * Returns task that will get data of the znode of the given path.
 *
 * @param path  path of the znode.//w  w w .  j  a  v a  2  s.com
 * @return task to get data.
 */
public WatchableTask<ZKData> getData(String path) {
    return new WatchableTask<ZKData>("zkGetData: " + path) {
        @Override
        protected Promise<? extends ZKData> run(Context context) throws Throwable {
            SettablePromise<ZKData> promise = Promises.settable();
            _zkClient.getData(path, _watcher, (int rc, String p, Object ctx, byte[] data, Stat stat) -> {
                KeeperException.Code code = KeeperException.Code.get(rc);
                switch (code) {
                case OK:
                    promise.done(new ZKData(p, data, stat));
                    break;
                default:
                    promise.fail(KeeperException.create(code, p));
                }
            }, null);
            return promise;
        }
    };
}

From source file:com.linkedin.parseq.zk.client.ZKClient.java

License:Apache License

/**
 * Returns task that will set the data for the node of the given path if
 * such a node exists and the given version matches the version of the node
 * (if the given version is -1, it matches any node's versions).
 *
 * @param path  path of the znode.//from  w  w w  . ja  v  a 2 s  .com
 * @param data  znode data to set.
 * @param version expected matching version.
 * @return task to set data.
 */
public Task<Stat> setData(String path, byte[] data, int version) {
    return Task.async("zkSetData: " + path, () -> {
        SettablePromise<Stat> promise = Promises.settable();
        _zkClient.setData(path, data, version, (int rc, String p, Object ctx, Stat stat) -> {
            KeeperException.Code code = KeeperException.Code.get(rc);
            switch (code) {
            case OK:
                promise.done(stat);
                break;
            default:
                promise.fail(KeeperException.create(code, p));
            }
        }, null);
        return promise;
    });
}

From source file:com.linkedin.parseq.zk.client.ZKClient.java

License:Apache License

/**
 * Returns task that will get children for the znode of the given path.
 *
 * @param path path to the znode./*w w  w.j a v a 2s  .  c  om*/
 * @return task to get children.
 */
public WatchableTask<List<String>> getChildren(String path) {
    return new WatchableTask<List<String>>("zkGetChildren: " + path) {
        @Override
        protected Promise run(Context context) throws Throwable {
            SettablePromise<List<String>> promise = Promises.settable();
            _zkClient.getChildren(path, _watcher, (int rc, String p, Object ctx, List<String> children) -> {
                KeeperException.Code code = KeeperException.Code.get(rc);
                switch (code) {
                case OK:
                    promise.done(children);
                    break;
                default:
                    promise.fail(KeeperException.create(code, p));
                }
            }, null);
            return promise;
        }
    };
}

From source file:com.linkedin.parseq.zk.client.ZKClient.java

License:Apache License

/**
 * Returns task that will test whether the znode of the given path exists
 * or not. If exists, the {@link Stat} of the znode is returned.
 *
 * @param path path to the znode.// ww w  . j av a2 s. c o  m
 * @return task to test existence of the znode.
 */
public WatchableTask<Optional<Stat>> exists(String path) {
    return new WatchableTask<Optional<Stat>>("zkExists: " + path) {
        @Override
        protected Promise run(Context context) throws Throwable {
            SettablePromise<Optional<Stat>> promise = Promises.settable();
            _zkClient.exists(path, _watcher, (int rc, String p, Object ctx, Stat stat) -> {
                KeeperException.Code code = KeeperException.Code.get(rc);
                switch (code) {
                case OK:
                    promise.done(Optional.of(stat));
                    break;
                case NONODE:
                    promise.done(Optional.empty());
                    break;
                default:
                    promise.fail(KeeperException.create(code, p));
                }
            }, null);
            return promise;
        }
    };
}

From source file:com.linkedin.parseq.zk.client.ZKClient.java

License:Apache License

/**
 * Returns task to delete znode of the given path if such a node exists
 * and the given version matches the version of the node (if the given
 * version is -1, it matches any node's versions).
 *
 * @param path path to the znode./* w  w w. j  av  a 2  s  .  com*/
 * @param version expected matching version.
 * @return task to delete znode.
 */
public Task<Void> delete(String path, int version) {
    return Task.async("zkDelete: " + path, () -> {
        SettablePromise<Void> promise = Promises.settable();
        _zkClient.delete(path, version, (int rc, String p, Object ctx) -> {
            KeeperException.Code code = KeeperException.Code.get(rc);
            switch (code) {
            case OK:
                promise.done(null);
                break;
            default:
                promise.fail(KeeperException.create(code, p));
            }
        }, null);
        return promise;
    });
}

From source file:com.linkedin.parseq.zk.client.ZKClientImpl.java

License:Apache License

/**
 * {@inheritDoc}//from ww  w  .  j a  v a 2s.c  o m
 */
@Override
public Task<String> create(String path, byte[] data, List<ACL> acl, CreateMode createMode) {
    return Task.async("zkCreate: " + path, () -> {
        SettablePromise<String> promise = Promises.settable();
        _zkClient.create(path, data, acl, createMode, (int rc, String p, Object ctx, String name) -> {
            KeeperException.Code code = KeeperException.Code.get(rc);
            switch (code) {
            case OK:
                promise.done(name);
                break;
            default:
                promise.fail(KeeperException.create(code, p));
            }
        }, null);
        return promise;
    });
}

From source file:com.linkedin.parseq.zk.client.ZKClientImpl.java

License:Apache License

/**
 * {@inheritDoc}/*  w  w w.  j  a v  a 2  s  .c o m*/
 */
@Override
public WatchableTask<ZKData> getData(String path) {
    return new WatchableTask<ZKData>("zkGetData: " + path) {
        @Override
        protected Promise<? extends ZKData> run(Context context) throws Throwable {
            SettablePromise<ZKData> promise = Promises.settable();
            _zkClient.getData(path, _watcher, (int rc, String p, Object ctx, byte[] data, Stat stat) -> {
                KeeperException.Code code = KeeperException.Code.get(rc);
                switch (code) {
                case OK:
                    promise.done(new ZKData(p, data, stat));
                    break;
                default:
                    promise.fail(KeeperException.create(code, p));
                }
            }, null);
            return promise;
        }
    };
}

From source file:com.linkedin.parseq.zk.client.ZKClientImpl.java

License:Apache License

/**
 * {@inheritDoc}// w ww  . ja  v  a 2  s .c  o m
 */
@Override
public Task<Stat> setData(String path, byte[] data, int version) {
    return Task.async("zkSetData: " + path, () -> {
        SettablePromise<Stat> promise = Promises.settable();
        _zkClient.setData(path, data, version, (int rc, String p, Object ctx, Stat stat) -> {
            KeeperException.Code code = KeeperException.Code.get(rc);
            switch (code) {
            case OK:
                promise.done(stat);
                break;
            default:
                promise.fail(KeeperException.create(code, p));
            }
        }, null);
        return promise;
    });
}

From source file:com.linkedin.parseq.zk.client.ZKClientImpl.java

License:Apache License

/**
 * {@inheritDoc}/*from   w  ww  .  j a  v a  2  s .  c  o m*/
 */
@Override
public WatchableTask<List<String>> getChildren(String path) {
    return new WatchableTask<List<String>>("zkGetChildren: " + path) {
        @Override
        protected Promise run(Context context) throws Throwable {
            SettablePromise<List<String>> promise = Promises.settable();
            _zkClient.getChildren(path, _watcher, (int rc, String p, Object ctx, List<String> children) -> {
                KeeperException.Code code = KeeperException.Code.get(rc);
                switch (code) {
                case OK:
                    promise.done(children);
                    break;
                default:
                    promise.fail(KeeperException.create(code, p));
                }
            }, null);
            return promise;
        }
    };
}