2 * Copyright (C) 2015 - EfficiOS Inc., Alexandre Montplaisir <alexmonthy@efficios.com>
3 * Copyright (C) 2013 - David Goulet <dgoulet@efficios.com>
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.
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
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
19 package org
.lttng
.ust
.agent
.client
;
21 import java
.nio
.ByteBuffer
;
22 import java
.nio
.ByteOrder
;
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
29 * @author Alexandre Montplaisir
31 abstract class LttngAgentResponse
{
33 private static final int INT_SIZE
= 4;
36 * Return codes used in agent responses, to indicate success or different
37 * types of failures of the commands.
39 protected enum ReturnCode
{
43 CODE_UNK_LOGGER_NAME(3);
47 private ReturnCode(int c
) {
51 public int getCode() {
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
61 * @return The return code
63 public abstract ReturnCode
getReturnCode();
66 * Gets a byte array of the response so that it may be streamed.
68 * @return The byte array of the response
70 public byte[] getBytes() {
71 byte data
[] = new byte[INT_SIZE
];
72 ByteBuffer buf
= ByteBuffer
.wrap(data
);
73 buf
.order(ByteOrder
.BIG_ENDIAN
);
74 buf
.putInt(getReturnCode().getCode());
78 public static final LttngAgentResponse SUCESS_RESPONSE
= new LttngAgentResponse() {
80 public ReturnCode
getReturnCode() {
81 return ReturnCode
.CODE_SUCCESS_CMD
;
85 public static final LttngAgentResponse FAILURE_RESPONSE
= new LttngAgentResponse() {
87 public ReturnCode
getReturnCode() {
88 return ReturnCode
.CODE_INVALID_CMD
;