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 * Execute enable handler action which is to enable the given handler
145 * to the received name.
147 * @return Event name as a string if the event is NOT found thus was
150 public String
execute(LTTngLogHandler handler
, HashMap enabledLoggers
) {
154 this.code
= lttng_jul_ret_code
.CODE_INVALID_CMD
;
158 /* Wild card to enable ALL logger. */
159 if (name
.trim().equals("*")) {
161 Enumeration loggers
= handler
.logManager
.getLoggerNames();
162 while (loggers
.hasMoreElements()) {
163 loggerName
= loggers
.nextElement().toString();
164 /* Somehow there is always an empty string at the end. */
165 if (loggerName
== "") {
169 if (enabledLoggers
.get(loggerName
) != null) {
173 logger
= handler
.logManager
.getLogger(loggerName
);
174 handler
.setLogLevel(loggerName
, lttngLogLevel
,
176 logger
.addHandler(handler
);
177 enabledLoggers
.put(loggerName
, logger
);
179 this.code
= lttng_jul_ret_code
.CODE_SUCCESS_CMD
;
181 * Return the name as a new string so we can add the * event
182 * name to the event list that we need to enable for new
185 return new String(name
);
188 this.code
= lttng_jul_ret_code
.CODE_SUCCESS_CMD
;
189 logger
= handler
.logManager
.getLogger(name
.trim());
190 if (logger
!= null) {
191 handler
.setLogLevel(name
.trim(), lttngLogLevel
,
193 logger
.addHandler(handler
);
194 enabledLoggers
.put(name
.trim(), logger
);
197 return new String(name
);
202 public class sessiond_disable_handler
implements SessiondResponse
, SessiondCommand
{
203 private final static int SIZE
= 4;
206 /** Return status code to the session daemon. */
207 public lttng_jul_ret_code code
;
210 public void populate(byte[] data
) {
211 ByteBuffer buf
= ByteBuffer
.wrap(data
);
212 buf
.order(ByteOrder
.BIG_ENDIAN
);
213 name
= new String(data
, 0, data
.length
);
217 public byte[] getBytes() {
218 byte data
[] = new byte[SIZE
];
219 ByteBuffer buf
= ByteBuffer
.wrap(data
);
220 buf
.order(ByteOrder
.BIG_ENDIAN
);
221 buf
.putInt(code
.getCode());
226 * Execute disable handler action which is to disable the given handler
227 * to the received name.
229 public void execute(LTTngLogHandler handler
) {
233 this.code
= lttng_jul_ret_code
.CODE_INVALID_CMD
;
237 /* Wild card to disable ALL logger. */
238 if (name
.trim().equals("*")) {
240 Enumeration loggers
= handler
.logManager
.getLoggerNames();
241 while (loggers
.hasMoreElements()) {
242 loggerName
= loggers
.nextElement().toString();
243 /* Somehow there is always an empty string at the end. */
244 if (loggerName
== "") {
248 logger
= handler
.logManager
.getLogger(loggerName
);
249 logger
.removeHandler(handler
);
251 this.code
= lttng_jul_ret_code
.CODE_SUCCESS_CMD
;
255 logger
= handler
.logManager
.getLogger(name
.trim());
256 if (logger
== null) {
257 this.code
= lttng_jul_ret_code
.CODE_UNK_LOGGER_NAME
;
259 logger
.removeHandler(handler
);
260 this.code
= lttng_jul_ret_code
.CODE_SUCCESS_CMD
;
265 public class sessiond_list_logger
implements SessiondResponse
{
266 private final static int SIZE
= 12;
268 private int data_size
= 0;
269 private int nb_logger
= 0;
271 List
<String
> logger_list
= new ArrayList
<String
>();
273 /** Return status code to the session daemon. */
274 public lttng_jul_ret_code code
;
277 public byte[] getBytes() {
278 byte data
[] = new byte[SIZE
+ data_size
];
279 ByteBuffer buf
= ByteBuffer
.wrap(data
);
280 buf
.order(ByteOrder
.BIG_ENDIAN
);
283 buf
.putInt(code
.getCode());
284 buf
.putInt(data_size
);
285 buf
.putInt(nb_logger
);
287 for (String logger
: logger_list
) {
288 buf
.put(logger
.getBytes());
289 /* NULL terminated byte after the logger name. */
296 * Execute enable handler action which is to enable the given handler
297 * to the received name.
299 public void execute(LTTngLogHandler handler
) {
302 Enumeration loggers
= handler
.logManager
.getLoggerNames();
303 while (loggers
.hasMoreElements()) {
304 loggerName
= loggers
.nextElement().toString();
305 /* Somehow there is always an empty string at the end. */
306 if (loggerName
== "") {
310 this.logger_list
.add(loggerName
);
312 this.data_size
+= loggerName
.length() + 1;
315 this.code
= lttng_jul_ret_code
.CODE_SUCCESS_CMD
;
This page took 0.035444 seconds and 4 git commands to generate.