Introduce a new client listener interface for the Java agent
[lttng-ust.git] / liblttng-ust-java-agent / java / lttng-ust-agent-common / org / lttng / ust / agent / client / SessiondEnableEventCommand.java
1 /*
2 * Copyright (C) 2015 - EfficiOS Inc., Alexandre Montplaisir <alexmonthy@efficios.com>
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
19 package org.lttng.ust.agent.client;
20
21 import java.nio.ByteBuffer;
22 import java.nio.ByteOrder;
23
24 /**
25 * Session daemon command indicating to the Java agent that some events were
26 * enabled in the tracing session.
27 *
28 * @author Alexandre Montplaisir
29 * @author David Goulet
30 */
31 class SessiondEnableEventCommand implements ISessiondCommand {
32
33 private static final int INT_SIZE = 4;
34
35 /** Event name to enable in the tracing session */
36 private final String eventName;
37
38 public SessiondEnableEventCommand(byte[] data) {
39 if (data == null) {
40 throw new IllegalArgumentException();
41 }
42 int dataOffset = INT_SIZE * 2;
43
44 ByteBuffer buf = ByteBuffer.wrap(data);
45 buf.order(ByteOrder.LITTLE_ENDIAN);
46 buf.getInt(); // logLevel, currently unused
47 buf.getInt(); // logLevelType, currently unused
48 eventName = new String(data, dataOffset, data.length - dataOffset).trim();
49 }
50
51 @Override
52 public LttngAgentResponse execute(ILttngTcpClientListener agent) {
53 boolean success = agent.eventEnabled(this.eventName);
54 return (success ? LttngAgentResponse.SUCESS_RESPONSE : LttngAgentResponse.FAILURE_RESPONSE);
55 }
56 }
This page took 0.032843 seconds and 5 git commands to generate.