Search in sources :

Example 6 with ReplyHeader

use of org.apache.zookeeper_voltpatches.proto.ReplyHeader in project voltdb by VoltDB.

the class ZooKeeper method getData.

/**
     * The Asynchronous version of getData. The request doesn't actually until
     * the asynchronous callback is called.
     *
     * @see #getData(String, Watcher, Stat)
     */
public void getData(final String path, Watcher watcher, DataCallback cb, Object ctx) {
    verbotenThreadCheck();
    final String clientPath = path;
    PathUtils.validatePath(clientPath);
    // the watch contains the un-chroot path
    WatchRegistration wcb = null;
    if (watcher != null) {
        wcb = new DataWatchRegistration(watcher, clientPath);
    }
    final String serverPath = prependChroot(clientPath);
    RequestHeader h = new RequestHeader();
    h.setType(ZooDefs.OpCode.getData);
    GetDataRequest request = new GetDataRequest();
    request.setPath(serverPath);
    request.setWatch(watcher != null);
    GetDataResponse response = new GetDataResponse();
    cnxn.queuePacket(h, new ReplyHeader(), request, response, cb, clientPath, serverPath, ctx, wcb);
}
Also used : ReplyHeader(org.apache.zookeeper_voltpatches.proto.ReplyHeader) RequestHeader(org.apache.zookeeper_voltpatches.proto.RequestHeader) GetDataResponse(org.apache.zookeeper_voltpatches.proto.GetDataResponse) GetDataRequest(org.apache.zookeeper_voltpatches.proto.GetDataRequest)

Example 7 with ReplyHeader

use of org.apache.zookeeper_voltpatches.proto.ReplyHeader in project voltdb by VoltDB.

the class ZooKeeper method getChildren.

/**
     * For the given znode path return the stat and children list.
     * <p>
     * If the watch is non-null and the call is successful (no exception is
     * thrown), a watch will be left on the node with the given path. The watch
     * willbe triggered by a successful operation that deletes the node of the
     * given path or creates/delete a child under the node.
     * <p>
     * The list of children returned is not sorted and no guarantee is provided
     * as to its natural or lexical order.
     * <p>
     * A KeeperException with error code KeeperException.NoNode will be thrown
     * if no node with the given path exists.
     *
     * @since 3.3.0
     *
     * @param path
     * @param watcher
     *            explicit watcher
     * @param stat
     *            stat of the znode designated by path
     * @return an unordered array of children of the node with the given path
     * @throws InterruptedException
     *             If the server transaction is interrupted.
     * @throws KeeperException
     *             If the server signals an error with a non-zero error code.
     * @throws IllegalArgumentException
     *             if an invalid path is specified
     */
public List<String> getChildren(final String path, Watcher watcher, Stat stat) throws KeeperException, InterruptedException {
    verbotenThreadCheck();
    final String clientPath = path;
    PathUtils.validatePath(clientPath);
    // the watch contains the un-chroot path
    WatchRegistration wcb = null;
    if (watcher != null) {
        wcb = new ChildWatchRegistration(watcher, clientPath);
    }
    final String serverPath = prependChroot(clientPath);
    RequestHeader h = new RequestHeader();
    h.setType(ZooDefs.OpCode.getChildren2);
    GetChildren2Request request = new GetChildren2Request();
    request.setPath(serverPath);
    request.setWatch(watcher != null);
    GetChildren2Response response = new GetChildren2Response();
    ReplyHeader r = cnxn.submitRequest(h, request, response, wcb);
    if (r.getErr() != 0) {
        throw KeeperException.create(KeeperException.Code.get(r.getErr()), clientPath);
    }
    if (stat != null) {
        DataTree.copyStat(response.getStat(), stat);
    }
    return response.getChildren();
}
Also used : GetChildren2Response(org.apache.zookeeper_voltpatches.proto.GetChildren2Response) ReplyHeader(org.apache.zookeeper_voltpatches.proto.ReplyHeader) GetChildren2Request(org.apache.zookeeper_voltpatches.proto.GetChildren2Request) RequestHeader(org.apache.zookeeper_voltpatches.proto.RequestHeader)

Example 8 with ReplyHeader

use of org.apache.zookeeper_voltpatches.proto.ReplyHeader in project voltdb by VoltDB.

the class ZooKeeper method delete.

/**
     * Delete the node with the given path. The call will succeed if such a node
     * exists, and the given version matches the node's version (if the given
     * version is -1, it matches any node's versions).
     * <p>
     * A KeeperException with error code KeeperException.NoNode will be thrown
     * if the nodes does not exist.
     * <p>
     * A KeeperException with error code KeeperException.BadVersion will be
     * thrown if the given version does not match the node's version.
     * <p>
     * A KeeperException with error code KeeperException.NotEmpty will be thrown
     * if the node has children.
     * <p>
     * This operation, if successful, will trigger all the watches on the node
     * of the given path left by exists API calls, and the watches on the parent
     * node left by getChildren API calls.
     *
     * @param path
     *            the path of the node to be deleted.
     * @param version
     *            the expected node version.
     * @throws InterruptedException
     *             IF the server transaction is interrupted
     * @throws KeeperException
     *             If the server signals an error with a non-zero return code.
     * @throws IllegalArgumentException
     *             if an invalid path is specified
     */
public void delete(final String path, int version) throws InterruptedException, KeeperException {
    verbotenThreadCheck();
    final String clientPath = path;
    PathUtils.validatePath(clientPath);
    final String serverPath;
    // I think this makes sense even in chroot case.
    if (clientPath.equals("/")) {
        // a bit of a hack, but delete(/) will never succeed and ensures
        // that the same semantics are maintained
        serverPath = clientPath;
    } else {
        serverPath = prependChroot(clientPath);
    }
    RequestHeader h = new RequestHeader();
    h.setType(ZooDefs.OpCode.delete);
    DeleteRequest request = new DeleteRequest();
    request.setPath(serverPath);
    request.setVersion(version);
    ReplyHeader r = cnxn.submitRequest(h, request, null, null);
    if (r.getErr() != 0) {
        throw KeeperException.create(KeeperException.Code.get(r.getErr()), clientPath);
    }
}
Also used : ReplyHeader(org.apache.zookeeper_voltpatches.proto.ReplyHeader) RequestHeader(org.apache.zookeeper_voltpatches.proto.RequestHeader) DeleteRequest(org.apache.zookeeper_voltpatches.proto.DeleteRequest)

Example 9 with ReplyHeader

use of org.apache.zookeeper_voltpatches.proto.ReplyHeader in project voltdb by VoltDB.

the class ZooKeeper method getChildren.

/**
     * Return the list of the children of the node of the given path.
     * <p>
     * If the watch is non-null and the call is successful (no exception is
     * thrown), a watch will be left on the node with the given path. The watch
     * willbe triggered by a successful operation that deletes the node of the
     * given path or creates/delete a child under the node.
     * <p>
     * The list of children returned is not sorted and no guarantee is provided
     * as to its natural or lexical order.
     * <p>
     * A KeeperException with error code KeeperException.NoNode will be thrown
     * if no node with the given path exists.
     *
     * @param path
     * @param watcher
     *            explicit watcher
     * @return an unordered array of children of the node with the given path
     * @throws InterruptedException
     *             If the server transaction is interrupted.
     * @throws KeeperException
     *             If the server signals an error with a non-zero error code.
     * @throws IllegalArgumentException
     *             if an invalid path is specified
     */
public List<String> getChildren(final String path, Watcher watcher) throws KeeperException, InterruptedException {
    verbotenThreadCheck();
    final String clientPath = path;
    PathUtils.validatePath(clientPath);
    // the watch contains the un-chroot path
    WatchRegistration wcb = null;
    if (watcher != null) {
        wcb = new ChildWatchRegistration(watcher, clientPath);
    }
    final String serverPath = prependChroot(clientPath);
    RequestHeader h = new RequestHeader();
    h.setType(ZooDefs.OpCode.getChildren);
    GetChildrenRequest request = new GetChildrenRequest();
    request.setPath(serverPath);
    request.setWatch(watcher != null);
    GetChildrenResponse response = new GetChildrenResponse();
    ReplyHeader r = cnxn.submitRequest(h, request, response, wcb);
    if (r.getErr() != 0) {
        throw KeeperException.create(KeeperException.Code.get(r.getErr()), clientPath);
    }
    return response.getChildren();
}
Also used : GetChildrenRequest(org.apache.zookeeper_voltpatches.proto.GetChildrenRequest) ReplyHeader(org.apache.zookeeper_voltpatches.proto.ReplyHeader) GetChildrenResponse(org.apache.zookeeper_voltpatches.proto.GetChildrenResponse) RequestHeader(org.apache.zookeeper_voltpatches.proto.RequestHeader)

Example 10 with ReplyHeader

use of org.apache.zookeeper_voltpatches.proto.ReplyHeader in project voltdb by VoltDB.

the class ZooKeeper method sync.

/**
     * Asynchronous sync. Flushes channel between process and leader.
     *
     * @param path
     * @param cb
     *            a handler for the callback
     * @param ctx
     *            context to be provided to the callback
     * @throws IllegalArgumentException
     *             if an invalid path is specified
     */
public void sync(final String path, VoidCallback cb, Object ctx) {
    verbotenThreadCheck();
    final String clientPath = path;
    PathUtils.validatePath(clientPath);
    final String serverPath = prependChroot(clientPath);
    RequestHeader h = new RequestHeader();
    h.setType(ZooDefs.OpCode.sync);
    SyncRequest request = new SyncRequest();
    SyncResponse response = new SyncResponse();
    request.setPath(serverPath);
    cnxn.queuePacket(h, new ReplyHeader(), request, response, cb, clientPath, serverPath, ctx, null);
}
Also used : ReplyHeader(org.apache.zookeeper_voltpatches.proto.ReplyHeader) SyncRequest(org.apache.zookeeper_voltpatches.proto.SyncRequest) SyncResponse(org.apache.zookeeper_voltpatches.proto.SyncResponse) RequestHeader(org.apache.zookeeper_voltpatches.proto.RequestHeader)

Aggregations

ReplyHeader (org.apache.zookeeper_voltpatches.proto.ReplyHeader)25 RequestHeader (org.apache.zookeeper_voltpatches.proto.RequestHeader)20 SetDataResponse (org.apache.zookeeper_voltpatches.proto.SetDataResponse)5 CreateResponse (org.apache.zookeeper_voltpatches.proto.CreateResponse)3 ExistsRequest (org.apache.zookeeper_voltpatches.proto.ExistsRequest)3 GetACLRequest (org.apache.zookeeper_voltpatches.proto.GetACLRequest)3 GetACLResponse (org.apache.zookeeper_voltpatches.proto.GetACLResponse)3 GetChildren2Request (org.apache.zookeeper_voltpatches.proto.GetChildren2Request)3 GetChildren2Response (org.apache.zookeeper_voltpatches.proto.GetChildren2Response)3 GetChildrenRequest (org.apache.zookeeper_voltpatches.proto.GetChildrenRequest)3 GetChildrenResponse (org.apache.zookeeper_voltpatches.proto.GetChildrenResponse)3 GetDataRequest (org.apache.zookeeper_voltpatches.proto.GetDataRequest)3 GetDataResponse (org.apache.zookeeper_voltpatches.proto.GetDataResponse)3 SetACLResponse (org.apache.zookeeper_voltpatches.proto.SetACLResponse)3 AuthPacket (org.apache.zookeeper_voltpatches.proto.AuthPacket)2 CreateRequest (org.apache.zookeeper_voltpatches.proto.CreateRequest)2 DeleteRequest (org.apache.zookeeper_voltpatches.proto.DeleteRequest)2 SetACLRequest (org.apache.zookeeper_voltpatches.proto.SetACLRequest)2 SetDataRequest (org.apache.zookeeper_voltpatches.proto.SetDataRequest)2 SyncRequest (org.apache.zookeeper_voltpatches.proto.SyncRequest)2