2 * SPDX-License-Identifier: LGPL-2.1-only
4 * Copyright (C) 2015 EfficiOS Inc.
5 * Copyright (C) 2015 Alexandre Montplaisir <alexmonthy@efficios.com>
6 * Copyright (C) 2013 David Goulet <dgoulet@efficios.com>
9 package org
.lttng
.ust
.agent
.client
;
11 import java
.nio
.ByteBuffer
;
12 import java
.nio
.ByteOrder
;
15 * Interface for all response messages sent from the Java agent to the sessiond
16 * daemon. Normally sent after a command coming from the session daemon was
19 * @author Alexandre Montplaisir
21 abstract class LttngAgentResponse
{
23 private static final int INT_SIZE
= 4;
25 public static final LttngAgentResponse SUCESS_RESPONSE
= new LttngAgentResponse() {
27 public ReturnCode
getReturnCode() {
28 return ReturnCode
.CODE_SUCCESS_CMD
;
32 public static final LttngAgentResponse FAILURE_RESPONSE
= new LttngAgentResponse() {
34 public ReturnCode
getReturnCode() {
35 return ReturnCode
.CODE_INVALID_CMD
;
40 * Return codes used in agent responses, to indicate success or different
41 * types of failures of the commands.
43 protected enum ReturnCode
{
45 CODE_SUCCESS_CMD(1, "sucess"),
46 CODE_INVALID_CMD(2, "invalid"),
47 CODE_UNKNOWN_LOGGER_NAME(3, "unknown logger name");
49 private final int code
;
50 private final String toString
;
52 private ReturnCode(int c
, String str
) {
57 public int getCode() {
62 * Mainly used for debugging. The strings are not sent through the
66 public String
toString() {
72 * Get the {@link ReturnCode} that goes with this response. It is expected
73 * by the session daemon, but some commands may require more than this
76 * @return The return code
78 public abstract ReturnCode
getReturnCode();
81 * Gets a byte array of the response so that it may be streamed.
83 * @return The byte array of the response
85 public byte[] getBytes() {
86 byte data
[] = new byte[INT_SIZE
];
87 ByteBuffer buf
= ByteBuffer
.wrap(data
);
88 buf
.order(ByteOrder
.BIG_ENDIAN
);
89 buf
.putInt(getReturnCode().getCode());
94 public String
toString() {
95 return "LttngAgentResponse["
96 + "code=" + getReturnCode().getCode()
97 + ", " + getReturnCode().toString()