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
;
28 import java
.util
.List
;
30 import java
.util
.Enumeration
;
32 public interface LTTngSessiondCmd2_4
{
34 * Maximum name length for a logger name to be send to sessiond.
36 final static int NAME_MAX
= 255;
39 * Size of a primitive type int in byte. Because you know, Java can't
40 * provide that since it does not makes sense...
42 final static int INT_SIZE
= 4;
44 public interface SessiondResponse
{
46 * Gets a byte array of the command so that it may be streamed
48 * @return the byte array of the command
50 public byte[] getBytes();
53 public interface SessiondCommand
{
55 * Populate the class from a byte array
58 * the byte array containing the streamed command
60 public void populate(byte[] data
);
63 public enum lttng_jul_command
{
64 /** List logger(s). */
66 /** Enable logger by name. */
68 /** Disable logger by name. */
70 /** Registration done */
75 private lttng_jul_command(int c
) {
79 public int getCommand() {
84 enum lttng_jul_ret_code
{
87 CODE_UNK_LOGGER_NAME(3);
90 private lttng_jul_ret_code(int c
) {
94 public int getCode() {
99 public class sessiond_hdr
implements SessiondCommand
{
100 /** ABI size of command header. */
101 public final static int SIZE
= 16;
102 /** Payload size in bytes following this header. */
103 public long data_size
;
105 public lttng_jul_command cmd
;
106 /** Command version. */
107 public int cmd_version
;
109 public void populate(byte[] data
) {
110 ByteBuffer buf
= ByteBuffer
.wrap(data
);
111 buf
.order(ByteOrder
.BIG_ENDIAN
);
113 data_size
= buf
.getLong();
114 cmd
= lttng_jul_command
.values()[buf
.getInt() - 1];
115 cmd_version
= buf
.getInt();
119 public class sessiond_enable_handler
implements SessiondResponse
, SessiondCommand
{
120 private final static int SIZE
= 4;
122 public int lttngLogLevel
;
123 public int lttngLogLevelType
;
125 /** Return status code to the session daemon. */
126 public lttng_jul_ret_code code
;
129 public void populate(byte[] data
) {
130 int data_offset
= INT_SIZE
* 2;
132 ByteBuffer buf
= ByteBuffer
.wrap(data
);
133 buf
.order(ByteOrder
.LITTLE_ENDIAN
);
134 lttngLogLevel
= buf
.getInt();
135 lttngLogLevelType
= buf
.getInt();
136 name
= new String(data
, data_offset
, data
.length
- data_offset
);
140 public byte[] getBytes() {
141 byte data
[] = new byte[SIZE
];
142 ByteBuffer buf
= ByteBuffer
.wrap(data
);
143 buf
.order(ByteOrder
.BIG_ENDIAN
);
144 buf
.putInt(code
.getCode());
149 * Execute enable handler action which is to enable the given handler
150 * to the received name.
152 * @return Event name as a string if the event is NOT found thus was
155 public void execute(LTTngLogHandler handler
,
156 Map
<String
, ArrayList
<LTTngEvent
>> eventMap
, Set wildCardSet
) {
157 ArrayList
<LTTngEvent
> bucket
;
161 this.code
= lttng_jul_ret_code
.CODE_INVALID_CMD
;
165 /* Wild card to enable ALL logger. */
166 if (name
.trim().equals("*")) {
168 Enumeration loggers
= handler
.logManager
.getLoggerNames();
170 /* Add event to the wildcard set. */
171 wildCardSet
.add(new LTTngEvent(name
.trim(), lttngLogLevel
,
175 * Create an event for each logger found and attach it to the
178 while (loggers
.hasMoreElements()) {
179 loggerName
= loggers
.nextElement().toString();
180 /* Somehow there is always an empty string at the end. */
181 if (loggerName
== "") {
185 event
= new LTTngEvent(loggerName
, lttngLogLevel
,
187 /* Attach event to Log handler to it can be traced. */
188 handler
.attachEvent(event
);
191 * The agent timer call this function with eventMap set to
192 * null because it already has a reference to an existing
193 * event so is should not try to add a new one here.
195 if (eventMap
!= null) {
196 bucket
= eventMap
.get(loggerName
);
197 if (bucket
== null) {
198 bucket
= new ArrayList
<LTTngEvent
>();
199 eventMap
.put(loggerName
, bucket
);
205 event
= new LTTngEvent(name
.trim(), lttngLogLevel
,
207 /* Attach event to Log handler to it can be traced. */
208 handler
.attachEvent(event
);
211 * The agent timer call this function with eventMap set to
212 * null because it already has a reference to an existing
213 * event so is should not try to add a new one here.
215 if (eventMap
!= null) {
216 bucket
= eventMap
.get(name
.trim());
217 if (bucket
== null) {
218 bucket
= new ArrayList
<LTTngEvent
>();
219 eventMap
.put(name
.trim(), bucket
);
225 this.code
= lttng_jul_ret_code
.CODE_SUCCESS_CMD
;
230 public class sessiond_disable_handler
implements SessiondResponse
, SessiondCommand
{
231 private final static int SIZE
= 4;
233 public int lttngLogLevel
;
234 public int lttngLogLevelType
;
236 /** Return status code to the session daemon. */
237 public lttng_jul_ret_code code
;
240 public void populate(byte[] data
) {
241 int data_offset
= INT_SIZE
* 2;
243 ByteBuffer buf
= ByteBuffer
.wrap(data
);
244 buf
.order(ByteOrder
.LITTLE_ENDIAN
);
245 lttngLogLevel
= buf
.getInt();
246 lttngLogLevelType
= buf
.getInt();
247 name
= new String(data
, data_offset
, data
.length
- data_offset
);
251 public byte[] getBytes() {
252 byte data
[] = new byte[SIZE
];
253 ByteBuffer buf
= ByteBuffer
.wrap(data
);
254 buf
.order(ByteOrder
.BIG_ENDIAN
);
255 buf
.putInt(code
.getCode());
260 * Execute disable handler action which is to disable the given handler
261 * to the received name.
263 public void execute(LTTngLogHandler handler
,
264 Map
<String
, ArrayList
<LTTngEvent
>> eventMap
, Set wildCardSet
) {
265 ArrayList
<LTTngEvent
> bucket
;
269 this.code
= lttng_jul_ret_code
.CODE_INVALID_CMD
;
273 /* Wild card to disable ALL logger. */
274 if (name
.trim().equals("*")) {
276 Enumeration loggers
= handler
.logManager
.getLoggerNames();
278 /* Remove event from the wildcard set. */
279 wildCardSet
.remove(new LTTngEvent(name
.trim(), lttngLogLevel
,
282 while (loggers
.hasMoreElements()) {
283 loggerName
= loggers
.nextElement().toString();
284 /* Somehow there is always an empty string at the end. */
285 if (loggerName
== "") {
289 event
= new LTTngEvent(loggerName
, lttngLogLevel
,
292 bucket
= eventMap
.get(loggerName
);
293 if (bucket
!= null) {
294 handler
.detachEvent(event
);
295 bucket
.remove(event
);
296 if (bucket
.isEmpty() == true) {
297 eventMap
.remove(bucket
);
301 this.code
= lttng_jul_ret_code
.CODE_SUCCESS_CMD
;
303 event
= new LTTngEvent(this.name
, lttngLogLevel
,
306 bucket
= eventMap
.get(this.name
);
307 if (bucket
!= null) {
308 handler
.detachEvent(event
);
309 bucket
.remove(event
);
310 if (bucket
.isEmpty() == true) {
311 eventMap
.remove(bucket
);
313 this.code
= lttng_jul_ret_code
.CODE_SUCCESS_CMD
;
315 this.code
= lttng_jul_ret_code
.CODE_UNK_LOGGER_NAME
;
323 public class sessiond_list_logger
implements SessiondResponse
{
324 private final static int SIZE
= 12;
326 private int data_size
= 0;
327 private int nb_logger
= 0;
329 List
<String
> logger_list
= new ArrayList
<String
>();
331 /** Return status code to the session daemon. */
332 public lttng_jul_ret_code code
;
335 public byte[] getBytes() {
336 byte data
[] = new byte[SIZE
+ data_size
];
337 ByteBuffer buf
= ByteBuffer
.wrap(data
);
338 buf
.order(ByteOrder
.BIG_ENDIAN
);
341 buf
.putInt(code
.getCode());
342 buf
.putInt(data_size
);
343 buf
.putInt(nb_logger
);
345 for (String logger
: logger_list
) {
346 buf
.put(logger
.getBytes());
347 /* NULL terminated byte after the logger name. */
354 * Execute enable handler action which is to enable the given handler
355 * to the received name.
357 public void execute(LTTngLogHandler handler
) {
360 Enumeration loggers
= handler
.logManager
.getLoggerNames();
361 while (loggers
.hasMoreElements()) {
362 loggerName
= loggers
.nextElement().toString();
363 /* Somehow there is always an empty string at the end. */
364 if (loggerName
== "") {
368 this.logger_list
.add(loggerName
);
370 this.data_size
+= loggerName
.length() + 1;
373 this.code
= lttng_jul_ret_code
.CODE_SUCCESS_CMD
;
This page took 0.048189 seconds and 5 git commands to generate.