* @param requestMsgId The JMS message id needed to reply.
* @throws UnknownServerException
*/
private void doProcess(AdminCommandRequest request, AgentId replyTo, String requestMsgId)
throws UnknownServerException {
AgentId targetId = null;
try {
targetId = AgentId.fromString(request.getTargetId());
} catch (Exception e) {
throw new UnknownServerException(e.getMessage());
}
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, "AdminTopic.doProcess(" + request + ',' + replyTo + ',' + requestMsgId
+ ") targetId = " + targetId);
if (targetId == null) {
if (logger.isLoggable(BasicLevel.WARN))
logger.log(BasicLevel.WARN, "Request (AdminCommandRequest) to an undefined targetId (null).");
distributeReply(replyTo, requestMsgId, new AdminReply(AdminReply.UNKNOWN_SERVER,
"Request (AdminCommandRequest) to an undefined targetId (null)."));
return;
}
if (targetId.isNullId()) {
if (checkServerId(targetId.getTo())) {
Properties replyProp = null;
try {
switch (request.getCommand()) {
case AdminCommandConstant.CMD_NO:
break;
case AdminCommandConstant.CMD_INVOKE_STATIC:
Object result = invokeStaticMethod(request.getProp());
if (result != null) {
replyProp = new Properties();
if (result instanceof Object[]) {
replyProp.setProperty(AdminCommandConstant.INVOKE_METHOD_RESULT,
Arrays.toString((Object[]) result));
} else {
replyProp.setProperty(AdminCommandConstant.INVOKE_METHOD_RESULT, result.toString());
}
}
break;
default:
throw new Exception("Bad command : \"" + AdminCommandConstant.commandNames[request.getCommand()] + "\"");
}
distributeReply(replyTo, requestMsgId, new AdminCommandReply(true,
AdminCommandConstant.commandNames[request.getCommand()] + " done.", replyProp));
} catch (Exception exc) {
if (logger.isLoggable(BasicLevel.WARN))
logger.log(BasicLevel.WARN, "", exc);
distributeReply(replyTo, requestMsgId, new AdminReply(false, exc.toString()));
}
} else {
// Forward the request to the right AdminTopic agent.
forward(getDefault(targetId.getTo()), new FwdAdminRequestNot(request, replyTo, requestMsgId));
}
} else {
// Forward the request to the target.
forward(targetId, new FwdAdminRequestNot(request, replyTo, requestMsgId, createMessageId()));
}