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