Commit | Line | Data |
---|---|---|
8ab5c06b AM |
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 enabled in the tracing session. | |
26 | * | |
27 | * @author Alexandre Montplaisir | |
28 | */ | |
29 | class SessiondEnableAppContextCommand extends SessiondCommand { | |
30 | ||
31 | private final String retrieverName; | |
32 | private final String contextName; | |
33 | ||
34 | private final boolean commandIsValid; | |
35 | ||
36 | public SessiondEnableAppContextCommand(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.appContextEnabled(retrieverName, contextName); | |
61 | return (success ? LttngAgentResponse.SUCESS_RESPONSE : LttngAgentResponse.FAILURE_RESPONSE); | |
62 | } | |
63 | } |