import java.nio.ByteBuffer;
import java.nio.ByteOrder;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.lttng.ust.agent.AbstractLttngAgent;
+import java.util.Collection;
/**
* Session daemon command asking the Java agent to list its registered loggers,
* @author Alexandre Montplaisir
* @author David Goulet
*/
-class SessiondListLoggersCommand implements ISessiondCommand {
+class SessiondListLoggersCommand extends SessiondCommand {
@Override
- public LttngAgentResponse execute(AbstractLttngAgent<?> agent) {
- final List<String> loggerList = new ArrayList<String>();
- int dataSize = 0;
-
- for (String event : agent.listEnabledEvents()) {
- loggerList.add(event);
- dataSize += event.length() + 1;
- }
-
- return new SessiondListLoggersResponse(loggerList, dataSize);
+ public LttngAgentResponse execute(ILttngTcpClientListener agent) {
+ final Collection<String> loggerList = agent.listAvailableEvents();
+ return new SessiondListLoggersResponse(loggerList);
}
private static class SessiondListLoggersResponse extends LttngAgentResponse {
private final static int SIZE = 12;
- private final List<String> loggers;
- private final int dataSize;
+ private final Collection<String> loggers;
- public SessiondListLoggersResponse(List<String> loggers, int dataSize) {
+ public SessiondListLoggersResponse(Collection<String> loggers) {
this.loggers = loggers;
- this.dataSize = dataSize;
}
@Override
@Override
public byte[] getBytes() {
+ /*
+ * Compute the data size, which is the number of bytes of each
+ * encoded string, +1 per string for the \0
+ */
+ int dataSize = 0;
+ for (String logger : loggers) {
+ dataSize += logger.getBytes(SESSIOND_PROTOCOL_CHARSET).length + 1;
+ }
+
+ /* Prepare the buffer */
byte data[] = new byte[SIZE + dataSize];
ByteBuffer buf = ByteBuffer.wrap(data);
buf.order(ByteOrder.BIG_ENDIAN);
- /* Returned code */
+ /* Write the header section of the response */
buf.putInt(getReturnCode().getCode());
buf.putInt(dataSize);
buf.putInt(loggers.size());
+ /* Write the payload */
for (String logger : loggers) {
- buf.put(logger.getBytes());
+ buf.put(logger.getBytes(SESSIOND_PROTOCOL_CHARSET));
/* NULL terminated byte after the logger name. */
buf.put((byte) 0x0);
}