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);
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.RequestHeader 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);
}
use of org.apache.zookeeper.proto.RequestHeader in project zookeeper by apache.
the class ZooKeeper method setData.
/**
* The asynchronous version of setData.
*
* @see #setData(String, byte[], int)
*/
public void setData(final String path, byte[] data, 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.setData);
SetDataRequest request = new SetDataRequest();
request.setPath(serverPath);
request.setData(data);
request.setVersion(version);
SetDataResponse response = new SetDataResponse();
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 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 create.
/**
* The asynchronous version of create.
*
* @see #create(String, byte[], List, CreateMode)
*/
public void create(final String path, byte[] data, List<ACL> acl, CreateMode createMode, StringCallback cb, Object ctx) {
final String clientPath = path;
PathUtils.validatePath(clientPath, createMode.isSequential());
EphemeralType.validateTTL(createMode, -1);
final String serverPath = prependChroot(clientPath);
RequestHeader h = new RequestHeader();
h.setType(createMode.isContainer() ? ZooDefs.OpCode.createContainer : ZooDefs.OpCode.create);
CreateRequest request = new CreateRequest();
CreateResponse response = new CreateResponse();
ReplyHeader r = new ReplyHeader();
request.setData(data);
request.setFlags(createMode.toFlag());
request.setPath(serverPath);
request.setAcl(acl);
cnxn.queuePacket(h, r, request, response, cb, clientPath, serverPath, ctx, null);
}
Aggregations