Fix: Correctly report filter notifications on Java agent teardown
authorAlexandre Montplaisir <alexmonthy@efficios.com>
Fri, 12 Feb 2016 16:51:47 +0000 (11:51 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 12 Feb 2016 22:54:29 +0000 (17:54 -0500)
If a Java agent gets disposed, it should not just clear() all its
tracked event rules: it should first send corresponding filter change
notifications indicating that these rules are not tracked anymore.

This fixes a problem where if event rules were still enabled on agent
tear down, the filter notifier's own tracked events would become out
of sync.

Signed-off-by: Alexandre Montplaisir <alexmonthy@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/AbstractLttngAgent.java

index 3c64e180a6474bd30e94d2e07db253b3e2db0364..a58803640f79c15e931fd51ce23e39c31aca394d 100644 (file)
@@ -199,11 +199,40 @@ 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.025897 seconds and 4 git commands to generate.