Search in sources :

Example 11 with RequestHeader

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

the class RequestHeader method compareTo.

public int compareTo(Object peer_) throws ClassCastException {
    if (!(peer_ instanceof RequestHeader)) {
        throw new ClassCastException("Comparing different types of records.");
    }
    RequestHeader peer = (RequestHeader) peer_;
    int ret = 0;
    ret = (xid == peer.xid) ? 0 : ((xid < peer.xid) ? -1 : 1);
    if (ret != 0)
        return ret;
    ret = (type == peer.type) ? 0 : ((type < peer.type) ? -1 : 1);
    if (ret != 0)
        return ret;
    return ret;
}
Also used : RequestHeader(org.apache.zookeeper_voltpatches.proto.RequestHeader)

Example 12 with RequestHeader

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

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

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

Example 15 with RequestHeader

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

the class ClientCnxn method close.

/**
     * Close the connection, which includes; send session disconnect to the
     * server, shutdown the send/event threads.
     *
     * @throws IOException
     */
public void close() throws IOException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Closing client for session: 0x" + Long.toHexString(getSessionId()));
    }
    try {
        RequestHeader h = new RequestHeader();
        h.setType(ZooDefs.OpCode.closeSession);
        submitRequest(h, null, null, null);
    } catch (InterruptedException e) {
    // ignore, close the send/event threads
    } finally {
        disconnect();
    }
}
Also used : RequestHeader(org.apache.zookeeper_voltpatches.proto.RequestHeader)

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