157ad7565c18fe05432bdf6bcf93f3f12a206c78
[lttng-ust.git] / liblttng-ust-java-agent / java / lttng-ust-agent-common / org / lttng / ust / agent / client / SessiondDisableAppContextCommand.java
1 /*
2 * Copyright (C) 2016 - EfficiOS Inc., Alexandre Montplaisir <alexmonthy@efficios.com>
3 *
4 * This library is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License, version 2.1 only,
6 * as published by the Free Software Foundation.
7 *
8 * This library is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
11 * for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this library; if not, write to the Free Software Foundation,
15 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17
18 package org.lttng.ust.agent.client;
19
20 import java.nio.ByteBuffer;
21 import java.nio.ByteOrder;
22
23 /**
24 * Session daemon command indicating to the Java agent that an
25 * application-specific context was disabled in the tracing session.
26 *
27 * @author Alexandre Montplaisir
28 */
29 class SessiondDisableAppContextCommand extends SessiondCommand {
30
31 private final String retrieverName;
32 private final String contextName;
33
34 private final boolean commandIsValid;
35
36 public SessiondDisableAppContextCommand(byte[] data) {
37 if (data == null) {
38 throw new IllegalArgumentException();
39 }
40 ByteBuffer buf = ByteBuffer.wrap(data);
41 buf.order(ByteOrder.BIG_ENDIAN);
42
43 /*
44 * The buffer contains the retriever name first, followed by the
45 * context's name.
46 */
47 retrieverName = readNextString(buf);
48 contextName = readNextString(buf);
49
50 /* If any of these strings were null then the command was invalid */
51 commandIsValid = ((retrieverName != null) && (contextName != null));
52 }
53
54 @Override
55 public LttngAgentResponse execute(ILttngTcpClientListener agent) {
56 if (!commandIsValid) {
57 return LttngAgentResponse.FAILURE_RESPONSE;
58 }
59
60 boolean success = agent.appContextDisabled(retrieverName, contextName);
61 return (success ? LttngAgentResponse.SUCESS_RESPONSE : DISABLE_APP_CONTEXT_FAILURE_RESPONSE);
62 }
63
64 /**
65 * Response sent when the disable-context command asks to disable an
66 * unknown context name.
67 */
68 private static final LttngAgentResponse DISABLE_APP_CONTEXT_FAILURE_RESPONSE = new LttngAgentResponse() {
69 @Override
70 public ReturnCode getReturnCode() {
71 /* Same return code used for unknown event/logger names */
72 return ReturnCode.CODE_UNKNOWN_LOGGER_NAME;
73 }
74 };
75 }
This page took 0.030608 seconds and 3 git commands to generate.