From 5c76231c94c9bbe2c4b707e7b63766d6c28452fa Mon Sep 17 00:00:00 2001 From: Alexandre Montplaisir Date: Fri, 12 Feb 2016 11:51:47 -0500 Subject: [PATCH] Fix: Correctly report filter notifications on Java agent teardown 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 Signed-off-by: Mathieu Desnoyers --- .../lttng/ust/agent/AbstractLttngAgent.java | 33 +++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/AbstractLttngAgent.java b/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/AbstractLttngAgent.java index 3c64e180..a5880364 100644 --- a/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/AbstractLttngAgent.java +++ b/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/AbstractLttngAgent.java @@ -199,11 +199,40 @@ public abstract class AbstractLttngAgent 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 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 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; -- 2.34.1