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. */
70 private lttng_jul_command(int c
) {
74 public int getCommand() {
79 enum lttng_jul_ret_code
{
82 CODE_UNK_LOGGER_NAME(3);
85 private lttng_jul_ret_code(int c
) {
89 public int getCode() {
94 public class sessiond_hdr
implements SessiondCommand
{
95 /** ABI size of command header. */
96 public final static int SIZE
= 16;
97 /** Payload size in bytes following this header. */
98 public long data_size
;
100 public lttng_jul_command cmd
;
101 /** Command version. */
102 public int cmd_version
;
104 public void populate(byte[] data
) {
105 ByteBuffer buf
= ByteBuffer
.wrap(data
);
106 buf
.order(ByteOrder
.BIG_ENDIAN
);
108 data_size
= buf
.getLong();
109 cmd
= lttng_jul_command
.values()[buf
.getInt() - 1];
110 cmd_version
= buf
.getInt();
114 public class sessiond_enable_handler
implements SessiondResponse
, SessiondCommand
{
115 private final static int SIZE
= 4;
117 public int lttngLogLevel
;
118 public int lttngLogLevelType
;
120 /** Return status code to the session daemon. */
121 public lttng_jul_ret_code code
;
124 public void populate(byte[] data
) {
125 int data_offset
= INT_SIZE
* 2;
127 ByteBuffer buf
= ByteBuffer
.wrap(data
);
128 buf
.order(ByteOrder
.LITTLE_ENDIAN
);
129 lttngLogLevel
= buf
.getInt();
130 lttngLogLevelType
= buf
.getInt();
131 name
= new String(data
, data_offset
, data
.length
- data_offset
);
135 public byte[] getBytes() {
136 byte data
[] = new byte[SIZE
];
137 ByteBuffer buf
= ByteBuffer
.wrap(data
);
138 buf
.order(ByteOrder
.BIG_ENDIAN
);
139 buf
.putInt(code
.getCode());
144 * Enable a logger meaning add our handler to it using an exiting
145 * event. If successful, the logger is added to the given enabled
148 * @return 0 if NO logger is found else 1 if added.
150 public int enableLogger(LTTngLogHandler handler
, LTTngEvent event
,
151 HashMap enabledLoggers
) {
154 logger
= handler
.logManager
.getLogger(event
.name
);
155 if (logger
== null) {
159 handler
.setEvent(event
);
160 logger
.addHandler(handler
);
161 enabledLoggers
.put(event
.name
, logger
);
167 * Execute enable handler action which is to enable the given handler
168 * to the received name.
170 * @return Event name as a string if the event is NOT found thus was
173 public LTTngEvent
execute(LTTngLogHandler handler
, HashMap enabledLoggers
) {
179 this.code
= lttng_jul_ret_code
.CODE_INVALID_CMD
;
183 /* Wild card to enable ALL logger. */
184 if (name
.trim().equals("*")) {
186 Enumeration loggers
= handler
.logManager
.getLoggerNames();
189 * Keep the loglevel value for all events in case an event
192 handler
.logLevelUseAll
= 1;
193 handler
.logLevelAll
= lttngLogLevel
;
194 handler
.logLevelTypeAll
= lttngLogLevelType
;
196 while (loggers
.hasMoreElements()) {
197 loggerName
= loggers
.nextElement().toString();
198 /* Somehow there is always an empty string at the end. */
199 if (loggerName
== "") {
203 if (enabledLoggers
.get(loggerName
) != null) {
208 * Create new event object and set it in the log handler so
209 * we can process the record entry with the right
210 * attributes like the loglevels.
212 event
= new LTTngEvent(loggerName
, lttngLogLevel
,
214 enableLogger(handler
, event
, enabledLoggers
);
216 this.code
= lttng_jul_ret_code
.CODE_SUCCESS_CMD
;
218 event
= new LTTngEvent("*", lttngLogLevel
, lttngLogLevelType
);
222 this.code
= lttng_jul_ret_code
.CODE_SUCCESS_CMD
;
225 * Create new event object and set it in the log handler so we can
226 * process the record entry with the right attributes like the
229 event
= new LTTngEvent(name
.trim(), lttngLogLevel
,
231 ret
= enableLogger(handler
, event
, enabledLoggers
);
239 public class sessiond_disable_handler
implements SessiondResponse
, SessiondCommand
{
240 private final static int SIZE
= 4;
243 /** Return status code to the session daemon. */
244 public lttng_jul_ret_code code
;
247 public void populate(byte[] data
) {
248 ByteBuffer buf
= ByteBuffer
.wrap(data
);
249 buf
.order(ByteOrder
.BIG_ENDIAN
);
250 name
= new String(data
, 0, data
.length
);
254 public byte[] getBytes() {
255 byte data
[] = new byte[SIZE
];
256 ByteBuffer buf
= ByteBuffer
.wrap(data
);
257 buf
.order(ByteOrder
.BIG_ENDIAN
);
258 buf
.putInt(code
.getCode());
263 * Execute disable handler action which is to disable the given handler
264 * to the received name.
266 public void execute(LTTngLogHandler handler
) {
270 this.code
= lttng_jul_ret_code
.CODE_INVALID_CMD
;
274 /* Wild card to disable ALL logger. */
275 if (name
.trim().equals("*")) {
277 Enumeration loggers
= handler
.logManager
.getLoggerNames();
278 while (loggers
.hasMoreElements()) {
279 loggerName
= loggers
.nextElement().toString();
280 /* Somehow there is always an empty string at the end. */
281 if (loggerName
== "") {
285 logger
= handler
.logManager
.getLogger(loggerName
);
286 logger
.removeHandler(handler
);
288 this.code
= lttng_jul_ret_code
.CODE_SUCCESS_CMD
;
292 logger
= handler
.logManager
.getLogger(name
.trim());
293 if (logger
== null) {
294 this.code
= lttng_jul_ret_code
.CODE_UNK_LOGGER_NAME
;
296 logger
.removeHandler(handler
);
297 this.code
= lttng_jul_ret_code
.CODE_SUCCESS_CMD
;
302 public class sessiond_list_logger
implements SessiondResponse
{
303 private final static int SIZE
= 12;
305 private int data_size
= 0;
306 private int nb_logger
= 0;
308 List
<String
> logger_list
= new ArrayList
<String
>();
310 /** Return status code to the session daemon. */
311 public lttng_jul_ret_code code
;
314 public byte[] getBytes() {
315 byte data
[] = new byte[SIZE
+ data_size
];
316 ByteBuffer buf
= ByteBuffer
.wrap(data
);
317 buf
.order(ByteOrder
.BIG_ENDIAN
);
320 buf
.putInt(code
.getCode());
321 buf
.putInt(data_size
);
322 buf
.putInt(nb_logger
);
324 for (String logger
: logger_list
) {
325 buf
.put(logger
.getBytes());
326 /* NULL terminated byte after the logger name. */
333 * Execute enable handler action which is to enable the given handler
334 * to the received name.
336 public void execute(LTTngLogHandler handler
) {
339 Enumeration loggers
= handler
.logManager
.getLoggerNames();
340 while (loggers
.hasMoreElements()) {
341 loggerName
= loggers
.nextElement().toString();
342 /* Somehow there is always an empty string at the end. */
343 if (loggerName
== "") {
347 this.logger_list
.add(loggerName
);
349 this.data_size
+= loggerName
.length() + 1;
352 this.code
= lttng_jul_ret_code
.CODE_SUCCESS_CMD
;
This page took 0.04156 seconds and 6 git commands to generate.