Search in sources :

Example 21 with RequestHeader

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

the class ClientTest method testNonExistingOpCode.

/**
     * We create a perfectly valid 'exists' request, except that the opcode is wrong.
     * @return
     * @throws Exception
     */
@Test
public void testNonExistingOpCode() throws Exception {
    TestableZooKeeper zk = createClient();
    final String path = "/m1";
    RequestHeader h = new RequestHeader();
    // This code does not exists
    h.setType(888);
    ExistsRequest request = new ExistsRequest();
    request.setPath(path);
    request.setWatch(false);
    ExistsResponse response = new ExistsResponse();
    ReplyHeader r = zk.submitRequest(h, request, response, null);
    Assert.assertEquals(r.getErr(), Code.UNIMPLEMENTED.intValue());
    zk.testableWaitForShutdown(CONNECTION_TIMEOUT);
}
Also used : ExistsRequest(org.apache.zookeeper.proto.ExistsRequest) ReplyHeader(org.apache.zookeeper.proto.ReplyHeader) TestableZooKeeper(org.apache.zookeeper.TestableZooKeeper) RequestHeader(org.apache.zookeeper.proto.RequestHeader) ExistsResponse(org.apache.zookeeper.proto.ExistsResponse) Test(org.junit.Test)

Example 22 with RequestHeader

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

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

Example 23 with RequestHeader

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

the class ZooKeeper method getChildren.

/**
     * The asynchronous version of getChildren.
     *
     * @see #getChildren(String, Watcher)
     */
public void getChildren(final String path, Watcher watcher, ChildrenCallback 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.getChildren);
    GetChildrenRequest request = new GetChildrenRequest();
    request.setPath(serverPath);
    request.setWatch(watcher != null);
    GetChildrenResponse response = new GetChildrenResponse();
    cnxn.queuePacket(h, new ReplyHeader(), request, response, cb, clientPath, serverPath, ctx, wcb);
}
Also used : GetChildrenRequest(org.apache.zookeeper.proto.GetChildrenRequest) ReplyHeader(org.apache.zookeeper.proto.ReplyHeader) GetChildrenResponse(org.apache.zookeeper.proto.GetChildrenResponse) RequestHeader(org.apache.zookeeper.proto.RequestHeader)

Example 24 with RequestHeader

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

the class ZooKeeperAdmin method reconfigure.

/**
     * Reconfigure - add/remove servers. Return the new configuration.
     * @param joiningServers
     *                a comma separated list of servers being added (incremental reconfiguration)
     * @param leavingServers
     *                a comma separated list of servers being removed (incremental reconfiguration)
     * @param newMembers
     *                a comma separated list of new membership (non-incremental reconfiguration)
     * @param fromConfig
     *                version of the current configuration
     *                (optional - causes reconfiguration to throw an exception if configuration is no longer current)
     * @param stat the stat of /zookeeper/config znode will be copied to this
     *             parameter if not null.
     * @return new configuration
     * @throws InterruptedException If the server transaction is interrupted.
     * @throws KeeperException If the server signals an error with a non-zero error code.
     */
public byte[] reconfigure(String joiningServers, String leavingServers, String newMembers, long fromConfig, Stat stat) throws KeeperException, InterruptedException {
    RequestHeader h = new RequestHeader();
    h.setType(ZooDefs.OpCode.reconfig);
    ReconfigRequest request = new ReconfigRequest(joiningServers, leavingServers, newMembers, fromConfig);
    GetDataResponse response = new GetDataResponse();
    ReplyHeader r = cnxn.submitRequest(h, request, response, null);
    if (r.getErr() != 0) {
        throw KeeperException.create(KeeperException.Code.get(r.getErr()), "");
    }
    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) ReconfigRequest(org.apache.zookeeper.proto.ReconfigRequest)

Example 25 with RequestHeader

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

the class ZooKeeper method setACL.

/**
     * The asynchronous version of setACL.
     *
     * @see #setACL(String, List, int)
     */
public void setACL(final String path, List<ACL> acl, int version, StatCallback cb, Object ctx) {
    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);
    request.setAcl(acl);
    request.setVersion(version);
    SetACLResponse response = new SetACLResponse();
    cnxn.queuePacket(h, new ReplyHeader(), request, response, cb, clientPath, serverPath, ctx, null);
}
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)

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