if (LOG.isDebugEnabled()) {
LOG.debug(request);
}
switch (request.type) {
case OpCode.ping:
request.cnxn.sendResponse(new ReplyHeader(-2,
zks.dataTree.lastProcessedZxid, 0), null, "response");
return;
case OpCode.createSession:
request.cnxn.finishSessionInit(true);
return;
case OpCode.create:
rsp = new CreateResponse(rc.path);
err = Code.get(rc.err);
break;
case OpCode.delete:
err = Code.get(rc.err);
break;
case OpCode.setData:
rsp = new SetDataResponse(rc.stat);
err = Code.get(rc.err);
break;
case OpCode.setACL:
rsp = new SetACLResponse(rc.stat);
err = Code.get(rc.err);
break;
case OpCode.closeSession:
err = Code.get(rc.err);
break;
case OpCode.sync:
SyncRequest syncRequest = new SyncRequest();
ZooKeeperServer.byteBuffer2Record(request.request,
syncRequest);
rsp = new SyncResponse(syncRequest.getPath());
break;
case OpCode.exists:
// TODO we need to figure out the security requirement for this!
ExistsRequest existsRequest = new ExistsRequest();
ZooKeeperServer.byteBuffer2Record(request.request,
existsRequest);
String path = existsRequest.getPath();
if (path.indexOf('\0') != -1) {
throw new KeeperException.BadArgumentsException();
}
Stat stat = zks.dataTree.statNode(path, existsRequest
.getWatch() ? request.cnxn : null);
rsp = new ExistsResponse(stat);
break;
case OpCode.getData:
GetDataRequest getDataRequest = new GetDataRequest();
ZooKeeperServer.byteBuffer2Record(request.request,
getDataRequest);
DataNode n = zks.dataTree.getNode(getDataRequest.getPath());
if (n == null) {
throw new KeeperException.NoNodeException();
}
PrepRequestProcessor.checkACL(zks, zks.dataTree.convertLong(n.acl),
ZooDefs.Perms.READ,
request.authInfo);
stat = new Stat();
byte b[] = zks.dataTree.getData(getDataRequest.getPath(), stat,
getDataRequest.getWatch() ? request.cnxn : null);
rsp = new GetDataResponse(b, stat);
break;
case OpCode.setWatches:
SetWatches setWatches = new SetWatches();
// XXX We really should NOT need this!!!!
request.request.rewind();
ZooKeeperServer.byteBuffer2Record(request.request, setWatches);
long relativeZxid = setWatches.getRelativeZxid();
zks.dataTree.setWatches(relativeZxid,
setWatches.getDataWatches(),
setWatches.getExistWatches(),
setWatches.getChildWatches(), request.cnxn);
break;
case OpCode.getACL:
GetACLRequest getACLRequest = new GetACLRequest();
ZooKeeperServer.byteBuffer2Record(request.request,
getACLRequest);
stat = new Stat();
List<ACL> acl =
zks.dataTree.getACL(getACLRequest.getPath(), stat);
rsp = new GetACLResponse(acl, stat);
break;
case OpCode.getChildren:
GetChildrenRequest getChildrenRequest = new GetChildrenRequest();
ZooKeeperServer.byteBuffer2Record(request.request,
getChildrenRequest);
stat = new Stat();
n = zks.dataTree.getNode(getChildrenRequest.getPath());
if (n == null) {
throw new KeeperException.NoNodeException();
}
PrepRequestProcessor.checkACL(zks, zks.dataTree.convertLong(n.acl),
ZooDefs.Perms.READ,
request.authInfo);
List<String> children = zks.dataTree.getChildren(
getChildrenRequest.getPath(), stat, getChildrenRequest
.getWatch() ? request.cnxn : null);
rsp = new GetChildrenResponse(children);
break;
}
} catch (KeeperException e) {
err = e.code();
} catch (Exception e) {
// log at error level as we are returning a marshalling
// error to the user
LOG.error("Failed to process " + request, e);
StringBuffer sb = new StringBuffer();
ByteBuffer bb = request.request;
bb.rewind();
while (bb.hasRemaining()) {
sb.append(Integer.toHexString(bb.get() & 0xff));
}
LOG.error("Dumping request buffer: 0x" + sb.toString());
err = Code.MARSHALLINGERROR;
}
ReplyHeader hdr =
new ReplyHeader(request.cxid, request.zxid, err.intValue());
zks.serverStats().updateLatency(request.createTime);
try {
request.cnxn.sendResponse(hdr, rsp, "response");
} catch (IOException e) {
LOG.error("FIXMSG",e);