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;fp=liblttng-ust-java-agent%2Fjava%2Flttng-ust-agent-common%2Forg%2Flttng%2Fust%2Fagent%2Fclient%2FSessiondListLoggersCommand.java;h=4dee6ae406c954466899357c0020257e41ddc49f;hb=8c207906959b7f74165febd957ac9c7472d017cd;hp=1c7ef9b400f019e7611c36b5bb349c99cc628b5d;hpb=b5eac5d48dddb45c7110bf1c5289af09630496e5;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 1c7ef9b4..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 @@ -34,13 +34,7 @@ class SessiondListLoggersCommand extends SessiondCommand { @Override public LttngAgentResponse execute(ILttngTcpClientListener agent) { final Collection loggerList = agent.listAvailableEvents(); - int dataSize = 0; - - for (String event : agent.listAvailableEvents()) { - dataSize += event.length() + 1; - } - - return new SessiondListLoggersResponse(loggerList, dataSize); + return new SessiondListLoggersResponse(loggerList); } private static class SessiondListLoggersResponse extends LttngAgentResponse { @@ -48,11 +42,9 @@ class SessiondListLoggersCommand extends SessiondCommand { private final static int SIZE = 12; private final Collection loggers; - private final int dataSize; - public SessiondListLoggersResponse(Collection loggers, int dataSize) { + public SessiondListLoggersResponse(Collection loggers) { this.loggers = loggers; - this.dataSize = dataSize; } @Override @@ -63,15 +55,26 @@ class SessiondListLoggersCommand extends SessiondCommand { @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(SESSIOND_PROTOCOL_CHARSET)); /* NULL terminated byte after the logger name. */