Search in sources :

Example 11 with ReplyHeader

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

the class ZooKeeper method setData.

/**
     * 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). Return the stat of the node.
     * <p>
     * This operation, if successful, will trigger all the watches on the node
     * of the given path left by getData calls.
     * <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.
     * <p>
     * The maximum allowable size of the data array is 1 MB (1,048,576 bytes).
     * Arrays larger than this will cause a KeeperExecption to be thrown.
     *
     * @param path
     *            the path of the node
     * @param data
     *            the data to set
     * @param version
     *            the expected matching version
     * @return the state 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 IllegalArgumentException
     *             if an invalid path is specified
     */
public Stat setData(final String path, byte[] data, int version) throws KeeperException, InterruptedException {
    verbotenThreadCheck();
    final String clientPath = path;
    PathUtils.validatePath(clientPath);
    final String serverPath = prependChroot(clientPath);
    RequestHeader h = new RequestHeader();
    h.setType(ZooDefs.OpCode.setData);
    SetDataRequest request = new SetDataRequest();
    request.setPath(serverPath);
    request.setData(data);
    request.setVersion(version);
    SetDataResponse response = new SetDataResponse();
    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_voltpatches.proto.ReplyHeader) RequestHeader(org.apache.zookeeper_voltpatches.proto.RequestHeader) SetDataRequest(org.apache.zookeeper_voltpatches.proto.SetDataRequest) SetDataResponse(org.apache.zookeeper_voltpatches.proto.SetDataResponse)

Example 12 with ReplyHeader

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

the class ZooKeeper method exists.

/**
     * Return the stat of the node of the given path. Return null if no such a
     * node exists.
     * <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
     * will be triggered by a successful operation that creates/delete the node
     * or sets the data on the node.
     *
     * @param path
     *            the node path
     * @param watcher
     *            explicit watcher
     * @return the stat of the node of the given path; return null if no such a
     *         node exists.
     * @throws KeeperException
     *             If the server signals an error
     * @throws InterruptedException
     *             If the server transaction is interrupted.
     * @throws IllegalArgumentException
     *             if an invalid path is specified
     */
public Stat exists(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 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();
    ReplyHeader r = cnxn.submitRequest(h, request, response, wcb);
    if (r.getErr() != 0) {
        if (r.getErr() == KeeperException.Code.NONODE.intValue()) {
            return null;
        }
        throw KeeperException.create(KeeperException.Code.get(r.getErr()), clientPath);
    }
    return response.getStat().getCzxid() == -1 ? null : response.getStat();
}
Also used : ExistsRequest(org.apache.zookeeper_voltpatches.proto.ExistsRequest) ReplyHeader(org.apache.zookeeper_voltpatches.proto.ReplyHeader) RequestHeader(org.apache.zookeeper_voltpatches.proto.RequestHeader) SetDataResponse(org.apache.zookeeper_voltpatches.proto.SetDataResponse)

Example 13 with ReplyHeader

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

the class ZooKeeper method delete.

/**
     * The Asynchronous version of delete. The request doesn't actually until
     * the asynchronous callback is called.
     *
     * @see #delete(String, int)
     */
public void delete(final String path, int version, VoidCallback cb, Object ctx) {
    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);
    cnxn.queuePacket(h, new ReplyHeader(), request, null, cb, clientPath, serverPath, ctx, null);
}
Also used : ReplyHeader(org.apache.zookeeper_voltpatches.proto.ReplyHeader) RequestHeader(org.apache.zookeeper_voltpatches.proto.RequestHeader) DeleteRequest(org.apache.zookeeper_voltpatches.proto.DeleteRequest)

Example 14 with ReplyHeader

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

the class ZooKeeper method getData.

/**
     * Return the data and the stat 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
     * will be triggered by a successful operation that sets data on the node,
     * or deletes the node.
     * <p>
     * A KeeperException with error code KeeperException.NoNode will be thrown
     * if no node with the given path exists.
     *
     * @param path
     *            the given path
     * @param watcher
     *            explicit watcher
     * @param stat
     *            the stat of the node
     * @return the data of the node
     * @throws KeeperException
     *             If the server signals an error with a non-zero error code
     * @throws InterruptedException
     *             If the server transaction is interrupted.
     * @throws IllegalArgumentException
     *             if an invalid path is specified
     */
public byte[] getData(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 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();
    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.getData();
}
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 15 with ReplyHeader

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

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_voltpatches.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 {
    verbotenThreadCheck();
    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();
    }
    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_voltpatches.proto.ReplyHeader) SetACLRequest(org.apache.zookeeper_voltpatches.proto.SetACLRequest) RequestHeader(org.apache.zookeeper_voltpatches.proto.RequestHeader) SetACLResponse(org.apache.zookeeper_voltpatches.proto.SetACLResponse)

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