Search in sources :

Example 6 with RequestHeader

use of org.apache.zookeeper_voltpatches.proto.RequestHeader 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 7 with RequestHeader

use of org.apache.zookeeper_voltpatches.proto.RequestHeader 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 8 with RequestHeader

use of org.apache.zookeeper_voltpatches.proto.RequestHeader 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)

Example 9 with RequestHeader

use of org.apache.zookeeper_voltpatches.proto.RequestHeader 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 10 with RequestHeader

use of org.apache.zookeeper_voltpatches.proto.RequestHeader 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)

Aggregations

RequestHeader (org.apache.zookeeper_voltpatches.proto.RequestHeader)24 ReplyHeader (org.apache.zookeeper_voltpatches.proto.ReplyHeader)20 SetDataResponse (org.apache.zookeeper_voltpatches.proto.SetDataResponse)4 AuthPacket (org.apache.zookeeper_voltpatches.proto.AuthPacket)2 CreateRequest (org.apache.zookeeper_voltpatches.proto.CreateRequest)2 CreateResponse (org.apache.zookeeper_voltpatches.proto.CreateResponse)2 DeleteRequest (org.apache.zookeeper_voltpatches.proto.DeleteRequest)2 ExistsRequest (org.apache.zookeeper_voltpatches.proto.ExistsRequest)2 GetACLRequest (org.apache.zookeeper_voltpatches.proto.GetACLRequest)2 GetACLResponse (org.apache.zookeeper_voltpatches.proto.GetACLResponse)2 GetChildren2Request (org.apache.zookeeper_voltpatches.proto.GetChildren2Request)2 GetChildren2Response (org.apache.zookeeper_voltpatches.proto.GetChildren2Response)2 GetChildrenRequest (org.apache.zookeeper_voltpatches.proto.GetChildrenRequest)2 GetChildrenResponse (org.apache.zookeeper_voltpatches.proto.GetChildrenResponse)2 GetDataRequest (org.apache.zookeeper_voltpatches.proto.GetDataRequest)2 GetDataResponse (org.apache.zookeeper_voltpatches.proto.GetDataResponse)2 SetACLRequest (org.apache.zookeeper_voltpatches.proto.SetACLRequest)2 SetACLResponse (org.apache.zookeeper_voltpatches.proto.SetACLResponse)2 SetDataRequest (org.apache.zookeeper_voltpatches.proto.SetDataRequest)2 InputStream (java.io.InputStream)1