Fix: Correctly report filter notifications on Java agent teardown
[lttng-ust.git] / liblttng-ust-java-agent / java / lttng-ust-agent-common / org / lttng / ust / agent / AbstractLttngAgent.java
index 22c58265c0c8429e38fcac90bba73f0a45f03ca3..a58803640f79c15e931fd51ce23e39c31aca394d 100644 (file)
@@ -31,6 +31,7 @@ import org.lttng.ust.agent.client.ILttngTcpClientListener;
 import org.lttng.ust.agent.client.LttngTcpSessiondClient;
 import org.lttng.ust.agent.filter.FilterChangeNotifier;
 import org.lttng.ust.agent.session.EventRule;
+import org.lttng.ust.agent.utils.LttngUstAgentLogger;
 
 /**
  * Base implementation of a {@link ILttngAgent}.
@@ -148,6 +149,9 @@ public abstract class AbstractLttngAgent<T extends ILttngHandler>
                if (initialized) {
                        return;
                }
+
+               LttngUstAgentLogger.log(AbstractLttngAgent.class, "Initializing Agent for domain: " + domain.name());
+
                String rootClientThreadName = "Root sessiond client started by agent: " + this.getClass().getSimpleName();
 
                rootSessiondClient = new LttngTcpSessiondClient(this, getDomain().value(), true);
@@ -174,6 +178,8 @@ public abstract class AbstractLttngAgent<T extends ILttngHandler>
         * Dispose the agent
         */
        private void dispose() {
+               LttngUstAgentLogger.log(AbstractLttngAgent.class, "Disposing Agent for domain: " + domain.name());
+
                /*
                 * Only called from a synchronized (registeredHandlers) block, should
                 * not need additional synchronization.
@@ -193,10 +199,41 @@ public abstract class AbstractLttngAgent<T extends ILttngHandler>
                userSessiondClient = null;
                userSessiondClientThread = null;
 
-               /* Reset all enabled event counts to 0 */
+               /*
+                * Send filter change notifications for all event rules currently
+                * active, then clear them.
+                */
+               FilterChangeNotifier fcn = FilterChangeNotifier.getInstance();
+
+               for (Map.Entry<String, Integer> entry : enabledEvents.entrySet()) {
+                       String eventName = entry.getKey();
+                       Integer nb = entry.getValue();
+                       for (int i = 0; i < nb.intValue(); i++) {
+                               fcn.removeEventRules(eventName);
+                       }
+               }
                enabledEvents.clear();
+
+               for (Map.Entry<String, Integer> entry : enabledEventPrefixes.entrySet()) {
+                       /* Re-add the * at the end, the FCN tracks the rules that way */
+                       String eventName = (entry.getKey() + "*");
+                       Integer nb = entry.getValue();
+                       for (int i = 0; i < nb.intValue(); i++) {
+                               fcn.removeEventRules(eventName);
+                       }
+               }
                enabledEventPrefixes.clear();
-               enabledWildcards.set(0);
+
+               int wildcardRules = enabledWildcards.getAndSet(0);
+               for (int i = 0; i < wildcardRules; i++) {
+                       fcn.removeEventRules(WILDCARD);
+               }
+
+               /*
+                * Also clear tracked app contexts (no filter notifications sent for
+                * those currently).
+                */
+               enabledAppContexts.clear();
 
                initialized = false;
        }
This page took 0.024202 seconds and 4 git commands to generate.