$(pkgpath)/ILttngHandler.java \
$(pkgpath)/LTTngAgent.java \
$(pkgpath)/client/ILttngTcpClientListener.java \
- $(pkgpath)/client/ISessiondCommand.java \
+ $(pkgpath)/client/SessiondCommand.java \
$(pkgpath)/client/LttngAgentResponse.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;
-
-/**
- * Interface to represent all commands sent from the session daemon to the Java
- * agent. The agent is then expected to execute the command and provide a
- * response.
- *
- * @author Alexandre Montplaisir
- */
-interface ISessiondCommand {
-
- enum CommandType {
-
- /** List logger(s). */
- CMD_LIST(1),
- /** Enable logger by name. */
- CMD_ENABLE(2),
- /** Disable logger by name. */
- CMD_DISABLE(3),
- /** Registration done */
- CMD_REG_DONE(4);
-
- private int code;
-
- private CommandType(int c) {
- code = c;
- }
-
- public int getCommandType() {
- return code;
- }
- }
-
- /**
- * Execute the command handler's action on the specified tracing agent.
- *
- * @param agent
- * The agent on which to execute the command
- * @return If the command completed successfully or not
- */
- public LttngAgentResponse execute(ILttngTcpClientListener agent);
-}
\ No newline at end of file
}
case CMD_LIST:
{
- ISessiondCommand listLoggerCmd = new SessiondListLoggersCommand();
+ SessiondCommand listLoggerCmd = new SessiondListLoggersCommand();
LttngAgentResponse response = listLoggerCmd.execute(logAgent);
responseData = response.getBytes();
break;
responseData = LttngAgentResponse.FAILURE_RESPONSE.getBytes();
break;
}
- ISessiondCommand enableCmd = new SessiondEnableEventCommand(inputData);
+ SessiondCommand enableCmd = new SessiondEnableEventCommand(inputData);
LttngAgentResponse response = enableCmd.execute(logAgent);
responseData = response.getBytes();
break;
responseData = LttngAgentResponse.FAILURE_RESPONSE.getBytes();
break;
}
- ISessiondCommand disableCmd = new SessiondDisableEventCommand(inputData);
+ SessiondCommand disableCmd = new SessiondDisableEventCommand(inputData);
LttngAgentResponse response = disableCmd.execute(logAgent);
responseData = response.getBytes();
break;
--- /dev/null
+/*
+ * Copyright (C) 2015-2016 - 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;
+
+/**
+ * Base class to represent all commands sent from the session daemon to the Java
+ * agent. The agent is then expected to execute the command and provide a
+ * response.
+ *
+ * @author Alexandre Montplaisir
+ */
+abstract class SessiondCommand {
+
+ enum CommandType {
+
+ /** List logger(s). */
+ CMD_LIST(1),
+ /** Enable logger by name. */
+ CMD_ENABLE(2),
+ /** Disable logger by name. */
+ CMD_DISABLE(3),
+ /** Registration done */
+ CMD_REG_DONE(4);
+
+ private int code;
+
+ private CommandType(int c) {
+ code = c;
+ }
+
+ public int getCommandType() {
+ return code;
+ }
+ }
+
+ /**
+ * Execute the command handler's action on the specified tracing agent.
+ *
+ * @param agent
+ * The agent on which to execute the command
+ * @return If the command completed successfully or not
+ */
+ public abstract LttngAgentResponse execute(ILttngTcpClientListener agent);
+
+ /**
+ * Utility method to read agent-protocol strings passed on the socket. The
+ * buffer will contain a 32-bit integer representing the length, immediately
+ * followed by the string itself.
+ *
+ * @param buffer
+ * The ByteBuffer from which to read. It should already be setup
+ * and positioned where the read should begin.
+ * @return The string that was read, or <code>null</code> if it was badly
+ * formatted.
+ */
+ protected static String readNextString(ByteBuffer buffer) {
+ int length = buffer.getInt();
+ if (length < 0) {
+ /* The string length should be positive */
+ return null;
+ }
+ if (length == 0) {
+ /* The string is explicitly an empty string */
+ return "";
+ }
+
+ byte[] stringBytes = new byte[length];
+ buffer.get(stringBytes);
+ return new String(stringBytes).trim();
+ }
+}
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
-import org.lttng.ust.agent.client.ISessiondCommand.CommandType;
+import org.lttng.ust.agent.client.SessiondCommand.CommandType;
/**
* Header of session daemon commands.
* @author Alexandre Montplaisir
* @author David Goulet
*/
-class SessiondDisableEventCommand implements ISessiondCommand {
+class SessiondDisableEventCommand extends SessiondCommand {
/** Event name to disable from the tracing session */
private final String eventName;
* @author Alexandre Montplaisir
* @author David Goulet
*/
-class SessiondEnableEventCommand implements ISessiondCommand {
+class SessiondEnableEventCommand extends SessiondCommand {
/** Fixed event name length. Value defined by the lttng agent protocol. */
private static final int EVENT_NAME_LENGTH = 256;
buf.get(eventNameBytes);
eventName = new String(eventNameBytes).trim();
- /*
- * Read the filter string. The buffer contains the length (number of
- * bytes), then the bytes themselves.
- *
- * The length is represented as an unsigned int, but it should never
- * be greater than Integer.MAX_VALUE.
- */
- int filterStringLength = buf.getInt();
- if (filterStringLength < 0) {
- /*
- * The (unsigned) length is above what the sessiond should send. The
- * command cannot be processed.
- */
- filterString = null;
- commandIsValid = false;
- return;
- }
- if (filterStringLength == 0) {
- /* There is explicitly no filter string */
- filterString = "";
- commandIsValid = true;
- return;
- }
-
- byte[] filterStringBytes = new byte[filterStringLength];
- buf.get(filterStringBytes);
- filterString = new String(filterStringBytes).trim();
+ /* Read the filter string */
+ filterString = readNextString(buf);
- commandIsValid = true;
+ /* The command was invalid if the string could not be read correctly */
+ commandIsValid = (filterString != null);
}
@Override
* @author Alexandre Montplaisir
* @author David Goulet
*/
-class SessiondListLoggersCommand implements ISessiondCommand {
+class SessiondListLoggersCommand extends SessiondCommand {
@Override
public LttngAgentResponse execute(ILttngTcpClientListener agent) {