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>
userSessiondClient = null;
userSessiondClientThread = null;
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);
+ }
+ }
+
+ 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();
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;
enabledAppContexts.clear();
initialized = false;