From: Alexandre Montplaisir Date: Tue, 25 Aug 2015 23:04:27 +0000 (-0400) Subject: Turn ILttngAgentResponse into an abstract class X-Git-Tag: v2.8.0-rc1~66 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=932535693bb8a719c40f63141dbfac786388ed4a;p=lttng-ust.git Turn ILttngAgentResponse into an abstract class 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 Signed-off-by: Mathieu Desnoyers --- diff --git a/liblttng-ust-java-agent/java/lttng-ust-agent-common/Makefile.am b/liblttng-ust-java-agent/java/lttng-ust-agent-common/Makefile.am index 26606b6b..2258fdc0 100644 --- a/liblttng-ust-java-agent/java/lttng-ust-agent-common/Makefile.am +++ b/liblttng-ust-java-agent/java/lttng-ust-agent-common/Makefile.am @@ -14,7 +14,7 @@ dist_noinst_JAVA = $(pkgpath)/AbstractLttngAgent.java \ $(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 \ diff --git a/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/ILttngAgentResponse.java b/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/ILttngAgentResponse.java deleted file mode 100644 index 7752c950..00000000 --- a/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/ILttngAgentResponse.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (C) 2015 - EfficiOS Inc., Alexandre Montplaisir - * Copyright (C) 2013 - David Goulet - * - * 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; - } - }; -} diff --git a/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/ISessiondCommand.java b/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/ISessiondCommand.java index 0b5a1644..c7d4faf8 100644 --- a/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/ISessiondCommand.java +++ b/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/ISessiondCommand.java @@ -58,5 +58,5 @@ interface ISessiondCommand { * 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 diff --git a/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/LttngAgentResponse.java b/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/LttngAgentResponse.java new file mode 100644 index 00000000..3c5a27e5 --- /dev/null +++ b/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/LttngAgentResponse.java @@ -0,0 +1,91 @@ +/* + * Copyright (C) 2015 - EfficiOS Inc., Alexandre Montplaisir + * Copyright (C) 2013 - David Goulet + * + * 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; + } + }; +} diff --git a/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/LttngTcpSessiondClient.java b/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/LttngTcpSessiondClient.java index 3e9e24dd..8fb0f5a5 100644 --- a/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/LttngTcpSessiondClient.java +++ b/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/LttngTcpSessiondClient.java @@ -248,7 +248,7 @@ public class LttngTcpSessiondClient implements Runnable { case CMD_LIST: { ISessiondCommand listLoggerCmd = new SessiondListLoggersCommand(); - ILttngAgentResponse response = listLoggerCmd.execute(logAgent); + LttngAgentResponse response = listLoggerCmd.execute(logAgent); responseData = response.getBytes(); break; } @@ -256,11 +256,11 @@ public class LttngTcpSessiondClient implements Runnable { { 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; } @@ -268,11 +268,11 @@ public class LttngTcpSessiondClient implements Runnable { { 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; } diff --git a/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/SessiondDisableEventCommand.java b/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/SessiondDisableEventCommand.java index 31d91e72..ee9d519f 100644 --- a/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/SessiondDisableEventCommand.java +++ b/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/SessiondDisableEventCommand.java @@ -45,29 +45,19 @@ class SessiondDisableEventCommand implements ISessiondCommand { } @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; - } }; } diff --git a/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/SessiondEnableEventCommand.java b/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/SessiondEnableEventCommand.java index 5f0fbd94..bb20ac57 100644 --- a/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/SessiondEnableEventCommand.java +++ b/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/SessiondEnableEventCommand.java @@ -51,8 +51,8 @@ class SessiondEnableEventCommand implements ISessiondCommand { } @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); } } diff --git a/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/SessiondListLoggersCommand.java b/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/SessiondListLoggersCommand.java index cb20ea90..f5ad9c50 100644 --- a/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/SessiondListLoggersCommand.java +++ b/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/SessiondListLoggersCommand.java @@ -35,7 +35,7 @@ import org.lttng.ust.agent.AbstractLttngAgent; class SessiondListLoggersCommand implements ISessiondCommand { @Override - public ILttngAgentResponse execute(AbstractLttngAgent agent) { + public LttngAgentResponse execute(AbstractLttngAgent agent) { final List loggerList = new ArrayList(); int dataSize = 0; @@ -47,7 +47,7 @@ class SessiondListLoggersCommand implements ISessiondCommand { return new SessiondListLoggersResponse(loggerList, dataSize); } - private static class SessiondListLoggersResponse implements ILttngAgentResponse { + private static class SessiondListLoggersResponse extends LttngAgentResponse { private final static int SIZE = 12; @@ -62,7 +62,7 @@ class SessiondListLoggersCommand implements ISessiondCommand { @Override public ReturnCode getReturnCode() { /* This command can't really fail */ - return ILttngAgentResponse.SUCESS_RESPONSE.getReturnCode(); + return ReturnCode.CODE_SUCCESS_CMD; } @Override