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 | ||
39 | @Override | |
40 | public boolean eventEnabled(EventRule rule) { | |
41 | enabledEventCommands.add(rule); | |
42 | return true; | |
43 | } | |
44 | ||
45 | @Override | |
46 | public boolean eventDisabled(String name) { | |
47 | disabledEventCommands.add(name); | |
48 | return true; | |
49 | } | |
50 | ||
419da12d AM |
51 | @Override |
52 | public boolean appContextDisabled(String contextRetrieverName, String contextName) { | |
53 | // TODO NYI | |
54 | return false; | |
55 | } | |
56 | ||
57 | @Override | |
58 | public boolean appContextEnabled(String contextRetrieverName, String contextName) { | |
59 | // TODO NYI | |
60 | return false; | |
61 | } | |
62 | ||
f37120c3 AM |
63 | /** |
64 | * Not yet implemented | |
65 | */ | |
66 | @Override | |
1aea3488 | 67 | public List<String> listAvailableEvents() { |
f37120c3 AM |
68 | // TODO NYI |
69 | return Collections.EMPTY_LIST; | |
70 | } | |
71 | ||
72 | /** | |
73 | * @return The "enable-event" commands that were received, since | |
74 | * instantiation or the last {@link #clearAllCommands}. | |
75 | */ | |
76 | public List<EventRule> getEnabledEventCommands() { | |
77 | synchronized (enabledEventCommands) { | |
78 | return new ArrayList<>(enabledEventCommands); | |
79 | } | |
80 | } | |
81 | ||
82 | /** | |
83 | * @return The "disable-event" commands that were received, since | |
84 | * instantiation or the last {@link #clearAllCommands}. | |
85 | */ | |
86 | public List<String> getDisabledEventCommands() { | |
87 | synchronized (disabledEventCommands) { | |
88 | return new ArrayList<>(disabledEventCommands); | |
89 | } | |
90 | } | |
91 | ||
92 | /** | |
93 | * Clear all tracked data. | |
94 | */ | |
95 | public void clearAllCommands() { | |
96 | enabledEventCommands.clear(); | |
97 | disabledEventCommands.clear(); | |
98 | } | |
99 | ||
100 | } |