class GetStatusHandler implements CommandHandler {
@Override
public CommandResult handleCommand(Command command) {
KongaCommandResult result = new KongaCommandResult(command.getCommandName());
int nArgs = command.getArguments().size();
if (nArgs != 1) {
result.addReturnValue(Integer.toString(KongaModuleStatusBitFields.rsERROR));
result.addReturnValue("Internal Error: Too many arguments for the GetStatus command.");
return result;
}
String cmd = command.getArguments().iterator().next();
int responseLevel = 0;
try {
responseLevel = Integer.parseInt(cmd);
if (responseLevel < -1 || responseLevel > 1)
responseLevel = 0;
} catch (NumberFormatException e) {
e.printStackTrace();
result.addReturnValue(Integer.toString(KongaModuleStatusBitFields.rsERROR));
result.addReturnValue("Internal Error: Invalid status level " + cmd);
return result;
}
long status = KongaModuleStatusBitFields.rsSTOPPED;
if (messageRouter != null) {
status = messageRouter.getStatus();
}
String msg = "The JMS Engine is ";
if ((status & KongaModuleStatusBitFields.rsSTARTING) != 0)
msg += "starting";
else if ((status & KongaModuleStatusBitFields.rsSTOPPING) != 0)
msg += "stopping";
else if ((status & KongaModuleStatusBitFields.rsRUNNING) != 0)
msg += "running";
else if ((status & KongaModuleStatusBitFields.rsSTOPPED) != 0)
msg += "stopped";
else if ((status & KongaModuleStatusBitFields.rsUNREACHABLE) != 0)
msg += "unreachable";
msg += ".";
if (responseLevel == 1) {
// TODO: Add "normal" level of information.
}
if (responseLevel == -1) {
// TODO: Add a longer status message
// Any more info we could send?
// Last 5 received/sent message times?
// Total time running?
}
result.addReturnValue(Long.toString(status));
result.addReturnValue(msg);
return result;
}