import java.nio.ByteOrder;
import java.util.logging.Logger;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
import java.util.Enumeration;
* @return Event name as a string if the event is NOT found thus was
* not enabled.
*/
- public String execute(LTTngLogHandler handler) {
+ public String execute(LTTngLogHandler handler, HashMap enabledLoggers) {
Logger logger;
if (name == null) {
continue;
}
+ if (enabledLoggers.get(loggerName) != null) {
+ continue;
+ }
+
logger = handler.logManager.getLogger(loggerName);
logger.addHandler(handler);
+ enabledLoggers.put(loggerName, logger);
}
this.code = lttng_jul_ret_code.CODE_SUCCESS_CMD;
- return null;
+ /*
+ * Return the name as a new string so we can add the * event
+ * name to the event list that we need to enable for new
+ * Logger.
+ */
+ return new String(name);
}
this.code = lttng_jul_ret_code.CODE_SUCCESS_CMD;
logger = handler.logManager.getLogger(name.trim());
if (logger != null) {
logger.addHandler(handler);
+ enabledLoggers.put(name.trim(), logger);
return null;
} else {
return new String(name);
import java.net.*;
import java.lang.management.ManagementFactory;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
+import java.util.logging.Logger;
class USTRegisterMsg {
public static int pid;
private Timer eventTimer;
private List<String> enabledEventList = new ArrayList<String>();
+ /*
+ * Map of Logger objects that have been enabled. They are indexed by name.
+ */
+ private HashMap<String, Logger> enabledLoggers = new HashMap<String, Logger>();
/* Timer delay at each 5 seconds. */
private final static long timerDelay = 5 * 1000;
private static boolean timerInitialized;
LTTngSessiondCmd2_4.sessiond_enable_handler enableCmd = new
LTTngSessiondCmd2_4.sessiond_enable_handler();
for (String strEventName: tmpList) {
+ /*
+ * Check if this Logger name has been enabled already. Note
+ * that in the case of "*", it's never added in that hash
+ * table thus the enable command does a lookup for each
+ * logger name in that hash table for the * case in order
+ * to make sure we don't enable twice the same logger
+ * because JUL apparently accepts that the *same*
+ * LogHandler can be added twice on a Logger object...
+ * don't ask...
+ */
+ if (enabledLoggers.get(strEventName) != null) {
+ continue;
+ }
+
enableCmd.name = strEventName;
- if (enableCmd.execute(handler) == null) {
+ if (enableCmd.execute(handler, enabledLoggers) == null) {
enabledEventList.remove(strEventName);
}
}
break;
}
enableCmd.populate(data);
- event_name = enableCmd.execute(this.handler);
+ event_name = enableCmd.execute(this.handler, this.enabledLoggers);
if (event_name != null) {
/*
* Add the event to the list so it can be enabled if
* the logger appears at some point in time.
*/
- enabledEventList.add(event_name);
+ if (enabledEventList.contains(event_name) == false) {
+ enabledEventList.add(event_name);
+ }
}
data = enableCmd.getBytes();
break;