Search in sources :

Example 11 with RequestHeader

use of org.apache.zookeeper.proto.RequestHeader in project zookeeper by apache.

the class ZooKeeper method exists.

/**
     * The asynchronous version of exists.
     *
     * @see #exists(String, Watcher)
     */
public void exists(final String path, Watcher watcher, StatCallback cb, Object ctx) {
    final String clientPath = path;
    PathUtils.validatePath(clientPath);
    // the watch contains the un-chroot path
    WatchRegistration wcb = null;
    if (watcher != null) {
        wcb = new ExistsWatchRegistration(watcher, clientPath);
    }
    final String serverPath = prependChroot(clientPath);
    RequestHeader h = new RequestHeader();
    h.setType(ZooDefs.OpCode.exists);
    ExistsRequest request = new ExistsRequest();
    request.setPath(serverPath);
    request.setWatch(watcher != null);
    SetDataResponse response = new SetDataResponse();
    cnxn.queuePacket(h, new ReplyHeader(), request, response, cb, clientPath, serverPath, ctx, wcb);
}
Also used : ExistsRequest(org.apache.zookeeper.proto.ExistsRequest) ReplyHeader(org.apache.zookeeper.proto.ReplyHeader) RequestHeader(org.apache.zookeeper.proto.RequestHeader) SetDataResponse(org.apache.zookeeper.proto.SetDataResponse)

Example 12 with RequestHeader

use of org.apache.zookeeper.proto.RequestHeader in project zookeeper by apache.

the class ClientCnxn method addAuthInfo.

public void addAuthInfo(String scheme, byte[] auth) {
    if (!state.isAlive()) {
        return;
    }
    authInfo.add(new AuthData(scheme, auth));
    queuePacket(new RequestHeader(-4, OpCode.auth), null, new AuthPacket(0, scheme, auth), null, null, null, null, null, null);
}
Also used : AuthPacket(org.apache.zookeeper.proto.AuthPacket) RequestHeader(org.apache.zookeeper.proto.RequestHeader)

Example 13 with RequestHeader

use of org.apache.zookeeper.proto.RequestHeader in project zookeeper by apache.

the class ZooKeeper method setACL.

/**
     * Set the ACL for the node of the given path if such a node exists and the
     * given version matches the version of the node. Return the stat of the
     * node.
     * <p>
     * A KeeperException with error code KeeperException.NoNode will be thrown
     * if no node with the given path exists.
     * <p>
     * A KeeperException with error code KeeperException.BadVersion will be
     * thrown if the given version does not match the node's version.
     *
     * @param path
     * @param acl
     * @param version
     * @return the stat of the node.
     * @throws InterruptedException If the server transaction is interrupted.
     * @throws KeeperException If the server signals an error with a non-zero error code.
     * @throws org.apache.zookeeper.KeeperException.InvalidACLException If the acl is invalide.
     * @throws IllegalArgumentException if an invalid path is specified
     */
public Stat setACL(final String path, List<ACL> acl, int version) throws KeeperException, InterruptedException {
    final String clientPath = path;
    PathUtils.validatePath(clientPath);
    final String serverPath = prependChroot(clientPath);
    RequestHeader h = new RequestHeader();
    h.setType(ZooDefs.OpCode.setACL);
    SetACLRequest request = new SetACLRequest();
    request.setPath(serverPath);
    if (acl != null && acl.size() == 0) {
        throw new KeeperException.InvalidACLException(clientPath);
    }
    request.setAcl(acl);
    request.setVersion(version);
    SetACLResponse response = new SetACLResponse();
    ReplyHeader r = cnxn.submitRequest(h, request, response, null);
    if (r.getErr() != 0) {
        throw KeeperException.create(KeeperException.Code.get(r.getErr()), clientPath);
    }
    return response.getStat();
}
Also used : ReplyHeader(org.apache.zookeeper.proto.ReplyHeader) SetACLRequest(org.apache.zookeeper.proto.SetACLRequest) RequestHeader(org.apache.zookeeper.proto.RequestHeader) SetACLResponse(org.apache.zookeeper.proto.SetACLResponse)

Example 14 with RequestHeader

use of org.apache.zookeeper.proto.RequestHeader in project zookeeper by apache.

the class ZooKeeper method getChildren.

/**
     * The asynchronous version of getChildren.
     *
     * @since 3.3.0
     * 
     * @see #getChildren(String, Watcher, Stat)
     */
public void getChildren(final String path, Watcher watcher, Children2Callback cb, Object ctx) {
    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();
    cnxn.queuePacket(h, new ReplyHeader(), request, response, cb, clientPath, serverPath, ctx, wcb);
}
Also used : GetChildren2Response(org.apache.zookeeper.proto.GetChildren2Response) ReplyHeader(org.apache.zookeeper.proto.ReplyHeader) GetChildren2Request(org.apache.zookeeper.proto.GetChildren2Request) RequestHeader(org.apache.zookeeper.proto.RequestHeader)

Example 15 with RequestHeader

use of org.apache.zookeeper.proto.RequestHeader in project zookeeper by apache.

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 {
    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.proto.ReplyHeader) RequestHeader(org.apache.zookeeper.proto.RequestHeader) DeleteRequest(org.apache.zookeeper.proto.DeleteRequest)

Aggregations

RequestHeader (org.apache.zookeeper.proto.RequestHeader)36 ReplyHeader (org.apache.zookeeper.proto.ReplyHeader)33 GetDataResponse (org.apache.zookeeper.proto.GetDataResponse)6 Record (org.apache.jute.Record)5 GetDataRequest (org.apache.zookeeper.proto.GetDataRequest)4 SetDataResponse (org.apache.zookeeper.proto.SetDataResponse)4 AuthPacket (org.apache.zookeeper.proto.AuthPacket)3 CreateRequest (org.apache.zookeeper.proto.CreateRequest)3 ExistsRequest (org.apache.zookeeper.proto.ExistsRequest)3 InputStream (java.io.InputStream)2 ConnectRequest (org.apache.zookeeper.proto.ConnectRequest)2 Create2Response (org.apache.zookeeper.proto.Create2Response)2 CreateResponse (org.apache.zookeeper.proto.CreateResponse)2 DeleteRequest (org.apache.zookeeper.proto.DeleteRequest)2 GetACLRequest (org.apache.zookeeper.proto.GetACLRequest)2 GetACLResponse (org.apache.zookeeper.proto.GetACLResponse)2 GetChildren2Request (org.apache.zookeeper.proto.GetChildren2Request)2 GetChildren2Response (org.apache.zookeeper.proto.GetChildren2Response)2 GetChildrenRequest (org.apache.zookeeper.proto.GetChildrenRequest)2 GetChildrenResponse (org.apache.zookeeper.proto.GetChildrenResponse)2