2 * Copyright (C) 2013 - David Goulet <dgoulet@efficios.com>
5 * This library is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU Lesser General Public License, version 2.1 only,
7 * as published by the Free Software Foundation.
9 * This library is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 package org
.lttng
.ust
.jul
;
21 import java
.nio
.ByteBuffer
;
22 import java
.nio
.ByteOrder
;
23 import java
.util
.logging
.Logger
;
24 import java
.util
.ArrayList
;
25 import java
.util
.HashMap
;
26 import java
.util
.List
;
27 import java
.util
.Enumeration
;
29 public interface LTTngSessiondCmd2_4
{
31 * Maximum name length for a logger name to be send to sessiond.
33 final static int NAME_MAX
= 255;
35 public interface SessiondResponse
{
37 * Gets a byte array of the command so that it may be streamed
39 * @return the byte array of the command
41 public byte[] getBytes();
44 public interface SessiondCommand
{
46 * Populate the class from a byte array
49 * the byte array containing the streamed command
51 public void populate(byte[] data
);
54 public enum lttng_jul_command
{
55 /** List logger(s). */
57 /** Enable logger by name. */
59 /** Disable logger by name. */
63 private lttng_jul_command(int c
) {
67 public int getCommand() {
72 enum lttng_jul_ret_code
{
75 CODE_UNK_LOGGER_NAME(3);
78 private lttng_jul_ret_code(int c
) {
82 public int getCode() {
87 public class sessiond_hdr
implements SessiondCommand
{
88 /** ABI size of command header. */
89 public final static int SIZE
= 16;
90 /** Payload size in bytes following this header. */
91 public long data_size
;
93 public lttng_jul_command cmd
;
94 /** Command version. */
95 public int cmd_version
;
97 public void populate(byte[] data
) {
98 ByteBuffer buf
= ByteBuffer
.wrap(data
);
99 buf
.order(ByteOrder
.BIG_ENDIAN
);
101 data_size
= buf
.getLong();
102 cmd
= lttng_jul_command
.values()[buf
.getInt() - 1];
103 cmd_version
= buf
.getInt();
107 public class sessiond_enable_handler
implements SessiondResponse
, SessiondCommand
{
108 private final static int SIZE
= 4;
111 /** Return status code to the session daemon. */
112 public lttng_jul_ret_code code
;
115 public void populate(byte[] data
) {
116 ByteBuffer buf
= ByteBuffer
.wrap(data
);
117 buf
.order(ByteOrder
.LITTLE_ENDIAN
);
118 name
= new String(data
, 0, data
.length
);
122 public byte[] getBytes() {
123 byte data
[] = new byte[SIZE
];
124 ByteBuffer buf
= ByteBuffer
.wrap(data
);
125 buf
.order(ByteOrder
.BIG_ENDIAN
);
126 buf
.putInt(code
.getCode());
131 * Execute enable handler action which is to enable the given handler
132 * to the received name.
134 * @return Event name as a string if the event is NOT found thus was
137 public String
execute(LTTngLogHandler handler
, HashMap enabledLoggers
) {
141 this.code
= lttng_jul_ret_code
.CODE_INVALID_CMD
;
145 /* Wild card to enable ALL logger. */
146 if (name
.trim().equals("*")) {
148 Enumeration loggers
= handler
.logManager
.getLoggerNames();
149 while (loggers
.hasMoreElements()) {
150 loggerName
= loggers
.nextElement().toString();
151 /* Somehow there is always an empty string at the end. */
152 if (loggerName
== "") {
156 if (enabledLoggers
.get(loggerName
) != null) {
160 logger
= handler
.logManager
.getLogger(loggerName
);
161 logger
.addHandler(handler
);
162 enabledLoggers
.put(loggerName
, logger
);
164 this.code
= lttng_jul_ret_code
.CODE_SUCCESS_CMD
;
166 * Return the name as a new string so we can add the * event
167 * name to the event list that we need to enable for new
170 return new String(name
);
173 this.code
= lttng_jul_ret_code
.CODE_SUCCESS_CMD
;
174 logger
= handler
.logManager
.getLogger(name
.trim());
175 if (logger
!= null) {
176 logger
.addHandler(handler
);
177 enabledLoggers
.put(name
.trim(), logger
);
180 return new String(name
);
185 public class sessiond_disable_handler
implements SessiondResponse
, SessiondCommand
{
186 private final static int SIZE
= 4;
189 /** Return status code to the session daemon. */
190 public lttng_jul_ret_code code
;
193 public void populate(byte[] data
) {
194 ByteBuffer buf
= ByteBuffer
.wrap(data
);
195 buf
.order(ByteOrder
.BIG_ENDIAN
);
196 name
= new String(data
, 0, data
.length
);
200 public byte[] getBytes() {
201 byte data
[] = new byte[SIZE
];
202 ByteBuffer buf
= ByteBuffer
.wrap(data
);
203 buf
.order(ByteOrder
.BIG_ENDIAN
);
204 buf
.putInt(code
.getCode());
209 * Execute disable handler action which is to disable the given handler
210 * to the received name.
212 public void execute(LTTngLogHandler handler
) {
216 this.code
= lttng_jul_ret_code
.CODE_INVALID_CMD
;
220 /* Wild card to disable ALL logger. */
221 if (name
.trim().equals("*")) {
223 Enumeration loggers
= handler
.logManager
.getLoggerNames();
224 while (loggers
.hasMoreElements()) {
225 loggerName
= loggers
.nextElement().toString();
226 /* Somehow there is always an empty string at the end. */
227 if (loggerName
== "") {
231 logger
= handler
.logManager
.getLogger(loggerName
);
232 logger
.removeHandler(handler
);
234 this.code
= lttng_jul_ret_code
.CODE_SUCCESS_CMD
;
238 logger
= handler
.logManager
.getLogger(name
.trim());
239 if (logger
== null) {
240 this.code
= lttng_jul_ret_code
.CODE_UNK_LOGGER_NAME
;
242 logger
.removeHandler(handler
);
243 this.code
= lttng_jul_ret_code
.CODE_SUCCESS_CMD
;
248 public class sessiond_list_logger
implements SessiondResponse
{
249 private final static int SIZE
= 12;
251 private int data_size
= 0;
252 private int nb_logger
= 0;
254 List
<String
> logger_list
= new ArrayList
<String
>();
256 /** Return status code to the session daemon. */
257 public lttng_jul_ret_code code
;
260 public byte[] getBytes() {
261 byte data
[] = new byte[SIZE
+ data_size
];
262 ByteBuffer buf
= ByteBuffer
.wrap(data
);
263 buf
.order(ByteOrder
.BIG_ENDIAN
);
266 buf
.putInt(code
.getCode());
267 buf
.putInt(data_size
);
268 buf
.putInt(nb_logger
);
270 for (String logger
: logger_list
) {
271 buf
.put(logger
.getBytes());
272 /* NULL terminated byte after the logger name. */
279 * Execute enable handler action which is to enable the given handler
280 * to the received name.
282 public void execute(LTTngLogHandler handler
) {
285 Enumeration loggers
= handler
.logManager
.getLoggerNames();
286 while (loggers
.hasMoreElements()) {
287 loggerName
= loggers
.nextElement().toString();
288 /* Somehow there is always an empty string at the end. */
289 if (loggerName
== "") {
293 this.logger_list
.add(loggerName
);
295 this.data_size
+= loggerName
.length() + 1;
298 this.code
= lttng_jul_ret_code
.CODE_SUCCESS_CMD
;
This page took 0.036113 seconds and 5 git commands to generate.