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
) {
157 logger
= handler
.logManager
.getLogger(event
.name
);
158 if (logger
== null) {
162 handler
.setEvent(event
);
163 logger
.addHandler(handler
);
164 enabledLoggers
.put(event
.name
, logger
);
170 * Execute enable handler action which is to enable the given handler
171 * to the received name.
173 * @return Event name as a string if the event is NOT found thus was
176 public LTTngEvent
execute(LTTngLogHandler handler
, HashMap enabledLoggers
) {
182 this.code
= lttng_jul_ret_code
.CODE_INVALID_CMD
;
186 /* Wild card to enable ALL logger. */
187 if (name
.trim().equals("*")) {
189 Enumeration loggers
= handler
.logManager
.getLoggerNames();
192 * Keep the loglevel value for all events in case an event
195 handler
.logLevelUseAll
= 1;
196 handler
.logLevelAll
= lttngLogLevel
;
197 handler
.logLevelTypeAll
= lttngLogLevelType
;
199 while (loggers
.hasMoreElements()) {
200 loggerName
= loggers
.nextElement().toString();
201 /* Somehow there is always an empty string at the end. */
202 if (loggerName
== "") {
206 if (enabledLoggers
.get(loggerName
) != null) {
211 * Create new event object and set it in the log handler so
212 * we can process the record entry with the right
213 * attributes like the loglevels.
215 event
= new LTTngEvent(loggerName
, lttngLogLevel
,
217 enableLogger(handler
, event
, enabledLoggers
);
219 this.code
= lttng_jul_ret_code
.CODE_SUCCESS_CMD
;
221 event
= new LTTngEvent("*", lttngLogLevel
, lttngLogLevelType
);
225 this.code
= lttng_jul_ret_code
.CODE_SUCCESS_CMD
;
228 * Create new event object and set it in the log handler so we can
229 * process the record entry with the right attributes like the
232 event
= new LTTngEvent(name
.trim(), lttngLogLevel
,
234 ret
= enableLogger(handler
, event
, enabledLoggers
);
242 public class sessiond_disable_handler
implements SessiondResponse
, SessiondCommand
{
243 private final static int SIZE
= 4;
246 /** Return status code to the session daemon. */
247 public lttng_jul_ret_code code
;
250 public void populate(byte[] data
) {
251 ByteBuffer buf
= ByteBuffer
.wrap(data
);
252 buf
.order(ByteOrder
.BIG_ENDIAN
);
253 name
= new String(data
, 0, data
.length
);
257 public byte[] getBytes() {
258 byte data
[] = new byte[SIZE
];
259 ByteBuffer buf
= ByteBuffer
.wrap(data
);
260 buf
.order(ByteOrder
.BIG_ENDIAN
);
261 buf
.putInt(code
.getCode());
266 * Execute disable handler action which is to disable the given handler
267 * to the received name.
269 public void execute(LTTngLogHandler handler
) {
273 this.code
= lttng_jul_ret_code
.CODE_INVALID_CMD
;
277 /* Wild card to disable ALL logger. */
278 if (name
.trim().equals("*")) {
280 Enumeration loggers
= handler
.logManager
.getLoggerNames();
281 while (loggers
.hasMoreElements()) {
282 loggerName
= loggers
.nextElement().toString();
283 /* Somehow there is always an empty string at the end. */
284 if (loggerName
== "") {
288 logger
= handler
.logManager
.getLogger(loggerName
);
289 logger
.removeHandler(handler
);
291 this.code
= lttng_jul_ret_code
.CODE_SUCCESS_CMD
;
295 logger
= handler
.logManager
.getLogger(name
.trim());
296 if (logger
== null) {
297 this.code
= lttng_jul_ret_code
.CODE_UNK_LOGGER_NAME
;
299 logger
.removeHandler(handler
);
300 this.code
= lttng_jul_ret_code
.CODE_SUCCESS_CMD
;
305 public class sessiond_list_logger
implements SessiondResponse
{
306 private final static int SIZE
= 12;
308 private int data_size
= 0;
309 private int nb_logger
= 0;
311 List
<String
> logger_list
= new ArrayList
<String
>();
313 /** Return status code to the session daemon. */
314 public lttng_jul_ret_code code
;
317 public byte[] getBytes() {
318 byte data
[] = new byte[SIZE
+ data_size
];
319 ByteBuffer buf
= ByteBuffer
.wrap(data
);
320 buf
.order(ByteOrder
.BIG_ENDIAN
);
323 buf
.putInt(code
.getCode());
324 buf
.putInt(data_size
);
325 buf
.putInt(nb_logger
);
327 for (String logger
: logger_list
) {
328 buf
.put(logger
.getBytes());
329 /* NULL terminated byte after the logger name. */
336 * Execute enable handler action which is to enable the given handler
337 * to the received name.
339 public void execute(LTTngLogHandler handler
) {
342 Enumeration loggers
= handler
.logManager
.getLoggerNames();
343 while (loggers
.hasMoreElements()) {
344 loggerName
= loggers
.nextElement().toString();
345 /* Somehow there is always an empty string at the end. */
346 if (loggerName
== "") {
350 this.logger_list
.add(loggerName
);
352 this.data_size
+= loggerName
.length() + 1;
355 this.code
= lttng_jul_ret_code
.CODE_SUCCESS_CMD
;
This page took 0.037023 seconds and 4 git commands to generate.