import java.nio.ByteBuffer;
import java.nio.ByteOrder;
+import java.lang.Object;
import java.util.logging.Logger;
import java.util.ArrayList;
import java.util.List;
*/
final static int NAME_MAX = 255;
+ /*
+ * Size of a primitive type int in byte. Because you know, Java can't
+ * provide that since it does not makes sense...
+ */
+ final static int INT_SIZE = 4;
+
public interface SessiondResponse {
/**
* Gets a byte array of the command so that it may be streamed
/** Enable logger by name. */
CMD_ENABLE(2),
/** Disable logger by name. */
- CMD_DISABLE(3);
+ CMD_DISABLE(3),
+ /** Registration done */
+ CMD_REG_DONE(4);
+
private int code;
private lttng_jul_command(int c) {
public class sessiond_enable_handler implements SessiondResponse, SessiondCommand {
private final static int SIZE = 4;
public String name;
+ public int lttngLogLevel;
+ public int lttngLogLevelType;
/** Return status code to the session daemon. */
public lttng_jul_ret_code code;
@Override
public void populate(byte[] data) {
+ int data_offset = INT_SIZE * 2;
+
ByteBuffer buf = ByteBuffer.wrap(data);
buf.order(ByteOrder.LITTLE_ENDIAN);
- name = new String(data, 0, data.length);
+ lttngLogLevel = buf.getInt();
+ lttngLogLevelType = buf.getInt();
+ name = new String(data, data_offset, data.length - data_offset).trim();
}
@Override
* @return Event name as a string if the event is NOT found thus was
* not enabled.
*/
- public String execute(LTTngLogHandler handler) {
- Logger logger;
+ public void execute(LTTngLogHandler handler) {
+ LTTngEvent event;
- if (name == null) {
+ if (this.name == null) {
this.code = lttng_jul_ret_code.CODE_INVALID_CMD;
- return null;
+ return;
}
- /* Wild card to enable ALL logger. */
- if (name.trim().equals("*")) {
- String loggerName;
- Enumeration loggers = handler.logManager.getLoggerNames();
- while (loggers.hasMoreElements()) {
- loggerName = loggers.nextElement().toString();
- /* Somehow there is always an empty string at the end. */
- if (loggerName == "") {
- continue;
- }
-
- logger = handler.logManager.getLogger(loggerName);
- logger.addHandler(handler);
- }
+ /* Add event to the enabled events hash map. */
+ event = handler.enabledEvents.put(this.name,
+ new LTTngEvent(this.name, 0, 0));
+ if (event != null) {
+ /* The event exists so skip updating the refcount. */
this.code = lttng_jul_ret_code.CODE_SUCCESS_CMD;
- return null;
+ return;
}
- this.code = lttng_jul_ret_code.CODE_SUCCESS_CMD;
- logger = handler.logManager.getLogger(name.trim());
- if (logger != null) {
- logger.addHandler(handler);
- return null;
- } else {
- return new String(name);
+ /*
+ * Get the root logger and attach to it if it's the first enable
+ * seen by the handler.
+ */
+ Logger rootLogger = handler.logManager.getLogger("");
+
+ handler.refcount++;
+ if (handler.refcount == 1) {
+ /* Add handler only if it's the first enable. */
+ rootLogger.addHandler(handler);
}
+
+ this.code = lttng_jul_ret_code.CODE_SUCCESS_CMD;
+ return;
}
}
public class sessiond_disable_handler implements SessiondResponse, SessiondCommand {
private final static int SIZE = 4;
public String name;
+ public int lttngLogLevel;
+ public int lttngLogLevelType;
/** Return status code to the session daemon. */
public lttng_jul_ret_code code;
@Override
public void populate(byte[] data) {
ByteBuffer buf = ByteBuffer.wrap(data);
- buf.order(ByteOrder.BIG_ENDIAN);
- name = new String(data, 0, data.length);
+ buf.order(ByteOrder.LITTLE_ENDIAN);
+ name = new String(data).trim();
}
@Override
* to the received name.
*/
public void execute(LTTngLogHandler handler) {
- Logger logger;
+ LTTngEvent event;
- if (name == null) {
+ if (this.name == null) {
this.code = lttng_jul_ret_code.CODE_INVALID_CMD;
return;
}
- /* Wild card to disable ALL logger. */
- if (name.trim().equals("*")) {
- String loggerName;
- Enumeration loggers = handler.logManager.getLoggerNames();
- while (loggers.hasMoreElements()) {
- loggerName = loggers.nextElement().toString();
- /* Somehow there is always an empty string at the end. */
- if (loggerName == "") {
- continue;
- }
-
- logger = handler.logManager.getLogger(loggerName);
- logger.removeHandler(handler);
- }
- this.code = lttng_jul_ret_code.CODE_SUCCESS_CMD;
+ /*
+ * Try to remove the logger name from the events map and if we
+ * can't, just skip the refcount update since the event was never
+ * enabled.
+ */
+ event = handler.enabledEvents.remove(this.name);
+ if (event == null) {
+ /* The event didn't exists so skip updating the refcount. */
+ this.code = lttng_jul_ret_code.CODE_INVALID_CMD;
return;
}
- logger = handler.logManager.getLogger(name.trim());
- if (logger == null) {
- this.code = lttng_jul_ret_code.CODE_UNK_LOGGER_NAME;
- } else {
- logger.removeHandler(handler);
- this.code = lttng_jul_ret_code.CODE_SUCCESS_CMD;
+ Logger rootLogger = handler.logManager.getLogger("");
+
+ handler.refcount--;
+ if (handler.refcount == 0) {
+ rootLogger.removeHandler(handler);
}
+
+ this.code = lttng_jul_ret_code.CODE_SUCCESS_CMD;
+ return;
}
}