Simplify EventHistoryManager
Change-Id: Ifefc68269e469883960359406d603e8c24b399df
Showing
2 changed files
with
10 additions
and
61 deletions
... | @@ -32,28 +32,18 @@ import org.apache.felix.scr.annotations.Reference; | ... | @@ -32,28 +32,18 @@ import org.apache.felix.scr.annotations.Reference; |
32 | import org.apache.felix.scr.annotations.ReferenceCardinality; | 32 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
33 | import org.apache.felix.scr.annotations.Service; | 33 | import org.apache.felix.scr.annotations.Service; |
34 | import org.onlab.util.UnmodifiableDeque; | 34 | import org.onlab.util.UnmodifiableDeque; |
35 | -import org.onosproject.cluster.ClusterEvent; | ||
36 | -import org.onosproject.cluster.ClusterEventListener; | ||
37 | import org.onosproject.cluster.ClusterService; | 35 | import org.onosproject.cluster.ClusterService; |
38 | import org.onosproject.core.ApplicationId; | 36 | import org.onosproject.core.ApplicationId; |
39 | import org.onosproject.core.CoreService; | 37 | import org.onosproject.core.CoreService; |
40 | import org.onosproject.event.Event; | 38 | import org.onosproject.event.Event; |
41 | import org.onosproject.event.ListenerTracker; | 39 | import org.onosproject.event.ListenerTracker; |
42 | -import org.onosproject.mastership.MastershipEvent; | ||
43 | -import org.onosproject.mastership.MastershipListener; | ||
44 | import org.onosproject.mastership.MastershipService; | 40 | import org.onosproject.mastership.MastershipService; |
45 | import org.onosproject.net.device.DeviceEvent; | 41 | import org.onosproject.net.device.DeviceEvent; |
46 | import org.onosproject.net.device.DeviceListener; | 42 | import org.onosproject.net.device.DeviceListener; |
47 | import org.onosproject.net.device.DeviceService; | 43 | import org.onosproject.net.device.DeviceService; |
48 | import org.onosproject.net.edge.EdgePortService; | 44 | import org.onosproject.net.edge.EdgePortService; |
49 | -import org.onosproject.net.host.HostEvent; | ||
50 | -import org.onosproject.net.host.HostListener; | ||
51 | import org.onosproject.net.host.HostService; | 45 | import org.onosproject.net.host.HostService; |
52 | -import org.onosproject.net.link.LinkEvent; | ||
53 | -import org.onosproject.net.link.LinkListener; | ||
54 | import org.onosproject.net.link.LinkService; | 46 | import org.onosproject.net.link.LinkService; |
55 | -import org.onosproject.net.topology.TopologyEvent; | ||
56 | -import org.onosproject.net.topology.TopologyListener; | ||
57 | import org.onosproject.net.topology.TopologyService; | 47 | import org.onosproject.net.topology.TopologyService; |
58 | import org.slf4j.Logger; | 48 | import org.slf4j.Logger; |
59 | import org.slf4j.LoggerFactory; | 49 | import org.slf4j.LoggerFactory; |
... | @@ -126,12 +116,12 @@ public class EventHistoryManager | ... | @@ -126,12 +116,12 @@ public class EventHistoryManager |
126 | pruneInterval, pruneInterval, TimeUnit.SECONDS); | 116 | pruneInterval, pruneInterval, TimeUnit.SECONDS); |
127 | 117 | ||
128 | listeners = new ListenerTracker(); | 118 | listeners = new ListenerTracker(); |
129 | - listeners.addListener(mastershipService, new InternalMastershipListener()) | 119 | + listeners.addListener(mastershipService, this::addEvent) |
130 | .addListener(deviceService, new InternalDeviceListener()) | 120 | .addListener(deviceService, new InternalDeviceListener()) |
131 | - .addListener(linkService, new InternalLinkListener()) | 121 | + .addListener(linkService, this::addEvent) |
132 | - .addListener(topologyService, new InternalTopologyListener()) | 122 | + .addListener(topologyService, this::addEvent) |
133 | - .addListener(hostService, new InternalHostListener()) | 123 | + .addListener(hostService, this::addEvent) |
134 | - .addListener(clusterService, new InternalClusterListener()) | 124 | + .addListener(clusterService, this::addEvent) |
135 | .addListener(edgeService, this::addEvent); | 125 | .addListener(edgeService, this::addEvent); |
136 | 126 | ||
137 | log.info("Started"); | 127 | log.info("Started"); |
... | @@ -172,15 +162,6 @@ public class EventHistoryManager | ... | @@ -172,15 +162,6 @@ public class EventHistoryManager |
172 | history.offer(event); | 162 | history.offer(event); |
173 | } | 163 | } |
174 | 164 | ||
175 | - class InternalMastershipListener | ||
176 | - implements MastershipListener { | ||
177 | - | ||
178 | - @Override | ||
179 | - public void event(MastershipEvent event) { | ||
180 | - addEvent(event); | ||
181 | - } | ||
182 | - } | ||
183 | - | ||
184 | class InternalDeviceListener | 165 | class InternalDeviceListener |
185 | implements DeviceListener { | 166 | implements DeviceListener { |
186 | 167 | ||
... | @@ -199,40 +180,4 @@ public class EventHistoryManager | ... | @@ -199,40 +180,4 @@ public class EventHistoryManager |
199 | } | 180 | } |
200 | } | 181 | } |
201 | 182 | ||
202 | - class InternalLinkListener | ||
203 | - implements LinkListener { | ||
204 | - | ||
205 | - @Override | ||
206 | - public void event(LinkEvent event) { | ||
207 | - addEvent(event); | ||
208 | - } | ||
209 | - } | ||
210 | - | ||
211 | - class InternalTopologyListener | ||
212 | - implements TopologyListener { | ||
213 | - | ||
214 | - @Override | ||
215 | - public void event(TopologyEvent event) { | ||
216 | - addEvent(event); | ||
217 | - } | ||
218 | - } | ||
219 | - | ||
220 | - class InternalHostListener | ||
221 | - implements HostListener { | ||
222 | - | ||
223 | - @Override | ||
224 | - public void event(HostEvent event) { | ||
225 | - addEvent(event); | ||
226 | - } | ||
227 | - } | ||
228 | - | ||
229 | - class InternalClusterListener | ||
230 | - implements ClusterEventListener { | ||
231 | - | ||
232 | - @Override | ||
233 | - public void event(ClusterEvent event) { | ||
234 | - addEvent(event); | ||
235 | - } | ||
236 | - } | ||
237 | - | ||
238 | } | 183 | } | ... | ... |
... | @@ -15,13 +15,14 @@ | ... | @@ -15,13 +15,14 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.event; | 16 | package org.onosproject.event; |
17 | 17 | ||
18 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
19 | + | ||
18 | import java.util.ArrayList; | 20 | import java.util.ArrayList; |
19 | import java.util.List; | 21 | import java.util.List; |
20 | 22 | ||
21 | import javax.annotation.concurrent.NotThreadSafe; | 23 | import javax.annotation.concurrent.NotThreadSafe; |
22 | 24 | ||
23 | import org.apache.commons.lang3.tuple.Pair; | 25 | import org.apache.commons.lang3.tuple.Pair; |
24 | - | ||
25 | import com.google.common.annotations.Beta; | 26 | import com.google.common.annotations.Beta; |
26 | import com.google.common.collect.Lists; | 27 | import com.google.common.collect.Lists; |
27 | 28 | ||
... | @@ -66,6 +67,9 @@ public class ListenerTracker { | ... | @@ -66,6 +67,9 @@ public class ListenerTracker { |
66 | */ | 67 | */ |
67 | public <E extends Event<?, ?>, L extends EventListener<E>> | 68 | public <E extends Event<?, ?>, L extends EventListener<E>> |
68 | ListenerTracker addListener(ListenerService<E, L> service, L listener) { | 69 | ListenerTracker addListener(ListenerService<E, L> service, L listener) { |
70 | + | ||
71 | + checkNotNull(service); | ||
72 | + checkNotNull(listener); | ||
69 | service.addListener(listener); | 73 | service.addListener(listener); |
70 | listeners.add(Pair.of(service, listener)); | 74 | listeners.add(Pair.of(service, listener)); |
71 | return this; | 75 | return this; | ... | ... |
-
Please register or login to post a comment