a8bc15209e8c3e4072d5f6a437d0a8921a2a4812
[lttng-ust.git] /
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 import java.util.Collection;
24
25 /**
26 * Session daemon command asking the Java agent to list its registered loggers,
27 * which corresponds to event names in the tracing session.
28 *
29 * @author Alexandre Montplaisir
30 * @author David Goulet
31 */
32 class SessiondListLoggersCommand implements ISessiondCommand {
33
34 @Override
35 public LttngAgentResponse execute(ILttngTcpClientListener agent) {
36 final Collection<String> loggerList = agent.listAvailableEvents();
37 int dataSize = 0;
38
39 for (String event : agent.listAvailableEvents()) {
40 dataSize += event.length() + 1;
41 }
42
43 return new SessiondListLoggersResponse(loggerList, dataSize);
44 }
45
46 private static class SessiondListLoggersResponse extends LttngAgentResponse {
47
48 private final static int SIZE = 12;
49
50 private final Collection<String> loggers;
51 private final int dataSize;
52
53 public SessiondListLoggersResponse(Collection<String> loggers, int dataSize) {
54 this.loggers = loggers;
55 this.dataSize = dataSize;
56 }
57
58 @Override
59 public ReturnCode getReturnCode() {
60 /* This command can't really fail */
61 return ReturnCode.CODE_SUCCESS_CMD;
62 }
63
64 @Override
65 public byte[] getBytes() {
66 byte data[] = new byte[SIZE + dataSize];
67 ByteBuffer buf = ByteBuffer.wrap(data);
68 buf.order(ByteOrder.BIG_ENDIAN);
69
70 /* Returned code */
71 buf.putInt(getReturnCode().getCode());
72 buf.putInt(dataSize);
73 buf.putInt(loggers.size());
74
75 for (String logger : loggers) {
76 buf.put(logger.getBytes());
77 /* NULL terminated byte after the logger name. */
78 buf.put((byte) 0x0);
79 }
80 return data;
81 }
82 }
83
84 }
This page took 0.029948 seconds and 3 git commands to generate.