Fix: examples jul: add missing files to make dist
[lttng-ust.git] / liblttng-ust-java-agent / java / lttng-ust-agent-common / org / lttng / ust / agent / client / SessiondEnableEventCommand.java
CommitLineData
d60dfbe4 1/*
301a3ddb 2 * Copyright (C) 2015 - EfficiOS Inc., Alexandre Montplaisir <alexmonthy@efficios.com>
d60dfbe4
AM
3 * Copyright (C) 2013 - David Goulet <dgoulet@efficios.com>
4 *
5 * This library is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU Lesser General Public License, version 2.1 only,
7 * as published by the Free Software Foundation.
8 *
9 * This library is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
12 * for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19package org.lttng.ust.agent.client;
20
21import java.nio.ByteBuffer;
22import java.nio.ByteOrder;
23
3daf5cba
AM
24import org.lttng.ust.agent.session.EventRule;
25import org.lttng.ust.agent.session.LogLevelSelector;
26
301a3ddb
AM
27/**
28 * Session daemon command indicating to the Java agent that some events were
29 * enabled in the tracing session.
30 *
31 * @author Alexandre Montplaisir
32 * @author David Goulet
33 */
34class SessiondEnableEventCommand implements ISessiondCommand {
d60dfbe4 35
191f4058
AM
36 /** Fixed event name length. Value defined by the lttng agent protocol. */
37 private static final int EVENT_NAME_LENGTH = 256;
38
39 private final boolean commandIsValid;
d60dfbe4 40
3daf5cba 41 /* Parameters of the event rule being enabled */
301a3ddb 42 private final String eventName;
3daf5cba
AM
43 private final LogLevelSelector logLevelFilter;
44 private final String filterString;
d60dfbe4 45
301a3ddb
AM
46 public SessiondEnableEventCommand(byte[] data) {
47 if (data == null) {
48 throw new IllegalArgumentException();
49 }
d60dfbe4
AM
50 ByteBuffer buf = ByteBuffer.wrap(data);
51 buf.order(ByteOrder.LITTLE_ENDIAN);
3daf5cba
AM
52 int logLevel = buf.getInt();
53 int logLevelType = buf.getInt();
54 logLevelFilter = new LogLevelSelector(logLevel, logLevelType);
55
191f4058
AM
56 /* Read the event name */
57 byte[] eventNameBytes = new byte[EVENT_NAME_LENGTH];
58 buf.get(eventNameBytes);
59 eventName = new String(eventNameBytes).trim();
60
61 /*
62 * Read the filter string. The buffer contains the length (number of
63 * bytes), then the bytes themselves.
64 *
65 * The length is represented as an unsigned int, but it should never
66 * be greater than Integer.MAX_VALUE.
67 */
68 int filterStringLength = buf.getInt();
69 if (filterStringLength < 0) {
70 /*
71 * The (unsigned) length is above what the sessiond should send. The
72 * command cannot be processed.
73 */
74 filterString = null;
75 commandIsValid = false;
76 return;
77 }
78 if (filterStringLength == 0) {
79 /* There is explicitly no filter string */
80 filterString = "";
81 commandIsValid = true;
82 return;
83 }
84
85 byte[] filterStringBytes = new byte[filterStringLength];
86 buf.get(filterStringBytes);
87 filterString = new String(filterStringBytes).trim();
88
89 commandIsValid = true;
d60dfbe4
AM
90 }
91
92 @Override
3165c2f5 93 public LttngAgentResponse execute(ILttngTcpClientListener agent) {
191f4058
AM
94 if (!commandIsValid) {
95 return LttngAgentResponse.FAILURE_RESPONSE;
96 }
97
3daf5cba
AM
98 EventRule rule = new EventRule(eventName, logLevelFilter, filterString);
99 boolean success = agent.eventEnabled(rule);
93253569 100 return (success ? LttngAgentResponse.SUCESS_RESPONSE : LttngAgentResponse.FAILURE_RESPONSE);
d60dfbe4
AM
101 }
102}
This page took 0.027662 seconds and 4 git commands to generate.