private static final int INT_SIZE = 4;
+ public static final LttngAgentResponse SUCESS_RESPONSE = new LttngAgentResponse() {
+ @Override
+ public ReturnCode getReturnCode() {
+ return ReturnCode.CODE_SUCCESS_CMD;
+ }
+ };
+
+ public static final LttngAgentResponse FAILURE_RESPONSE = new LttngAgentResponse() {
+ @Override
+ public ReturnCode getReturnCode() {
+ return ReturnCode.CODE_INVALID_CMD;
+ }
+ };
+
/**
* Return codes used in agent responses, to indicate success or different
* types of failures of the commands.
*/
protected enum ReturnCode {
- CODE_SUCCESS_CMD(1),
- CODE_INVALID_CMD(2),
- CODE_UNKNOWN_LOGGER_NAME(3);
+ CODE_SUCCESS_CMD(1, "sucess"),
+ CODE_INVALID_CMD(2, "invalid"),
+ CODE_UNKNOWN_LOGGER_NAME(3, "unknown logger name");
- private int code;
+ private final int code;
+ private final String toString;
- private ReturnCode(int c) {
+ private ReturnCode(int c, String str) {
code = c;
+ toString = str;
}
public int getCode() {
return code;
}
+
+ /**
+ * Mainly used for debugging. The strings are not sent through the
+ * socket.
+ */
+ @Override
+ public String toString() {
+ return toString;
+ }
}
/**
return data;
}
- public static final LttngAgentResponse SUCESS_RESPONSE = new LttngAgentResponse() {
- @Override
- public ReturnCode getReturnCode() {
- return ReturnCode.CODE_SUCCESS_CMD;
- }
- };
-
- public static final LttngAgentResponse FAILURE_RESPONSE = new LttngAgentResponse() {
- @Override
- public ReturnCode getReturnCode() {
- return ReturnCode.CODE_INVALID_CMD;
- }
- };
+ @Override
+ public String toString() {
+ return "LttngAgentResponse["
+ + "code=" + getReturnCode().getCode()
+ + ", " + getReturnCode().toString()
+ + "]";
+ }
}
/* Data read from the socket */
byte inputData[] = null;
/* Reply data written to the socket, sent to the sessiond */
- byte responseData[] = null;
+ LttngAgentResponse response;
while (true) {
/* Get header from session daemon. */
case CMD_LIST:
{
SessiondCommand listLoggerCmd = new SessiondListLoggersCommand();
- LttngAgentResponse response = listLoggerCmd.execute(logAgent);
- responseData = response.getBytes();
+ response = listLoggerCmd.execute(logAgent);
log("Received list loggers command");
break;
}
{
if (inputData == null) {
/* Invalid command */
- responseData = LttngAgentResponse.FAILURE_RESPONSE.getBytes();
+ response = LttngAgentResponse.FAILURE_RESPONSE;
break;
}
SessiondCommand enableEventCmd = new SessiondEnableEventCommand(inputData);
- LttngAgentResponse response = enableEventCmd.execute(logAgent);
- responseData = response.getBytes();
- log("Received enable event command");
+ response = enableEventCmd.execute(logAgent);
+ log("Received enable event command: " + enableEventCmd.toString());
break;
}
case CMD_EVENT_DISABLE:
{
if (inputData == null) {
/* Invalid command */
- responseData = LttngAgentResponse.FAILURE_RESPONSE.getBytes();
+ response = LttngAgentResponse.FAILURE_RESPONSE;
break;
}
SessiondCommand disableEventCmd = new SessiondDisableEventCommand(inputData);
- LttngAgentResponse response = disableEventCmd.execute(logAgent);
- responseData = response.getBytes();
- log("Received disable event command");
+ response = disableEventCmd.execute(logAgent);
+ log("Received disable event command: " + disableEventCmd.toString());
break;
}
case CMD_APP_CTX_ENABLE:
{
if (inputData == null) {
/* This commands expects a payload, invalid command */
- responseData = LttngAgentResponse.FAILURE_RESPONSE.getBytes();
+ response = LttngAgentResponse.FAILURE_RESPONSE;
break;
}
SessiondCommand enableAppCtxCmd = new SessiondEnableAppContextCommand(inputData);
- LttngAgentResponse response = enableAppCtxCmd.execute(logAgent);
- responseData = response.getBytes();
+ response = enableAppCtxCmd.execute(logAgent);
log("Received enable app-context command");
break;
}
{
if (inputData == null) {
/* This commands expects a payload, invalid command */
- responseData = LttngAgentResponse.FAILURE_RESPONSE.getBytes();
+ response = LttngAgentResponse.FAILURE_RESPONSE;
break;
}
SessiondCommand disableAppCtxCmd = new SessiondDisableAppContextCommand(inputData);
- LttngAgentResponse response = disableAppCtxCmd.execute(logAgent);
- responseData = response.getBytes();
+ response = disableAppCtxCmd.execute(logAgent);
log("Received disable app-context command");
break;
}
default:
{
/* Unknown command, send empty reply */
- responseData = new byte[4];
- ByteBuffer buf = ByteBuffer.wrap(responseData);
- buf.order(ByteOrder.BIG_ENDIAN);
+ response = null;
log("Received unknown command, ignoring");
break;
}
}
/* Send response to the session daemon. */
- log("Sending response");
+ byte[] responseData;
+ if (response == null) {
+ responseData = new byte[4];
+ ByteBuffer buf = ByteBuffer.wrap(responseData);
+ buf.order(ByteOrder.BIG_ENDIAN);
+ } else {
+ log("Sending response: " + response.toString());
+ responseData = response.getBytes();
+ }
this.outToSessiond.write(responseData, 0, responseData.length);
this.outToSessiond.flush();
}
*/
class SessiondDisableEventCommand extends SessiondCommand {
+ /**
+ * Response sent when the disable-event command asks to disable an
+ * unknown event.
+ */
+ private static final LttngAgentResponse DISABLE_EVENT_FAILURE_RESPONSE = new LttngAgentResponse() {
+ @Override
+ public ReturnCode getReturnCode() {
+ return ReturnCode.CODE_UNKNOWN_LOGGER_NAME;
+ }
+ };
+
/** Event name to disable from the tracing session */
private final String eventName;
return (success ? LttngAgentResponse.SUCESS_RESPONSE : DISABLE_EVENT_FAILURE_RESPONSE);
}
- /**
- * Response sent when the disable-event command asks to disable an
- * unknown event.
- */
- private static final LttngAgentResponse DISABLE_EVENT_FAILURE_RESPONSE = new LttngAgentResponse() {
- @Override
- public ReturnCode getReturnCode() {
- return ReturnCode.CODE_UNKNOWN_LOGGER_NAME;
- }
- };
+ @Override
+ public String toString() {
+ return "SessiondDisableEventCommand["
+ + "eventName=" + eventName
+ +"]";
+ }
}