Add filter notifications and TCP client tests
[lttng-ust-java-tests.git] / lttng-ust-java-tests / src / test / java / org / lttng / ust / agent / integration / client / TcpClientDebugListener.java
diff --git a/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/client/TcpClientDebugListener.java b/lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/client/TcpClientDebugListener.java
new file mode 100644 (file)
index 0000000..e2ec3d8
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) 2015, EfficiOS Inc., Alexandre Montplaisir <alexmonthy@efficios.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+package org.lttng.ust.agent.integration.client;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.lttng.ust.agent.client.ILttngTcpClientListener;
+import org.lttng.ust.agent.session.EventRule;
+
+/**
+ * TCP client listener used for test. Instead of "handling" commands, it just
+ * keep tracks of commands it receives.
+ *
+ * @author Alexandre Montplaisir
+ */
+public class TcpClientDebugListener implements ILttngTcpClientListener {
+
+    private final List<EventRule> enabledEventCommands = Collections.synchronizedList(new ArrayList<>());
+    private final List<String> disabledEventCommands = Collections.synchronizedList(new ArrayList<>());
+
+    @Override
+    public boolean eventEnabled(EventRule rule) {
+        enabledEventCommands.add(rule);
+        return true;
+    }
+
+    @Override
+    public boolean eventDisabled(String name) {
+        disabledEventCommands.add(name);
+        return true;
+    }
+
+    /**
+     * Not yet implemented
+     */
+    @Override
+    public Iterable<String> listEnabledEvents() {
+        // TODO NYI
+        return Collections.EMPTY_LIST;
+    }
+
+    /**
+     * @return The "enable-event" commands that were received, since
+     *         instantiation or the last {@link #clearAllCommands}.
+     */
+    public List<EventRule> getEnabledEventCommands() {
+        synchronized (enabledEventCommands) {
+            return new ArrayList<>(enabledEventCommands);
+        }
+    }
+
+    /**
+     * @return The "disable-event" commands that were received, since
+     *         instantiation or the last {@link #clearAllCommands}.
+     */
+    public List<String> getDisabledEventCommands() {
+        synchronized (disabledEventCommands) {
+            return new ArrayList<>(disabledEventCommands);
+        }
+    }
+
+    /**
+     * Clear all tracked data.
+     */
+    public void clearAllCommands() {
+        enabledEventCommands.clear();
+        disabledEventCommands.clear();
+    }
+
+}
This page took 0.02355 seconds and 4 git commands to generate.