This allows defining a default behavior for the getBytes() method.
That behavior consists of only returning the integer return code,
which is what most (but not all) subclasses use.
Signed-off-by: Alexandre Montplaisir <alexmonthy@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
$(pkgpath)/ILttngAgent.java \
$(pkgpath)/ILttngHandler.java \
$(pkgpath)/LTTngAgent.java \
- $(pkgpath)/client/ILttngAgentResponse.java \
+ $(pkgpath)/client/LttngAgentResponse.java \
$(pkgpath)/client/ISessiondCommand.java \
$(pkgpath)/client/LttngTcpSessiondClient.java \
$(pkgpath)/client/SessiondCommandHeader.java \
+++ /dev/null
-/*
- * Copyright (C) 2015 - EfficiOS Inc., Alexandre Montplaisir <alexmonthy@efficios.com>
- * Copyright (C) 2013 - David Goulet <dgoulet@efficios.com>
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License, version 2.1 only,
- * as published by the Free Software Foundation.
- *
- * This library is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this library; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-package org.lttng.ust.agent.client;
-
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-
-/**
- * Interface for all response messages sent from the Java agent to the sessiond
- * daemon. Normally sent after a command coming from the session daemon was
- * executed.
- *
- * @author Alexandre Montplaisir
- */
-interface ILttngAgentResponse {
-
- int INT_SIZE = 4;
-
- /**
- * Return codes used in agent responses, to indicate success or different
- * types of failures of the commands.
- */
- enum ReturnCode {
-
- CODE_SUCCESS_CMD(1),
- CODE_INVALID_CMD(2),
- CODE_UNK_LOGGER_NAME(3);
-
- private int code;
-
- private ReturnCode(int c) {
- code = c;
- }
-
- public int getCode() {
- return code;
- }
- }
-
- /**
- * Get the {@link ReturnCode} that goes with this response. It is expected
- * by the session daemon, but some commands may require more than this
- * in their response.
- *
- * @return The return code
- */
- ReturnCode getReturnCode();
-
- /**
- * Gets a byte array of the response so that it may be streamed.
- *
- * @return The byte array of the response
- */
- byte[] getBytes();
-
- ILttngAgentResponse SUCESS_RESPONSE = new ILttngAgentResponse() {
-
- @Override
- public ReturnCode getReturnCode() {
- return ReturnCode.CODE_SUCCESS_CMD;
- }
-
- @Override
- public byte[] getBytes() {
- byte data[] = new byte[INT_SIZE];
- ByteBuffer buf = ByteBuffer.wrap(data);
- buf.order(ByteOrder.BIG_ENDIAN);
- buf.putInt(getReturnCode().getCode());
- return data;
- }
- };
-
- ILttngAgentResponse FAILURE_RESPONSE = new ILttngAgentResponse() {
-
- @Override
- public ReturnCode getReturnCode() {
- return ReturnCode.CODE_INVALID_CMD;
- }
-
- @Override
- public byte[] getBytes() {
- byte data[] = new byte[INT_SIZE];
- ByteBuffer buf = ByteBuffer.wrap(data);
- buf.order(ByteOrder.BIG_ENDIAN);
- buf.putInt(getReturnCode().getCode());
- return data;
- }
- };
-}
* The agent on which to execute the command
* @return If the command completed successfully or not
*/
- public ILttngAgentResponse execute(AbstractLttngAgent<?> agent);
+ public LttngAgentResponse execute(AbstractLttngAgent<?> agent);
}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (C) 2015 - EfficiOS Inc., Alexandre Montplaisir <alexmonthy@efficios.com>
+ * Copyright (C) 2013 - David Goulet <dgoulet@efficios.com>
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License, version 2.1 only,
+ * as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.lttng.ust.agent.client;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+/**
+ * Interface for all response messages sent from the Java agent to the sessiond
+ * daemon. Normally sent after a command coming from the session daemon was
+ * executed.
+ *
+ * @author Alexandre Montplaisir
+ */
+abstract class LttngAgentResponse {
+
+ private static final int INT_SIZE = 4;
+
+ /**
+ * 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_UNK_LOGGER_NAME(3);
+
+ private int code;
+
+ private ReturnCode(int c) {
+ code = c;
+ }
+
+ public int getCode() {
+ return code;
+ }
+ }
+
+ /**
+ * Get the {@link ReturnCode} that goes with this response. It is expected
+ * by the session daemon, but some commands may require more than this
+ * in their response.
+ *
+ * @return The return code
+ */
+ public abstract ReturnCode getReturnCode();
+
+ /**
+ * Gets a byte array of the response so that it may be streamed.
+ *
+ * @return The byte array of the response
+ */
+ public byte[] getBytes() {
+ byte data[] = new byte[INT_SIZE];
+ ByteBuffer buf = ByteBuffer.wrap(data);
+ buf.order(ByteOrder.BIG_ENDIAN);
+ buf.putInt(getReturnCode().getCode());
+ 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;
+ }
+ };
+}
case CMD_LIST:
{
ISessiondCommand listLoggerCmd = new SessiondListLoggersCommand();
- ILttngAgentResponse response = listLoggerCmd.execute(logAgent);
+ LttngAgentResponse response = listLoggerCmd.execute(logAgent);
responseData = response.getBytes();
break;
}
{
if (inputData == null) {
/* Invalid command */
- responseData = ILttngAgentResponse.FAILURE_RESPONSE.getBytes();
+ responseData = LttngAgentResponse.FAILURE_RESPONSE.getBytes();
break;
}
ISessiondCommand enableCmd = new SessiondEnableEventCommand(inputData);
- ILttngAgentResponse response = enableCmd.execute(logAgent);
+ LttngAgentResponse response = enableCmd.execute(logAgent);
responseData = response.getBytes();
break;
}
{
if (inputData == null) {
/* Invalid command */
- responseData = ILttngAgentResponse.FAILURE_RESPONSE.getBytes();
+ responseData = LttngAgentResponse.FAILURE_RESPONSE.getBytes();
break;
}
ISessiondCommand disableCmd = new SessiondDisableEventCommand(inputData);
- ILttngAgentResponse response = disableCmd.execute(logAgent);
+ LttngAgentResponse response = disableCmd.execute(logAgent);
responseData = response.getBytes();
break;
}
}
@Override
- public ILttngAgentResponse execute(AbstractLttngAgent<?> agent) {
+ public LttngAgentResponse execute(AbstractLttngAgent<?> agent) {
boolean success = agent.eventDisabled(this.eventName);
- return (success ? ILttngAgentResponse.SUCESS_RESPONSE : DISABLE_EVENT_FAILURE_RESPONSE);
+ 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 ILttngAgentResponse DISABLE_EVENT_FAILURE_RESPONSE = new ILttngAgentResponse() {
-
+ private static final LttngAgentResponse DISABLE_EVENT_FAILURE_RESPONSE = new LttngAgentResponse() {
@Override
public ReturnCode getReturnCode() {
return ReturnCode.CODE_UNK_LOGGER_NAME;
}
-
- @Override
- public byte[] getBytes() {
- byte data[] = new byte[INT_SIZE];
- ByteBuffer buf = ByteBuffer.wrap(data);
- buf.order(ByteOrder.BIG_ENDIAN);
- buf.putInt(getReturnCode().getCode());
- return data;
- }
};
}
}
@Override
- public ILttngAgentResponse execute(AbstractLttngAgent<?> agent) {
+ public LttngAgentResponse execute(AbstractLttngAgent<?> agent) {
boolean success = agent.eventEnabled(this.eventName);
- return (success ? ILttngAgentResponse.SUCESS_RESPONSE : ILttngAgentResponse.FAILURE_RESPONSE);
+ return (success ? LttngAgentResponse.SUCESS_RESPONSE : LttngAgentResponse.FAILURE_RESPONSE);
}
}
class SessiondListLoggersCommand implements ISessiondCommand {
@Override
- public ILttngAgentResponse execute(AbstractLttngAgent<?> agent) {
+ public LttngAgentResponse execute(AbstractLttngAgent<?> agent) {
final List<String> loggerList = new ArrayList<String>();
int dataSize = 0;
return new SessiondListLoggersResponse(loggerList, dataSize);
}
- private static class SessiondListLoggersResponse implements ILttngAgentResponse {
+ private static class SessiondListLoggersResponse extends LttngAgentResponse {
private final static int SIZE = 12;
@Override
public ReturnCode getReturnCode() {
/* This command can't really fail */
- return ILttngAgentResponse.SUCESS_RESPONSE.getReturnCode();
+ return ReturnCode.CODE_SUCCESS_CMD;
}
@Override