Commit | Line | Data |
---|---|---|
f37120c3 AM |
1 | /* |
2 | * Copyright (C) 2015, EfficiOS Inc., Alexandre Montplaisir <alexmonthy@efficios.com> | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or modify | |
5 | * it under the terms of the GNU General Public License as published by | |
6 | * the Free Software Foundation; either version 2 of the License, or | |
7 | * (at your option) any later version. | |
8 | * | |
9 | * This program is distributed in the hope that it will be useful, | |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | * GNU General Public License for more details. | |
13 | * | |
14 | * You should have received a copy of the GNU General Public License along | |
15 | * with this program; if not, write to the Free Software Foundation, Inc., | |
16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
17 | */ | |
18 | ||
19 | package org.lttng.ust.agent.integration.client; | |
20 | ||
21 | import java.util.ArrayList; | |
22 | import java.util.Collections; | |
23 | import java.util.List; | |
24 | ||
25 | import org.lttng.ust.agent.client.ILttngTcpClientListener; | |
26 | import org.lttng.ust.agent.session.EventRule; | |
27 | ||
28 | /** | |
29 | * TCP client listener used for test. Instead of "handling" commands, it just | |
30 | * keep tracks of commands it receives. | |
31 | * | |
32 | * @author Alexandre Montplaisir | |
33 | */ | |
34 | public class TcpClientDebugListener implements ILttngTcpClientListener { | |
35 | ||
36 | private final List<EventRule> enabledEventCommands = Collections.synchronizedList(new ArrayList<>()); | |
37 | private final List<String> disabledEventCommands = Collections.synchronizedList(new ArrayList<>()); | |
38 | ||
73fb6785 AM |
39 | private final List<String> enabledAppContextCommands = Collections.synchronizedList(new ArrayList<>()); |
40 | private final List<String> disabledAppContextCommands = Collections.synchronizedList(new ArrayList<>()); | |
41 | ||
f37120c3 AM |
42 | @Override |
43 | public boolean eventEnabled(EventRule rule) { | |
44 | enabledEventCommands.add(rule); | |
45 | return true; | |
46 | } | |
47 | ||
48 | @Override | |
49 | public boolean eventDisabled(String name) { | |
50 | disabledEventCommands.add(name); | |
51 | return true; | |
52 | } | |
53 | ||
419da12d | 54 | @Override |
73fb6785 AM |
55 | public boolean appContextEnabled(String contextRetrieverName, String contextName) { |
56 | enabledAppContextCommands.add(contextRetrieverName + ':' + contextName); | |
57 | return true; | |
419da12d AM |
58 | } |
59 | ||
60 | @Override | |
73fb6785 AM |
61 | public boolean appContextDisabled(String contextRetrieverName, String contextName) { |
62 | disabledAppContextCommands.add(contextRetrieverName + ':' + contextName); | |
63 | return true; | |
419da12d AM |
64 | } |
65 | ||
f37120c3 AM |
66 | /** |
67 | * Not yet implemented | |
68 | */ | |
69 | @Override | |
1aea3488 | 70 | public List<String> listAvailableEvents() { |
f37120c3 AM |
71 | // TODO NYI |
72 | return Collections.EMPTY_LIST; | |
73 | } | |
74 | ||
75 | /** | |
76 | * @return The "enable-event" commands that were received, since | |
77 | * instantiation or the last {@link #clearAllCommands}. | |
78 | */ | |
79 | public List<EventRule> getEnabledEventCommands() { | |
80 | synchronized (enabledEventCommands) { | |
81 | return new ArrayList<>(enabledEventCommands); | |
82 | } | |
83 | } | |
84 | ||
85 | /** | |
86 | * @return The "disable-event" commands that were received, since | |
87 | * instantiation or the last {@link #clearAllCommands}. | |
88 | */ | |
89 | public List<String> getDisabledEventCommands() { | |
90 | synchronized (disabledEventCommands) { | |
91 | return new ArrayList<>(disabledEventCommands); | |
92 | } | |
93 | } | |
94 | ||
73fb6785 AM |
95 | /** |
96 | * @return The "add-context" commands that were received since instantiation | |
97 | * or the last {@link #clearAllCommands}. | |
98 | */ | |
99 | public List<String> getEnabledAppContextCommands() { | |
100 | synchronized (enabledAppContextCommands) { | |
101 | return new ArrayList<>(enabledAppContextCommands); | |
102 | } | |
103 | } | |
104 | ||
105 | /** | |
106 | * Return the number of "context disabled" commands received. | |
107 | * | |
108 | * There is no equivalent command in the lttng CLI, but the sessiond will | |
109 | * send such messages through the agent socket when a session is destroyed | |
110 | * and had contexts enabled. | |
111 | * | |
112 | * @return The number of "context disabled" commands received. | |
113 | */ | |
114 | public List<String> getDisabledAppContextCommands() { | |
115 | synchronized (disabledAppContextCommands) { | |
116 | return new ArrayList<>(disabledAppContextCommands); | |
117 | } | |
118 | } | |
119 | ||
f37120c3 AM |
120 | /** |
121 | * Clear all tracked data. | |
122 | */ | |
123 | public void clearAllCommands() { | |
124 | enabledEventCommands.clear(); | |
125 | disabledEventCommands.clear(); | |
73fb6785 AM |
126 | enabledAppContextCommands.clear(); |
127 | disabledAppContextCommands.clear(); | |
f37120c3 AM |
128 | } |
129 | ||
130 | } |