X-Git-Url: http://git.lttng.org./?a=blobdiff_plain;f=liblttng-ust-java-agent%2Fjava%2Flttng-ust-agent-common%2Forg%2Flttng%2Fust%2Fagent%2Fclient%2FSessiondListLoggersCommand.java;h=4dee6ae406c954466899357c0020257e41ddc49f;hb=6e1fdc3a9e5e6231c8edc87b35eb9babdc4b69bb;hp=c06eaaad95e09db12565d841a7b75c88ada37194;hpb=3165c2f51abe3093f4c5512b499e33cb380b387d;p=lttng-ust.git diff --git a/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/SessiondListLoggersCommand.java b/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/SessiondListLoggersCommand.java index c06eaaad..4dee6ae4 100644 --- a/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/SessiondListLoggersCommand.java +++ b/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/SessiondListLoggersCommand.java @@ -20,8 +20,7 @@ package org.lttng.ust.agent.client; import java.nio.ByteBuffer; import java.nio.ByteOrder; -import java.util.ArrayList; -import java.util.List; +import java.util.Collection; /** * Session daemon command asking the Java agent to list its registered loggers, @@ -30,31 +29,22 @@ import java.util.List; * @author Alexandre Montplaisir * @author David Goulet */ -class SessiondListLoggersCommand implements ISessiondCommand { +class SessiondListLoggersCommand extends SessiondCommand { @Override public LttngAgentResponse execute(ILttngTcpClientListener agent) { - final List loggerList = new ArrayList(); - int dataSize = 0; - - for (String event : agent.listEnabledEvents()) { - loggerList.add(event); - dataSize += event.length() + 1; - } - - return new SessiondListLoggersResponse(loggerList, dataSize); + final Collection loggerList = agent.listAvailableEvents(); + return new SessiondListLoggersResponse(loggerList); } private static class SessiondListLoggersResponse extends LttngAgentResponse { private final static int SIZE = 12; - private final List loggers; - private final int dataSize; + private final Collection loggers; - public SessiondListLoggersResponse(List loggers, int dataSize) { + public SessiondListLoggersResponse(Collection loggers) { this.loggers = loggers; - this.dataSize = dataSize; } @Override @@ -65,17 +55,28 @@ class SessiondListLoggersCommand implements ISessiondCommand { @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); }