4b893e0b596662a3ebfd2523fa6acd0577b1039d
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
.util
.logging
.Logger
;
24 import java
.util
.ArrayList
;
25 import java
.util
.List
;
26 import java
.util
.Enumeration
;
28 public interface LTTngSessiondCmd2_4
{
30 * Maximum name length for a logger name to be send to sessiond.
32 final static int NAME_MAX
= 255;
34 public interface SessiondResponse
{
36 * Gets a byte array of the command so that it may be streamed
38 * @return the byte array of the command
40 public byte[] getBytes();
43 public interface SessiondCommand
{
45 * Populate the class from a byte array
48 * the byte array containing the streamed command
50 public void populate(byte[] data
);
53 public enum lttng_jul_command
{
54 /** List logger(s). */
56 /** Enable logger by name. */
58 /** Disable logger by name. */
62 private lttng_jul_command(int c
) {
66 public int getCommand() {
71 enum lttng_jul_ret_code
{
74 CODE_UNK_LOGGER_NAME(3);
77 private lttng_jul_ret_code(int c
) {
81 public int getCode() {
86 public class sessiond_hdr
implements SessiondCommand
{
87 /** ABI size of command header. */
88 public final static int SIZE
= 16;
89 /** Payload size in bytes following this header. */
90 public long data_size
;
92 public lttng_jul_command cmd
;
93 /** Command version. */
94 public int cmd_version
;
96 public void populate(byte[] data
) {
97 ByteBuffer buf
= ByteBuffer
.wrap(data
);
98 buf
.order(ByteOrder
.BIG_ENDIAN
);
100 data_size
= buf
.getLong();
101 cmd
= lttng_jul_command
.values()[buf
.getInt() - 1];
102 cmd_version
= buf
.getInt();
106 public class sessiond_enable_handler
implements SessiondResponse
, SessiondCommand
{
107 private final static int SIZE
= 4;
110 /** Return status code to the session daemon. */
111 public lttng_jul_ret_code code
;
114 public void populate(byte[] data
) {
115 ByteBuffer buf
= ByteBuffer
.wrap(data
);
116 buf
.order(ByteOrder
.LITTLE_ENDIAN
);
117 name
= new String(data
, 0, data
.length
);
121 public byte[] getBytes() {
122 byte data
[] = new byte[SIZE
];
123 ByteBuffer buf
= ByteBuffer
.wrap(data
);
124 buf
.order(ByteOrder
.BIG_ENDIAN
);
125 buf
.putInt(code
.getCode());
130 * Execute enable handler action which is to enable the given handler
131 * to the received name.
133 * @return Event name as a string if the event is NOT found thus was
136 public String
execute(LTTngLogHandler handler
) {
140 this.code
= lttng_jul_ret_code
.CODE_INVALID_CMD
;
144 /* Wild card to enable ALL logger. */
145 if (name
.trim().equals("*")) {
147 Enumeration loggers
= handler
.logManager
.getLoggerNames();
148 while (loggers
.hasMoreElements()) {
149 loggerName
= loggers
.nextElement().toString();
150 /* Somehow there is always an empty string at the end. */
151 if (loggerName
== "") {
155 logger
= handler
.logManager
.getLogger(loggerName
);
156 logger
.addHandler(handler
);
158 this.code
= lttng_jul_ret_code
.CODE_SUCCESS_CMD
;
162 this.code
= lttng_jul_ret_code
.CODE_SUCCESS_CMD
;
163 logger
= handler
.logManager
.getLogger(name
.trim());
164 if (logger
!= null) {
165 logger
.addHandler(handler
);
168 return new String(name
);
173 public class sessiond_disable_handler
implements SessiondResponse
, SessiondCommand
{
174 private final static int SIZE
= 4;
177 /** Return status code to the session daemon. */
178 public lttng_jul_ret_code code
;
181 public void populate(byte[] data
) {
182 ByteBuffer buf
= ByteBuffer
.wrap(data
);
183 buf
.order(ByteOrder
.BIG_ENDIAN
);
184 name
= new String(data
, 0, data
.length
);
188 public byte[] getBytes() {
189 byte data
[] = new byte[SIZE
];
190 ByteBuffer buf
= ByteBuffer
.wrap(data
);
191 buf
.order(ByteOrder
.BIG_ENDIAN
);
192 buf
.putInt(code
.getCode());
197 * Execute disable handler action which is to disable the given handler
198 * to the received name.
200 public void execute(LTTngLogHandler handler
) {
204 this.code
= lttng_jul_ret_code
.CODE_INVALID_CMD
;
208 /* Wild card to disable ALL logger. */
209 if (name
.trim().equals("*")) {
211 Enumeration loggers
= handler
.logManager
.getLoggerNames();
212 while (loggers
.hasMoreElements()) {
213 loggerName
= loggers
.nextElement().toString();
214 /* Somehow there is always an empty string at the end. */
215 if (loggerName
== "") {
219 logger
= handler
.logManager
.getLogger(loggerName
);
220 logger
.removeHandler(handler
);
222 this.code
= lttng_jul_ret_code
.CODE_SUCCESS_CMD
;
226 logger
= handler
.logManager
.getLogger(name
.trim());
227 if (logger
== null) {
228 this.code
= lttng_jul_ret_code
.CODE_UNK_LOGGER_NAME
;
230 logger
.removeHandler(handler
);
231 this.code
= lttng_jul_ret_code
.CODE_SUCCESS_CMD
;
236 public class sessiond_list_logger
implements SessiondResponse
{
237 private final static int SIZE
= 12;
239 private int data_size
= 0;
240 private int nb_logger
= 0;
242 List
<String
> logger_list
= new ArrayList
<String
>();
244 /** Return status code to the session daemon. */
245 public lttng_jul_ret_code code
;
248 public byte[] getBytes() {
249 byte data
[] = new byte[SIZE
+ data_size
];
250 ByteBuffer buf
= ByteBuffer
.wrap(data
);
251 buf
.order(ByteOrder
.BIG_ENDIAN
);
254 buf
.putInt(code
.getCode());
255 buf
.putInt(data_size
);
256 buf
.putInt(nb_logger
);
258 for (String logger
: logger_list
) {
259 buf
.put(logger
.getBytes());
260 /* NULL terminated byte after the logger name. */
267 * Execute enable handler action which is to enable the given handler
268 * to the received name.
270 public void execute(LTTngLogHandler handler
) {
273 Enumeration loggers
= handler
.logManager
.getLoggerNames();
274 while (loggers
.hasMoreElements()) {
275 loggerName
= loggers
.nextElement().toString();
276 /* Somehow there is always an empty string at the end. */
277 if (loggerName
== "") {
281 this.logger_list
.add(loggerName
);
283 this.data_size
+= loggerName
.length() + 1;
286 this.code
= lttng_jul_ret_code
.CODE_SUCCESS_CMD
;
This page took 0.03579 seconds and 4 git commands to generate.