Turn ILttngAgentResponse into an abstract class
authorAlexandre Montplaisir <alexmonthy@efficios.com>
Tue, 25 Aug 2015 23:04:27 +0000 (19:04 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 22 Oct 2015 20:54:54 +0000 (16:54 -0400)
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>
liblttng-ust-java-agent/java/lttng-ust-agent-common/Makefile.am
liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/ILttngAgentResponse.java [deleted file]
liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/ISessiondCommand.java
liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/LttngAgentResponse.java [new file with mode: 0644]
liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/LttngTcpSessiondClient.java
liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/SessiondDisableEventCommand.java
liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/SessiondEnableEventCommand.java
liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/SessiondListLoggersCommand.java

index 26606b6b5470c802900b1eb86713e002136a47db..2258fdc0c347dcd90b40cc2e6b8d346c8eaa9a49 100644 (file)
@@ -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 (file)
index 7752c95..0000000
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * 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;
-               }
-       };
-}
index 0b5a164433f075542942427016158b5d8eea77be..c7d4faf8c38a5c0848c7ac2784505ff6c04455e2 100644 (file)
@@ -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 (file)
index 0000000..3c5a27e
--- /dev/null
@@ -0,0 +1,91 @@
+/*
+ * 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;
+               }
+       };
+}
index 3e9e24dd65463d2100d7d8095595919a24cddbcb..8fb0f5a5b81db230d218b5ac040174f00c9b231d 100644 (file)
@@ -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;
                        }
index 31d91e72e5a6d6e7e86e2bc5ae6f42d5fc6c625d..ee9d519f65a8fd699a07623974a0fc54041dabde 100644 (file)
@@ -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;
-               }
        };
 }
index 5f0fbd948ce5801c89eab64400dc8076ebc94a6e..bb20ac5784454ac6170b22913f1e096e3c379fe3 100644 (file)
@@ -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);
        }
 }
index cb20ea90b499d5e2a3dd3c1347d8ae558cf01b49..f5ad9c50443f6ec805ced0191e2456600693e148 100644 (file)
@@ -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<String> loggerList = new ArrayList<String>();
                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
This page took 0.031169 seconds and 4 git commands to generate.