Move to kernel style SPDX license identifiers
[lttng-ust.git] / liblttng-ust-java-agent / java / lttng-ust-agent-common / org / lttng / ust / agent / client / SessiondListLoggersCommand.java
index a8bc15209e8c3e4072d5f6a437d0a8921a2a4812..0500055c1394cc4af121136497d48391fa93fa3a 100644 (file)
@@ -1,19 +1,9 @@
 /*
- * Copyright (C) 2015 - EfficiOS Inc., Alexandre Montplaisir <alexmonthy@efficios.com>
- * Copyright (C) 2013 - David Goulet <dgoulet@efficios.com>
+ * 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 <alexmonthy@efficios.com>
+ * Copyright (C) 2013 David Goulet <dgoulet@efficios.com>
  */
 
 package org.lttng.ust.agent.client;
@@ -29,18 +19,12 @@ import java.util.Collection;
  * @author Alexandre Montplaisir
  * @author David Goulet
  */
-class SessiondListLoggersCommand implements ISessiondCommand {
+class SessiondListLoggersCommand extends SessiondCommand {
 
        @Override
        public LttngAgentResponse execute(ILttngTcpClientListener agent) {
                final Collection<String> 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 +32,9 @@ class SessiondListLoggersCommand implements ISessiondCommand {
                private final static int SIZE = 12;
 
                private final Collection<String> loggers;
-               private final int dataSize;
 
-               public SessiondListLoggersResponse(Collection<String> loggers, int dataSize) {
+               public SessiondListLoggersResponse(Collection<String> loggers) {
                        this.loggers = loggers;
-                       this.dataSize = dataSize;
                }
 
                @Override
@@ -63,17 +45,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);
                        }
This page took 0.025634 seconds and 4 git commands to generate.