JUL: fix enable all event for delayed Logger
authorDavid Goulet <dgoulet@efficios.com>
Wed, 20 Nov 2013 16:35:35 +0000 (11:35 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 20 Nov 2013 21:41:18 +0000 (16:41 -0500)
This adds a HashMap containing the enabled Logger names (and wildcard
'*'). This is used to make sure we don't enable twice the same Logger
for the '*' event name (enable all -a).

Signed-off-by: David Goulet <dgoulet@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
liblttng-ust-jul/org/lttng/ust/jul/LTTngSessiondCmd2_4.java
liblttng-ust-jul/org/lttng/ust/jul/LTTngTCPSessiondClient.java

index 4b893e0b596662a3ebfd2523fa6acd0577b1039d..eab7e5d9c1752dce3b35e36da48c7c67f07214af 100644 (file)
@@ -22,6 +22,7 @@ import java.nio.ByteBuffer;
 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;
 
@@ -133,7 +134,7 @@ public interface LTTngSessiondCmd2_4 {
                 * @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) {
@@ -152,17 +153,28 @@ public interface LTTngSessiondCmd2_4 {
                                                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);
index b89deb818c4702514d86842570abf9a9aac16dcd..0c2cb48f1b92e3eb8c590b6debf67648cee7ad71 100644 (file)
@@ -29,9 +29,11 @@ import java.io.DataInputStream;
 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;
@@ -56,6 +58,10 @@ public class LTTngTCPSessiondClient {
 
        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;
@@ -85,8 +91,22 @@ public class LTTngTCPSessiondClient {
                                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);
                                        }
                                }
@@ -220,13 +240,15 @@ public class LTTngTCPSessiondClient {
                                                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;
This page took 0.02774 seconds and 4 git commands to generate.