Search in sources :

Example 26 with ReplyHeader

use of org.apache.zookeeper.proto.ReplyHeader 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 27 with ReplyHeader

use of org.apache.zookeeper.proto.ReplyHeader 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 28 with ReplyHeader

use of org.apache.zookeeper.proto.ReplyHeader 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)

Example 29 with ReplyHeader

use of org.apache.zookeeper.proto.ReplyHeader 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);
    final String serverPath = prependChroot(clientPath);
    RequestHeader h = new RequestHeader();
    setCreateHeader(createMode, h);
    Create2Response response = new Create2Response();
    if (acl != null && acl.size() == 0) {
        throw new KeeperException.InvalidACLException();
    }
    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 30 with ReplyHeader

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

the class ZooKeeper method getConfig.

/**
     * The asynchronous version of getConfig.
     *
     * @see #getConfig(Watcher, Stat)
     */
public void getConfig(Watcher watcher, DataCallback cb, Object ctx) {
    final String configZnode = ZooDefs.CONFIG_NODE;
    // the watch contains the un-chroot path
    WatchRegistration wcb = null;
    if (watcher != null) {
        wcb = new DataWatchRegistration(watcher, configZnode);
    }
    RequestHeader h = new RequestHeader();
    h.setType(ZooDefs.OpCode.getData);
    GetDataRequest request = new GetDataRequest();
    request.setPath(configZnode);
    request.setWatch(watcher != null);
    GetDataResponse response = new GetDataResponse();
    cnxn.queuePacket(h, new ReplyHeader(), request, response, cb, configZnode, configZnode, ctx, wcb);
}
Also used : ReplyHeader(org.apache.zookeeper.proto.ReplyHeader) RequestHeader(org.apache.zookeeper.proto.RequestHeader) GetDataResponse(org.apache.zookeeper.proto.GetDataResponse) GetDataRequest(org.apache.zookeeper.proto.GetDataRequest)

Aggregations

ReplyHeader (org.apache.zookeeper.proto.ReplyHeader)39 RequestHeader (org.apache.zookeeper.proto.RequestHeader)33 GetDataResponse (org.apache.zookeeper.proto.GetDataResponse)7 Record (org.apache.jute.Record)6 GetDataRequest (org.apache.zookeeper.proto.GetDataRequest)5 SetDataResponse (org.apache.zookeeper.proto.SetDataResponse)5 IOException (java.io.IOException)4 ExistsRequest (org.apache.zookeeper.proto.ExistsRequest)4 AuthPacket (org.apache.zookeeper.proto.AuthPacket)3 Create2Response (org.apache.zookeeper.proto.Create2Response)3 CreateResponse (org.apache.zookeeper.proto.CreateResponse)3 GetACLRequest (org.apache.zookeeper.proto.GetACLRequest)3 GetACLResponse (org.apache.zookeeper.proto.GetACLResponse)3 GetChildren2Request (org.apache.zookeeper.proto.GetChildren2Request)3 GetChildren2Response (org.apache.zookeeper.proto.GetChildren2Response)3 GetChildrenRequest (org.apache.zookeeper.proto.GetChildrenRequest)3 GetChildrenResponse (org.apache.zookeeper.proto.GetChildrenResponse)3 SetACLResponse (org.apache.zookeeper.proto.SetACLResponse)3 KeeperException (org.apache.zookeeper.KeeperException)2 Code (org.apache.zookeeper.KeeperException.Code)2