2 * SPDX-License-Identifier: LGPL-2.1-only
4 * Copyright (C) 2015-2016 EfficiOS Inc.
5 * Copyright (C) 2015-2016 Alexandre Montplaisir <alexmonthy@efficios.com>
6 * Copyright (C) 2013 David Goulet <dgoulet@efficios.com>
9 package org.lttng.ust.agent.client;
11 import java.nio.ByteBuffer;
12 import java.nio.charset.Charset;
15 * Base class to represent all commands sent from the session daemon to the Java
16 * agent. The agent is then expected to execute the command and provide a
19 * @author Alexandre Montplaisir
21 abstract class SessiondCommand {
24 * Encoding that should be used for the strings in the sessiond agent
25 * protocol on the socket.
27 protected static final Charset SESSIOND_PROTOCOL_CHARSET = Charset.forName("UTF-8");
30 /** List logger(s). */
32 /** Enable logger by name. */
34 /** Disable logger by name. */
36 /** Registration done */
38 /** Enable application context */
39 CMD_APP_CTX_ENABLE(5),
40 /** Disable application context */
41 CMD_APP_CTX_DISABLE(6);
45 private CommandType(int c) {
49 public int getCommandType() {
55 * Execute the command handler's action on the specified tracing agent.
58 * The agent on which to execute the command
59 * @return If the command completed successfully or not
61 public abstract LttngAgentResponse execute(ILttngTcpClientListener agent);
64 * Utility method to read agent-protocol strings passed on the socket. The
65 * buffer will contain a 32-bit integer representing the length, immediately
66 * followed by the string itself.
69 * The ByteBuffer from which to read. It should already be setup
70 * and positioned where the read should begin.
71 * @return The string that was read, or <code>null</code> if it was badly
74 protected static String readNextString(ByteBuffer buffer) {
75 int nbBytes = buffer.getInt();
77 /* The string length should be positive */
81 /* The string is explicitly an empty string */
85 byte[] stringBytes = new byte[nbBytes];
86 buffer.get(stringBytes);
87 return new String(stringBytes, SESSIOND_PROTOCOL_CHARSET).trim();