2 * SPDX-License-Identifier: LGPL-2.1-only
4 * Copyright (C) 2015 EfficiOS Inc.
5 * Copyright (C) 2015 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.ByteOrder;
14 import org.lttng.ust.agent.session.EventRule;
15 import org.lttng.ust.agent.session.LogLevelSelector;
18 * Session daemon command indicating to the Java agent that some events were
19 * enabled in the tracing session.
21 * @author Alexandre Montplaisir
22 * @author David Goulet
24 class SessiondEnableEventCommand extends SessiondCommand {
26 /** Fixed event name length. Value defined by the lttng agent protocol. */
27 private static final int EVENT_NAME_LENGTH = 256;
29 private final boolean commandIsValid;
31 /* Parameters of the event rule being enabled */
32 private final String eventName;
33 private final LogLevelSelector logLevelFilter;
34 private final String filterString;
36 public SessiondEnableEventCommand(byte[] data) {
38 throw new IllegalArgumentException();
40 ByteBuffer buf = ByteBuffer.wrap(data);
41 buf.order(ByteOrder.BIG_ENDIAN);
42 int logLevel = buf.getInt();
43 int logLevelType = buf.getInt();
44 logLevelFilter = new LogLevelSelector(logLevel, logLevelType);
46 /* Read the event name */
47 byte[] eventNameBytes = new byte[EVENT_NAME_LENGTH];
48 buf.get(eventNameBytes);
49 eventName = new String(eventNameBytes, SESSIOND_PROTOCOL_CHARSET).trim();
51 /* Read the filter string */
52 filterString = readNextString(buf);
54 /* The command was invalid if the string could not be read correctly */
55 commandIsValid = (filterString != null);
59 public LttngAgentResponse execute(ILttngTcpClientListener agent) {
60 if (!commandIsValid) {
61 return LttngAgentResponse.FAILURE_RESPONSE;
64 EventRule rule = new EventRule(eventName, logLevelFilter, filterString);
65 boolean success = agent.eventEnabled(rule);
66 return (success ? LttngAgentResponse.SUCESS_RESPONSE : LttngAgentResponse.FAILURE_RESPONSE);
70 public String toString() {
71 return "SessiondEnableEventCommand["
72 + "eventName=" + eventName
73 + ", logLevel=" + logLevelFilter.toString()
74 + ", filterString=" + filterString