X-Git-Url: http://git.lttng.org/?a=blobdiff_plain;ds=sidebyside;f=liblttng-ust-java-agent%2Fjava%2Flttng-ust-agent-common%2Forg%2Flttng%2Fust%2Fagent%2Fclient%2FSessiondListLoggersCommand.java;h=0500055c1394cc4af121136497d48391fa93fa3a;hb=c0c0989ab70574e09b2f7e8b48c2da6af664a849;hp=cb20ea90b499d5e2a3dd3c1347d8ae558cf01b49;hpb=301a3ddb302c9c2767f41f3b47d2f3e8ca8b9067;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 cb20ea90..0500055c 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 @@ -1,29 +1,16 @@ /* - * Copyright (C) 2015 - EfficiOS Inc., Alexandre Montplaisir - * Copyright (C) 2013 - David Goulet + * SPDX-License-Identifier: LGPL-2.1-only * - * This library is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License, version 2.1 only, - * as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Copyright (C) 2015 EfficiOS Inc. + * Copyright (C) 2015 Alexandre Montplaisir + * Copyright (C) 2013 David Goulet */ package org.lttng.ust.agent.client; 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, @@ -32,52 +19,54 @@ import org.lttng.ust.agent.AbstractLttngAgent; * @author Alexandre Montplaisir * @author David Goulet */ -class SessiondListLoggersCommand implements ISessiondCommand { +class SessiondListLoggersCommand extends SessiondCommand { @Override - public ILttngAgentResponse execute(AbstractLttngAgent 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); + public LttngAgentResponse execute(ILttngTcpClientListener agent) { + final Collection loggerList = agent.listAvailableEvents(); + return new SessiondListLoggersResponse(loggerList); } - private static class SessiondListLoggersResponse implements ILttngAgentResponse { + 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 public ReturnCode getReturnCode() { /* This command can't really fail */ - return ILttngAgentResponse.SUCESS_RESPONSE.getReturnCode(); + return ReturnCode.CODE_SUCCESS_CMD; } @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); }