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
.lang
.Object
;
24 import java
.util
.logging
.Logger
;
25 import java
.util
.ArrayList
;
26 import java
.util
.HashMap
;
27 import java
.util
.List
;
28 import java
.util
.Enumeration
;
30 public interface LTTngSessiondCmd2_4
{
32 * Maximum name length for a logger name to be send to sessiond.
34 final static int NAME_MAX
= 255;
37 * Size of a primitive type int in byte. Because you know, Java can't
38 * provide that since it does not makes sense...
40 final static int INT_SIZE
= 4;
42 public interface SessiondResponse
{
44 * Gets a byte array of the command so that it may be streamed
46 * @return the byte array of the command
48 public byte[] getBytes();
51 public interface SessiondCommand
{
53 * Populate the class from a byte array
56 * the byte array containing the streamed command
58 public void populate(byte[] data
);
61 public enum lttng_jul_command
{
62 /** List logger(s). */
64 /** Enable logger by name. */
66 /** Disable logger by name. */
68 /** Registration done */
73 private lttng_jul_command(int c
) {
77 public int getCommand() {
82 enum lttng_jul_ret_code
{
85 CODE_UNK_LOGGER_NAME(3);
88 private lttng_jul_ret_code(int c
) {
92 public int getCode() {
97 public class sessiond_hdr
implements SessiondCommand
{
98 /** ABI size of command header. */
99 public final static int SIZE
= 16;
100 /** Payload size in bytes following this header. */
101 public long data_size
;
103 public lttng_jul_command cmd
;
104 /** Command version. */
105 public int cmd_version
;
107 public void populate(byte[] data
) {
108 ByteBuffer buf
= ByteBuffer
.wrap(data
);
109 buf
.order(ByteOrder
.BIG_ENDIAN
);
111 data_size
= buf
.getLong();
112 cmd
= lttng_jul_command
.values()[buf
.getInt() - 1];
113 cmd_version
= buf
.getInt();
117 public class sessiond_enable_handler
implements SessiondResponse
, SessiondCommand
{
118 private final static int SIZE
= 4;
120 public int lttngLogLevel
;
121 public int lttngLogLevelType
;
123 /** Return status code to the session daemon. */
124 public lttng_jul_ret_code code
;
127 public void populate(byte[] data
) {
128 int data_offset
= INT_SIZE
* 2;
130 ByteBuffer buf
= ByteBuffer
.wrap(data
);
131 buf
.order(ByteOrder
.LITTLE_ENDIAN
);
132 lttngLogLevel
= buf
.getInt();
133 lttngLogLevelType
= buf
.getInt();
134 name
= new String(data
, data_offset
, data
.length
- data_offset
);
138 public byte[] getBytes() {
139 byte data
[] = new byte[SIZE
];
140 ByteBuffer buf
= ByteBuffer
.wrap(data
);
141 buf
.order(ByteOrder
.BIG_ENDIAN
);
142 buf
.putInt(code
.getCode());
147 * Enable a logger meaning add our handler to it using an exiting
148 * event. If successful, the logger is added to the given enabled
151 * @return 0 if NO logger is found else 1 if added.
153 public int enableLogger(LTTngLogHandler handler
, LTTngEvent event
,
154 HashMap enabledLoggers
) {
158 logger
= handler
.logManager
.getLogger(event
.name
);
159 if (logger
== null) {
163 ret
= handler
.setEvent(event
);
165 /* Newly created event, add the handler. */
166 logger
.addHandler(handler
);
167 enabledLoggers
.put(event
.name
, logger
);
174 * Execute enable handler action which is to enable the given handler
175 * to the received name.
177 * @return Event name as a string if the event is NOT found thus was
180 public LTTngEvent
execute(LTTngLogHandler handler
, HashMap enabledLoggers
) {
183 LTTngEvent event
= null;
186 this.code
= lttng_jul_ret_code
.CODE_INVALID_CMD
;
190 /* Wild card to enable ALL logger. */
191 if (name
.trim().equals("*")) {
193 Enumeration loggers
= handler
.logManager
.getLoggerNames();
196 * Keep the loglevel value for all events in case an event
199 if (lttngLogLevel
!= -1) {
200 handler
.logLevelUseAll
= 1;
201 handler
.logLevelsAll
.add(new LTTngLogLevel(lttngLogLevel
,
205 while (loggers
.hasMoreElements()) {
206 loggerName
= loggers
.nextElement().toString();
207 /* Somehow there is always an empty string at the end. */
208 if (loggerName
== "") {
213 * Create new event object and set it in the log handler so
214 * we can process the record entry with the right
215 * attributes like the loglevels.
217 event
= new LTTngEvent(loggerName
, 0, 0);
218 /* Clean up loglevel and merge the the ones from all events. */
219 event
.logLevels
.clear();
220 event
.logLevels
.addAll(handler
.logLevelsAll
);
221 enableLogger(handler
, event
, enabledLoggers
);
223 this.code
= lttng_jul_ret_code
.CODE_SUCCESS_CMD
;
226 * Only return an event if this is a newly created event
227 * meaning the loglevel is valid.
229 if (lttngLogLevel
!= -1) {
230 event
= new LTTngEvent("*", lttngLogLevel
, lttngLogLevelType
);
235 this.code
= lttng_jul_ret_code
.CODE_SUCCESS_CMD
;
238 * Create new event object and set it in the log handler so we can
239 * process the record entry with the right attributes like the
242 event
= new LTTngEvent(name
.trim(), lttngLogLevel
,
244 ret
= enableLogger(handler
, event
, enabledLoggers
);
252 public class sessiond_disable_handler
implements SessiondResponse
, SessiondCommand
{
253 private final static int SIZE
= 4;
256 /** Return status code to the session daemon. */
257 public lttng_jul_ret_code code
;
260 public void populate(byte[] data
) {
261 ByteBuffer buf
= ByteBuffer
.wrap(data
);
262 buf
.order(ByteOrder
.BIG_ENDIAN
);
263 name
= new String(data
, 0, data
.length
);
267 public byte[] getBytes() {
268 byte data
[] = new byte[SIZE
];
269 ByteBuffer buf
= ByteBuffer
.wrap(data
);
270 buf
.order(ByteOrder
.BIG_ENDIAN
);
271 buf
.putInt(code
.getCode());
276 * Execute disable handler action which is to disable the given handler
277 * to the received name.
279 public void execute(LTTngLogHandler handler
) {
283 this.code
= lttng_jul_ret_code
.CODE_INVALID_CMD
;
287 /* Wild card to disable ALL logger. */
288 if (name
.trim().equals("*")) {
290 Enumeration loggers
= handler
.logManager
.getLoggerNames();
291 while (loggers
.hasMoreElements()) {
292 loggerName
= loggers
.nextElement().toString();
293 /* Somehow there is always an empty string at the end. */
294 if (loggerName
== "") {
298 logger
= handler
.logManager
.getLogger(loggerName
);
299 logger
.removeHandler(handler
);
301 this.code
= lttng_jul_ret_code
.CODE_SUCCESS_CMD
;
305 logger
= handler
.logManager
.getLogger(name
.trim());
306 if (logger
== null) {
307 this.code
= lttng_jul_ret_code
.CODE_UNK_LOGGER_NAME
;
309 logger
.removeHandler(handler
);
310 this.code
= lttng_jul_ret_code
.CODE_SUCCESS_CMD
;
315 public class sessiond_list_logger
implements SessiondResponse
{
316 private final static int SIZE
= 12;
318 private int data_size
= 0;
319 private int nb_logger
= 0;
321 List
<String
> logger_list
= new ArrayList
<String
>();
323 /** Return status code to the session daemon. */
324 public lttng_jul_ret_code code
;
327 public byte[] getBytes() {
328 byte data
[] = new byte[SIZE
+ data_size
];
329 ByteBuffer buf
= ByteBuffer
.wrap(data
);
330 buf
.order(ByteOrder
.BIG_ENDIAN
);
333 buf
.putInt(code
.getCode());
334 buf
.putInt(data_size
);
335 buf
.putInt(nb_logger
);
337 for (String logger
: logger_list
) {
338 buf
.put(logger
.getBytes());
339 /* NULL terminated byte after the logger name. */
346 * Execute enable handler action which is to enable the given handler
347 * to the received name.
349 public void execute(LTTngLogHandler handler
) {
352 Enumeration loggers
= handler
.logManager
.getLoggerNames();
353 while (loggers
.hasMoreElements()) {
354 loggerName
= loggers
.nextElement().toString();
355 /* Somehow there is always an empty string at the end. */
356 if (loggerName
== "") {
360 this.logger_list
.add(loggerName
);
362 this.data_size
+= loggerName
.length() + 1;
365 this.code
= lttng_jul_ret_code
.CODE_SUCCESS_CMD
;
This page took 0.038077 seconds and 5 git commands to generate.