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
.List
;
27 import java
.util
.Enumeration
;
29 public interface LTTngSessiondCmd2_4
{
31 * Maximum name length for a logger name to be send to sessiond.
33 final static int NAME_MAX
= 255;
36 * Size of a primitive type int in byte. Because you know, Java can't
37 * provide that since it does not makes sense...
39 final static int INT_SIZE
= 4;
41 public interface SessiondResponse
{
43 * Gets a byte array of the command so that it may be streamed
45 * @return the byte array of the command
47 public byte[] getBytes();
50 public interface SessiondCommand
{
52 * Populate the class from a byte array
55 * the byte array containing the streamed command
57 public void populate(byte[] data
);
60 public enum lttng_jul_command
{
61 /** List logger(s). */
63 /** Enable logger by name. */
65 /** Disable logger by name. */
67 /** Registration done */
72 private lttng_jul_command(int c
) {
76 public int getCommand() {
81 enum lttng_jul_ret_code
{
84 CODE_UNK_LOGGER_NAME(3);
87 private lttng_jul_ret_code(int c
) {
91 public int getCode() {
96 public class sessiond_hdr
implements SessiondCommand
{
97 /** ABI size of command header. */
98 public final static int SIZE
= 16;
99 /** Payload size in bytes following this header. */
100 public long data_size
;
102 public lttng_jul_command cmd
;
103 /** Command version. */
104 public int cmd_version
;
106 public void populate(byte[] data
) {
107 ByteBuffer buf
= ByteBuffer
.wrap(data
);
108 buf
.order(ByteOrder
.BIG_ENDIAN
);
110 data_size
= buf
.getLong();
111 cmd
= lttng_jul_command
.values()[buf
.getInt() - 1];
112 cmd_version
= buf
.getInt();
116 public class sessiond_enable_handler
implements SessiondResponse
, SessiondCommand
{
117 private final static int SIZE
= 4;
119 public int lttngLogLevel
;
120 public int lttngLogLevelType
;
122 /** Return status code to the session daemon. */
123 public lttng_jul_ret_code code
;
126 public void populate(byte[] data
) {
127 int data_offset
= INT_SIZE
* 2;
129 ByteBuffer buf
= ByteBuffer
.wrap(data
);
130 buf
.order(ByteOrder
.LITTLE_ENDIAN
);
131 lttngLogLevel
= buf
.getInt();
132 lttngLogLevelType
= buf
.getInt();
133 name
= new String(data
, data_offset
, data
.length
- data_offset
).trim();
137 public byte[] getBytes() {
138 byte data
[] = new byte[SIZE
];
139 ByteBuffer buf
= ByteBuffer
.wrap(data
);
140 buf
.order(ByteOrder
.BIG_ENDIAN
);
141 buf
.putInt(code
.getCode());
146 * Execute enable handler action which is to enable the given handler
147 * to the received name.
149 * @return Event name as a string if the event is NOT found thus was
152 public void execute(LTTngLogHandler handler
) {
155 if (this.name
== null) {
156 this.code
= lttng_jul_ret_code
.CODE_INVALID_CMD
;
160 /* Add event to the enabled events hash map. */
161 event
= handler
.enabledEvents
.put(this.name
,
162 new LTTngEvent(this.name
, 0, 0));
164 /* The event exists so skip updating the refcount. */
165 this.code
= lttng_jul_ret_code
.CODE_SUCCESS_CMD
;
170 * Get the root logger and attach to it if it's the first enable
171 * seen by the handler.
173 Logger rootLogger
= handler
.logManager
.getLogger("");
176 if (handler
.refcount
== 1) {
177 /* Add handler only if it's the first enable. */
178 rootLogger
.addHandler(handler
);
181 this.code
= lttng_jul_ret_code
.CODE_SUCCESS_CMD
;
186 public class sessiond_disable_handler
implements SessiondResponse
, SessiondCommand
{
187 private final static int SIZE
= 4;
189 public int lttngLogLevel
;
190 public int lttngLogLevelType
;
192 /** Return status code to the session daemon. */
193 public lttng_jul_ret_code code
;
196 public void populate(byte[] data
) {
197 ByteBuffer buf
= ByteBuffer
.wrap(data
);
198 buf
.order(ByteOrder
.LITTLE_ENDIAN
);
199 name
= new String(data
).trim();
203 public byte[] getBytes() {
204 byte data
[] = new byte[SIZE
];
205 ByteBuffer buf
= ByteBuffer
.wrap(data
);
206 buf
.order(ByteOrder
.BIG_ENDIAN
);
207 buf
.putInt(code
.getCode());
212 * Execute disable handler action which is to disable the given handler
213 * to the received name.
215 public void execute(LTTngLogHandler handler
) {
218 if (this.name
== null) {
219 this.code
= lttng_jul_ret_code
.CODE_INVALID_CMD
;
224 * Try to remove the logger name from the events map and if we
225 * can't, just skip the refcount update since the event was never
228 event
= handler
.enabledEvents
.remove(this.name
);
230 /* The event didn't exists so skip updating the refcount. */
231 this.code
= lttng_jul_ret_code
.CODE_INVALID_CMD
;
235 Logger rootLogger
= handler
.logManager
.getLogger("");
238 if (handler
.refcount
== 0) {
239 rootLogger
.removeHandler(handler
);
242 this.code
= lttng_jul_ret_code
.CODE_SUCCESS_CMD
;
247 public class sessiond_list_logger
implements SessiondResponse
{
248 private final static int SIZE
= 12;
250 private int data_size
= 0;
251 private int nb_logger
= 0;
253 List
<String
> logger_list
= new ArrayList
<String
>();
255 /** Return status code to the session daemon. */
256 public lttng_jul_ret_code code
;
259 public byte[] getBytes() {
260 byte data
[] = new byte[SIZE
+ data_size
];
261 ByteBuffer buf
= ByteBuffer
.wrap(data
);
262 buf
.order(ByteOrder
.BIG_ENDIAN
);
265 buf
.putInt(code
.getCode());
266 buf
.putInt(data_size
);
267 buf
.putInt(nb_logger
);
269 for (String logger
: logger_list
) {
270 buf
.put(logger
.getBytes());
271 /* NULL terminated byte after the logger name. */
278 * Execute enable handler action which is to enable the given handler
279 * to the received name.
281 public void execute(LTTngLogHandler handler
) {
284 Enumeration loggers
= handler
.logManager
.getLoggerNames();
285 while (loggers
.hasMoreElements()) {
286 loggerName
= loggers
.nextElement().toString();
287 /* Somehow there is always an empty string at the end. */
288 if (loggerName
== "") {
292 this.logger_list
.add(loggerName
);
294 this.data_size
+= loggerName
.length() + 1;
297 this.code
= lttng_jul_ret_code
.CODE_SUCCESS_CMD
;
This page took 0.03774 seconds and 5 git commands to generate.