Search in sources :

Example 31 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 32 with RequestHeader

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

the class ZooKeeper method create.

/**
 * same as {@link #create(String, byte[], List, CreateMode, Stat)} but
 * allows for specifying a TTL when mode is {@link CreateMode#PERSISTENT_WITH_TTL}
 * or {@link CreateMode#PERSISTENT_SEQUENTIAL_WITH_TTL}. If the znode has not been modified
 * within the given TTL, it will be deleted once it has no children. The TTL unit is
 * milliseconds and must be greater than 0 and less than or equal to
 * {@link EphemeralType#MAX_TTL}.
 */
public String create(final String path, byte[] data, List<ACL> acl, CreateMode createMode, Stat stat, long ttl) throws KeeperException, InterruptedException {
    final String clientPath = path;
    PathUtils.validatePath(clientPath, createMode.isSequential());
    EphemeralType.validateTTL(createMode, ttl);
    validateACL(acl);
    final String serverPath = prependChroot(clientPath);
    RequestHeader h = new RequestHeader();
    setCreateHeader(createMode, h);
    Create2Response response = new Create2Response();
    Record record = makeCreateRecord(createMode, serverPath, data, acl, ttl);
    ReplyHeader r = cnxn.submitRequest(h, record, response, null);
    if (r.getErr() != 0) {
        throw KeeperException.create(KeeperException.Code.get(r.getErr()), clientPath);
    }
    if (stat != null) {
        DataTree.copyStat(response.getStat(), stat);
    }
    if (cnxn.chrootPath == null) {
        return response.getPath();
    } else {
        return response.getPath().substring(cnxn.chrootPath.length());
    }
}
Also used : ReplyHeader(org.apache.zookeeper.proto.ReplyHeader) RequestHeader(org.apache.zookeeper.proto.RequestHeader) Record(org.apache.jute.Record) Create2Response(org.apache.zookeeper.proto.Create2Response)

Example 33 with RequestHeader

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

the class ZooKeeper method delete.

/**
 * The asynchronous version of delete.
 *
 * @see #delete(String, int)
 */
public void delete(final String path, int version, VoidCallback cb, Object ctx) {
    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.proto.ReplyHeader) RequestHeader(org.apache.zookeeper.proto.RequestHeader) DeleteRequest(org.apache.zookeeper.proto.DeleteRequest)

Example 34 with RequestHeader

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

the class ZooKeeper method getACL.

/**
 * The asynchronous version of getACL.
 *
 * @see #getACL(String, Stat)
 */
public void getACL(final String path, Stat stat, ACLCallback cb, Object ctx) {
    final String clientPath = path;
    PathUtils.validatePath(clientPath);
    final String serverPath = prependChroot(clientPath);
    RequestHeader h = new RequestHeader();
    h.setType(ZooDefs.OpCode.getACL);
    GetACLRequest request = new GetACLRequest();
    request.setPath(serverPath);
    GetACLResponse response = new GetACLResponse();
    cnxn.queuePacket(h, new ReplyHeader(), request, response, cb, clientPath, serverPath, ctx, null);
}
Also used : ReplyHeader(org.apache.zookeeper.proto.ReplyHeader) GetACLRequest(org.apache.zookeeper.proto.GetACLRequest) RequestHeader(org.apache.zookeeper.proto.RequestHeader) GetACLResponse(org.apache.zookeeper.proto.GetACLResponse)

Example 35 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)

Aggregations

RequestHeader (org.apache.zookeeper.proto.RequestHeader)37 ReplyHeader (org.apache.zookeeper.proto.ReplyHeader)34 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 CreateResponse (org.apache.zookeeper.proto.CreateResponse)3 ExistsRequest (org.apache.zookeeper.proto.ExistsRequest)3 Test (org.junit.Test)3 InputStream (java.io.InputStream)2 ConnectRequest (org.apache.zookeeper.proto.ConnectRequest)2 Create2Response (org.apache.zookeeper.proto.Create2Response)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