Move all sources to 'src/'
[lttng-ust.git] / src / liblttng-ust-java-agent / java / lttng-ust-agent-common / org / lttng / ust / agent / client / SessiondEnableEventCommand.java
1 /*
2 * SPDX-License-Identifier: LGPL-2.1-only
3 *
4 * Copyright (C) 2015 EfficiOS Inc.
5 * Copyright (C) 2015 Alexandre Montplaisir <alexmonthy@efficios.com>
6 * Copyright (C) 2013 David Goulet <dgoulet@efficios.com>
7 */
8
9 package org.lttng.ust.agent.client;
10
11 import java.nio.ByteBuffer;
12 import java.nio.ByteOrder;
13
14 import org.lttng.ust.agent.session.EventRule;
15 import org.lttng.ust.agent.session.LogLevelSelector;
16
17 /**
18 * Session daemon command indicating to the Java agent that some events were
19 * enabled in the tracing session.
20 *
21 * @author Alexandre Montplaisir
22 * @author David Goulet
23 */
24 class SessiondEnableEventCommand extends SessiondCommand {
25
26 /** Fixed event name length. Value defined by the lttng agent protocol. */
27 private static final int EVENT_NAME_LENGTH = 256;
28
29 private final boolean commandIsValid;
30
31 /* Parameters of the event rule being enabled */
32 private final String eventName;
33 private final LogLevelSelector logLevelFilter;
34 private final String filterString;
35
36 public SessiondEnableEventCommand(byte[] data) {
37 if (data == null) {
38 throw new IllegalArgumentException();
39 }
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);
45
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();
50
51 /* Read the filter string */
52 filterString = readNextString(buf);
53
54 /* The command was invalid if the string could not be read correctly */
55 commandIsValid = (filterString != null);
56 }
57
58 @Override
59 public LttngAgentResponse execute(ILttngTcpClientListener agent) {
60 if (!commandIsValid) {
61 return LttngAgentResponse.FAILURE_RESPONSE;
62 }
63
64 EventRule rule = new EventRule(eventName, logLevelFilter, filterString);
65 boolean success = agent.eventEnabled(rule);
66 return (success ? LttngAgentResponse.SUCESS_RESPONSE : LttngAgentResponse.FAILURE_RESPONSE);
67 }
68
69 @Override
70 public String toString() {
71 return "SessiondEnableEventCommand["
72 + "eventName=" + eventName
73 + ", logLevel=" + logLevelFilter.toString()
74 + ", filterString=" + filterString
75 +"]";
76 }
77 }
This page took 0.036463 seconds and 4 git commands to generate.