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
;
13 import java
.util
.Collection
;
16 * Session daemon command asking the Java agent to list its registered loggers,
17 * which corresponds to event names in the tracing session.
19 * @author Alexandre Montplaisir
20 * @author David Goulet
22 class SessiondListLoggersCommand
extends SessiondCommand
{
25 public LttngAgentResponse
execute(ILttngTcpClientListener agent
) {
26 final Collection
<String
> loggerList
= agent
.listAvailableEvents();
27 return new SessiondListLoggersResponse(loggerList
);
30 private static class SessiondListLoggersResponse
extends LttngAgentResponse
{
32 private final static int SIZE
= 12;
34 private final Collection
<String
> loggers
;
36 public SessiondListLoggersResponse(Collection
<String
> loggers
) {
37 this.loggers
= loggers
;
41 public ReturnCode
getReturnCode() {
42 /* This command can't really fail */
43 return ReturnCode
.CODE_SUCCESS_CMD
;
47 public byte[] getBytes() {
49 * Compute the data size, which is the number of bytes of each
50 * encoded string, +1 per string for the \0
53 for (String logger
: loggers
) {
54 dataSize
+= logger
.getBytes(SESSIOND_PROTOCOL_CHARSET
).length
+ 1;
57 /* Prepare the buffer */
58 byte data
[] = new byte[SIZE
+ dataSize
];
59 ByteBuffer buf
= ByteBuffer
.wrap(data
);
60 buf
.order(ByteOrder
.BIG_ENDIAN
);
62 /* Write the header section of the response */
63 buf
.putInt(getReturnCode().getCode());
65 buf
.putInt(loggers
.size());
67 /* Write the payload */
68 for (String logger
: loggers
) {
69 buf
.put(logger
.getBytes(SESSIOND_PROTOCOL_CHARSET
));
70 /* NULL terminated byte after the logger name. */