Commit | Line | Data |
---|---|---|
301a3ddb AM |
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 | * Interface for all response messages sent from the Java agent to the sessiond | |
26 | * daemon. Normally sent after a command coming from the session daemon was | |
27 | * executed. | |
28 | * | |
29 | * @author Alexandre Montplaisir | |
30 | */ | |
31 | interface ILttngAgentResponse { | |
32 | ||
33 | int INT_SIZE = 4; | |
34 | ||
35 | /** | |
36 | * Return codes used in agent responses, to indicate success or different | |
37 | * types of failures of the commands. | |
38 | */ | |
39 | enum ReturnCode { | |
40 | ||
41 | CODE_SUCCESS_CMD(1), | |
42 | CODE_INVALID_CMD(2), | |
43 | CODE_UNK_LOGGER_NAME(3); | |
44 | ||
45 | private int code; | |
46 | ||
47 | private ReturnCode(int c) { | |
48 | code = c; | |
49 | } | |
50 | ||
51 | public int getCode() { | |
52 | return code; | |
53 | } | |
54 | } | |
55 | ||
56 | /** | |
57 | * Get the {@link ReturnCode} that goes with this response. It is expected | |
58 | * by the session daemon, but some commands may require more than this | |
59 | * in their response. | |
60 | * | |
61 | * @return The return code | |
62 | */ | |
63 | ReturnCode getReturnCode(); | |
64 | ||
65 | /** | |
66 | * Gets a byte array of the response so that it may be streamed. | |
67 | * | |
68 | * @return The byte array of the response | |
69 | */ | |
70 | byte[] getBytes(); | |
71 | ||
72 | ILttngAgentResponse SUCESS_RESPONSE = new ILttngAgentResponse() { | |
73 | ||
74 | @Override | |
75 | public ReturnCode getReturnCode() { | |
76 | return ReturnCode.CODE_SUCCESS_CMD; | |
77 | } | |
78 | ||
79 | @Override | |
80 | public byte[] getBytes() { | |
81 | byte data[] = new byte[INT_SIZE]; | |
82 | ByteBuffer buf = ByteBuffer.wrap(data); | |
83 | buf.order(ByteOrder.BIG_ENDIAN); | |
84 | buf.putInt(getReturnCode().getCode()); | |
85 | return data; | |
86 | } | |
87 | }; | |
88 | ||
89 | ILttngAgentResponse FAILURE_RESPONSE = new ILttngAgentResponse() { | |
90 | ||
91 | @Override | |
92 | public ReturnCode getReturnCode() { | |
93 | return ReturnCode.CODE_INVALID_CMD; | |
94 | } | |
95 | ||
96 | @Override | |
97 | public byte[] getBytes() { | |
98 | byte data[] = new byte[INT_SIZE]; | |
99 | ByteBuffer buf = ByteBuffer.wrap(data); | |
100 | buf.order(ByteOrder.BIG_ENDIAN); | |
101 | buf.putInt(getReturnCode().getCode()); | |
102 | return data; | |
103 | } | |
104 | }; | |
105 | } |