Move to kernel style SPDX license identifiers
[lttng-ust.git] / liblttng-ust-java-agent / java / lttng-ust-agent-common / org / lttng / ust / agent / client / SessiondEnableAppContextCommand.java
1 /*
2 * SPDX-License-Identifier: LGPL-2.1-only
3 *
4 * Copyright (C) 2016 EfficiOS Inc.
5 * Copyright (C) 2016 Alexandre Montplaisir <alexmonthy@efficios.com>
6 */
7
8 package org.lttng.ust.agent.client;
9
10 import java.nio.ByteBuffer;
11 import java.nio.ByteOrder;
12
13 /**
14 * Session daemon command indicating to the Java agent that an
15 * application-specific context was enabled in the tracing session.
16 *
17 * @author Alexandre Montplaisir
18 */
19 class SessiondEnableAppContextCommand extends SessiondCommand {
20
21 private final String retrieverName;
22 private final String contextName;
23
24 private final boolean commandIsValid;
25
26 public SessiondEnableAppContextCommand(byte[] data) {
27 if (data == null) {
28 throw new IllegalArgumentException();
29 }
30 ByteBuffer buf = ByteBuffer.wrap(data);
31 buf.order(ByteOrder.BIG_ENDIAN);
32
33 /*
34 * The buffer contains the retriever name first, followed by the
35 * context's name.
36 */
37 retrieverName = readNextString(buf);
38 contextName = readNextString(buf);
39
40 /* If any of these strings were null then the command was invalid */
41 commandIsValid = ((retrieverName != null) && (contextName != null));
42 }
43
44 @Override
45 public LttngAgentResponse execute(ILttngTcpClientListener agent) {
46 if (!commandIsValid) {
47 return LttngAgentResponse.FAILURE_RESPONSE;
48 }
49
50 boolean success = agent.appContextEnabled(retrieverName, contextName);
51 return (success ? LttngAgentResponse.SUCESS_RESPONSE : LttngAgentResponse.FAILURE_RESPONSE);
52 }
53 }
This page took 0.029845 seconds and 4 git commands to generate.