Move to kernel style SPDX license identifiers
[lttng-ust.git] / liblttng-ust-java-agent / java / lttng-ust-agent-common / org / lttng / ust / agent / client / SessiondDisableAppContextCommand.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 disabled in the tracing session.
16 *
17 * @author Alexandre Montplaisir
18 */
19 class SessiondDisableAppContextCommand extends SessiondCommand {
20
21 private final String retrieverName;
22 private final String contextName;
23
24 private final boolean commandIsValid;
25
26 public SessiondDisableAppContextCommand(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.appContextDisabled(retrieverName, contextName);
51 return (success ? LttngAgentResponse.SUCESS_RESPONSE : DISABLE_APP_CONTEXT_FAILURE_RESPONSE);
52 }
53
54 /**
55 * Response sent when the disable-context command asks to disable an
56 * unknown context name.
57 */
58 private static final LttngAgentResponse DISABLE_APP_CONTEXT_FAILURE_RESPONSE = new LttngAgentResponse() {
59 @Override
60 public ReturnCode getReturnCode() {
61 /* Same return code used for unknown event/logger names */
62 return ReturnCode.CODE_UNKNOWN_LOGGER_NAME;
63 }
64 };
65 }
This page took 0.030452 seconds and 4 git commands to generate.