0500055c1394cc4af121136497d48391fa93fa3a
[lttng-ust.git] /
1 /*
2 * SPDX-License-Identifier: LGPL-2.1-only
3 *
4 * Copyright (C) 2015 EfficiOS Inc.
5 * Copyright (C) 2015 Alexandre Montplaisir <alexmonthy@efficios.com>
6 * Copyright (C) 2013 David Goulet <dgoulet@efficios.com>
7 */
8
9 package org.lttng.ust.agent.client;
10
11 import java.nio.ByteBuffer;
12 import java.nio.ByteOrder;
13 import java.util.Collection;
14
15 /**
16 * Session daemon command asking the Java agent to list its registered loggers,
17 * which corresponds to event names in the tracing session.
18 *
19 * @author Alexandre Montplaisir
20 * @author David Goulet
21 */
22 class SessiondListLoggersCommand extends SessiondCommand {
23
24 @Override
25 public LttngAgentResponse execute(ILttngTcpClientListener agent) {
26 final Collection<String> loggerList = agent.listAvailableEvents();
27 return new SessiondListLoggersResponse(loggerList);
28 }
29
30 private static class SessiondListLoggersResponse extends LttngAgentResponse {
31
32 private final static int SIZE = 12;
33
34 private final Collection<String> loggers;
35
36 public SessiondListLoggersResponse(Collection<String> loggers) {
37 this.loggers = loggers;
38 }
39
40 @Override
41 public ReturnCode getReturnCode() {
42 /* This command can't really fail */
43 return ReturnCode.CODE_SUCCESS_CMD;
44 }
45
46 @Override
47 public byte[] getBytes() {
48 /*
49 * Compute the data size, which is the number of bytes of each
50 * encoded string, +1 per string for the \0
51 */
52 int dataSize = 0;
53 for (String logger : loggers) {
54 dataSize += logger.getBytes(SESSIOND_PROTOCOL_CHARSET).length + 1;
55 }
56
57 /* Prepare the buffer */
58 byte data[] = new byte[SIZE + dataSize];
59 ByteBuffer buf = ByteBuffer.wrap(data);
60 buf.order(ByteOrder.BIG_ENDIAN);
61
62 /* Write the header section of the response */
63 buf.putInt(getReturnCode().getCode());
64 buf.putInt(dataSize);
65 buf.putInt(loggers.size());
66
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. */
71 buf.put((byte) 0x0);
72 }
73 return data;
74 }
75 }
76
77 }
This page took 0.029872 seconds and 3 git commands to generate.