Search in sources :

Example 11 with ReplyHeader

use of org.apache.zookeeper.proto.ReplyHeader 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 ReplyHeader

use of org.apache.zookeeper.proto.ReplyHeader 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 13 with ReplyHeader

use of org.apache.zookeeper.proto.ReplyHeader 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 14 with ReplyHeader

use of org.apache.zookeeper.proto.ReplyHeader 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)

Example 15 with ReplyHeader

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

the class ZooKeeper method getConfig.

/**
     * Return the last committed configuration (as known to the server to which the client is connected)
     * and the stat of the configuration.
     * <p>
     * If the watch is non-null and the call is successful (no exception is
     * thrown), a watch will be left on the configuration node (ZooDefs.CONFIG_NODE). The watch
     * will be triggered by a successful reconfig operation
     * <p>
     * A KeeperException with error code KeeperException.NoNode will be thrown
     * if the configuration node doesn't exists.
     *
     * @param watcher explicit watcher
     * @param stat the stat of the configuration node ZooDefs.CONFIG_NODE
     * @return configuration data stored in ZooDefs.CONFIG_NODE
     * @throws KeeperException If the server signals an error with a non-zero error code
     * @throws InterruptedException If the server transaction is interrupted.
     */
public byte[] getConfig(Watcher watcher, Stat stat) throws KeeperException, InterruptedException {
    final String configZnode = ZooDefs.CONFIG_NODE;
    // the watch contains the un-chroot path
    WatchRegistration wcb = null;
    if (watcher != null) {
        wcb = new DataWatchRegistration(watcher, configZnode);
    }
    RequestHeader h = new RequestHeader();
    h.setType(ZooDefs.OpCode.getData);
    GetDataRequest request = new GetDataRequest();
    request.setPath(configZnode);
    request.setWatch(watcher != null);
    GetDataResponse response = new GetDataResponse();
    ReplyHeader r = cnxn.submitRequest(h, request, response, wcb);
    if (r.getErr() != 0) {
        throw KeeperException.create(KeeperException.Code.get(r.getErr()), configZnode);
    }
    if (stat != null) {
        DataTree.copyStat(response.getStat(), stat);
    }
    return response.getData();
}
Also used : ReplyHeader(org.apache.zookeeper.proto.ReplyHeader) RequestHeader(org.apache.zookeeper.proto.RequestHeader) GetDataResponse(org.apache.zookeeper.proto.GetDataResponse) GetDataRequest(org.apache.zookeeper.proto.GetDataRequest)

Aggregations

ReplyHeader (org.apache.zookeeper.proto.ReplyHeader)39 RequestHeader (org.apache.zookeeper.proto.RequestHeader)33 GetDataResponse (org.apache.zookeeper.proto.GetDataResponse)7 Record (org.apache.jute.Record)6 GetDataRequest (org.apache.zookeeper.proto.GetDataRequest)5 SetDataResponse (org.apache.zookeeper.proto.SetDataResponse)5 IOException (java.io.IOException)4 ExistsRequest (org.apache.zookeeper.proto.ExistsRequest)4 AuthPacket (org.apache.zookeeper.proto.AuthPacket)3 Create2Response (org.apache.zookeeper.proto.Create2Response)3 CreateResponse (org.apache.zookeeper.proto.CreateResponse)3 GetACLRequest (org.apache.zookeeper.proto.GetACLRequest)3 GetACLResponse (org.apache.zookeeper.proto.GetACLResponse)3 GetChildren2Request (org.apache.zookeeper.proto.GetChildren2Request)3 GetChildren2Response (org.apache.zookeeper.proto.GetChildren2Response)3 GetChildrenRequest (org.apache.zookeeper.proto.GetChildrenRequest)3 GetChildrenResponse (org.apache.zookeeper.proto.GetChildrenResponse)3 SetACLResponse (org.apache.zookeeper.proto.SetACLResponse)3 KeeperException (org.apache.zookeeper.KeeperException)2 Code (org.apache.zookeeper.KeeperException.Code)2