use of org.apache.zookeeper_voltpatches.proto.RequestHeader in project voltdb by VoltDB.
the class RequestHeader method compareTo.
public int compareTo(Object peer_) throws ClassCastException {
if (!(peer_ instanceof RequestHeader)) {
throw new ClassCastException("Comparing different types of records.");
}
RequestHeader peer = (RequestHeader) peer_;
int ret = 0;
ret = (xid == peer.xid) ? 0 : ((xid < peer.xid) ? -1 : 1);
if (ret != 0)
return ret;
ret = (type == peer.type) ? 0 : ((type < peer.type) ? -1 : 1);
if (ret != 0)
return ret;
return ret;
}
use of org.apache.zookeeper_voltpatches.proto.RequestHeader in project voltdb by VoltDB.
the class ZooKeeper method delete.
/**
* The Asynchronous version of delete. The request doesn't actually until
* the asynchronous callback is called.
*
* @see #delete(String, int)
*/
public void delete(final String path, int version, VoidCallback cb, Object ctx) {
verbotenThreadCheck();
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_voltpatches.proto.RequestHeader in project voltdb by VoltDB.
the class ZooKeeper method getData.
/**
* Return the data and the stat of the node of the given path.
* <p>
* If the watch is non-null and the call is successful (no exception is
* thrown), a watch will be left on the node with the given path. The watch
* will be triggered by a successful operation that sets data on the node,
* or deletes the node.
* <p>
* A KeeperException with error code KeeperException.NoNode will be thrown
* if no node with the given path exists.
*
* @param path
* the given path
* @param watcher
* explicit watcher
* @param stat
* the stat of the node
* @return the data of the node
* @throws KeeperException
* If the server signals an error with a non-zero error code
* @throws InterruptedException
* If the server transaction is interrupted.
* @throws IllegalArgumentException
* if an invalid path is specified
*/
public byte[] getData(final String path, Watcher watcher, Stat stat) throws KeeperException, InterruptedException {
verbotenThreadCheck();
final String clientPath = path;
PathUtils.validatePath(clientPath);
// the watch contains the un-chroot path
WatchRegistration wcb = null;
if (watcher != null) {
wcb = new DataWatchRegistration(watcher, clientPath);
}
final String serverPath = prependChroot(clientPath);
RequestHeader h = new RequestHeader();
h.setType(ZooDefs.OpCode.getData);
GetDataRequest request = new GetDataRequest();
request.setPath(serverPath);
request.setWatch(watcher != null);
GetDataResponse response = new GetDataResponse();
ReplyHeader r = cnxn.submitRequest(h, request, response, wcb);
if (r.getErr() != 0) {
throw KeeperException.create(KeeperException.Code.get(r.getErr()), clientPath);
}
if (stat != null) {
DataTree.copyStat(response.getStat(), stat);
}
return response.getData();
}
use of org.apache.zookeeper_voltpatches.proto.RequestHeader in project voltdb by VoltDB.
the class ZooKeeper method setACL.
/**
* Set the ACL for the node of the given path if such a node exists and the
* given version matches the version of the node. Return the stat of the
* node.
* <p>
* A KeeperException with error code KeeperException.NoNode will be thrown
* if no node with the given path exists.
* <p>
* A KeeperException with error code KeeperException.BadVersion will be
* thrown if the given version does not match the node's version.
*
* @param path
* @param acl
* @param version
* @return the stat of the node.
* @throws InterruptedException
* If the server transaction is interrupted.
* @throws KeeperException
* If the server signals an error with a non-zero error code.
* @throws org.apache.zookeeper_voltpatches.KeeperException.InvalidACLException
* If the acl is invalide.
* @throws IllegalArgumentException
* if an invalid path is specified
*/
public Stat setACL(final String path, List<ACL> acl, int version) throws KeeperException, InterruptedException {
verbotenThreadCheck();
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);
if (acl != null && acl.size() == 0) {
throw new KeeperException.InvalidACLException();
}
request.setAcl(acl);
request.setVersion(version);
SetACLResponse response = new SetACLResponse();
ReplyHeader r = cnxn.submitRequest(h, request, response, null);
if (r.getErr() != 0) {
throw KeeperException.create(KeeperException.Code.get(r.getErr()), clientPath);
}
return response.getStat();
}
use of org.apache.zookeeper_voltpatches.proto.RequestHeader in project voltdb by VoltDB.
the class ClientCnxn method close.
/**
* Close the connection, which includes; send session disconnect to the
* server, shutdown the send/event threads.
*
* @throws IOException
*/
public void close() throws IOException {
if (LOG.isDebugEnabled()) {
LOG.debug("Closing client for session: 0x" + Long.toHexString(getSessionId()));
}
try {
RequestHeader h = new RequestHeader();
h.setType(ZooDefs.OpCode.closeSession);
submitRequest(h, null, null, null);
} catch (InterruptedException e) {
// ignore, close the send/event threads
} finally {
disconnect();
}
}
Aggregations