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);
}
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();
}
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);
}
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());
}
}
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);
}
Aggregations