Example usage for org.apache.zookeeper KeeperException create

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

Introduction

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

Prototype

@Deprecated
public static KeeperException create(int code, String path) 

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./*from ww  w. j a  v a2  s  .  c  om*/
 * @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./*  ww w .jav  a  2s . c o  m*/
 * @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   www . j  av  a 2s .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.//  ww  w. j  av a2  s  .  c o  m
 * @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.//from ww  w  . ja v a2s  . 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./*from w  w  w. j av a2s. c om*/
 * @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}// ww w .ja v  a  2 s  .co  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}/*from   w w  w . j a va  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 om*/
 */
@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 ww w  .  j  a v  a  2  s . com*/
 */
@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;
        }
    };
}