Thomas Vachuska
Committed by Gerrit Code Review

Adding some base-classes to eliminate event and listener boiler-plate code throu…

…ghout a number of subsystems.

Refactored all core components to take advantage of this; apps remain to be done.

Change-Id: Ib0935ba07ff81b0fa032534004ec9ac6187cbf22
Showing 55 changed files with 418 additions and 822 deletions
...@@ -18,13 +18,15 @@ package org.onosproject.app; ...@@ -18,13 +18,15 @@ package org.onosproject.app;
18 import org.onosproject.core.Application; 18 import org.onosproject.core.Application;
19 import org.onosproject.core.ApplicationId; 19 import org.onosproject.core.ApplicationId;
20 import org.onosproject.core.Permission; 20 import org.onosproject.core.Permission;
21 +import org.onosproject.event.ListenerService;
21 22
22 import java.util.Set; 23 import java.util.Set;
23 24
24 /** 25 /**
25 * Service for inspecting inventory of network control applications. 26 * Service for inspecting inventory of network control applications.
26 */ 27 */
27 -public interface ApplicationService { 28 +public interface ApplicationService
29 + extends ListenerService<ApplicationEvent, ApplicationListener> {
28 30
29 /** 31 /**
30 * Returns the set of all installed applications. 32 * Returns the set of all installed applications.
...@@ -65,18 +67,4 @@ public interface ApplicationService { ...@@ -65,18 +67,4 @@ public interface ApplicationService {
65 */ 67 */
66 Set<Permission> getPermissions(ApplicationId appId); 68 Set<Permission> getPermissions(ApplicationId appId);
67 69
68 - /**
69 - * Adds the given listener for application lifecycle events.
70 - *
71 - * @param listener listener to be added
72 - */
73 - void addListener(ApplicationListener listener);
74 -
75 - /**
76 - * Removes the specified listener for application lifecycle events.
77 - *
78 - * @param listener listener to be removed
79 - */
80 - void removeListener(ApplicationListener listener);
81 -
82 } 70 }
......
...@@ -18,12 +18,14 @@ package org.onosproject.cluster; ...@@ -18,12 +18,14 @@ package org.onosproject.cluster;
18 import java.util.Set; 18 import java.util.Set;
19 19
20 import org.joda.time.DateTime; 20 import org.joda.time.DateTime;
21 +import org.onosproject.event.ListenerService;
21 22
22 /** 23 /**
23 * Service for obtaining information about the individual nodes within 24 * Service for obtaining information about the individual nodes within
24 * the controller cluster. 25 * the controller cluster.
25 */ 26 */
26 -public interface ClusterService { 27 +public interface ClusterService
28 + extends ListenerService<ClusterEvent, ClusterEventListener> {
27 29
28 /** 30 /**
29 * Returns the local controller node. 31 * Returns the local controller node.
...@@ -63,18 +65,4 @@ public interface ClusterService { ...@@ -63,18 +65,4 @@ public interface ClusterService {
63 */ 65 */
64 DateTime getLastUpdated(NodeId nodeId); 66 DateTime getLastUpdated(NodeId nodeId);
65 67
66 - /**
67 - * Adds the specified cluster event listener.
68 - *
69 - * @param listener the cluster listener
70 - */
71 - void addListener(ClusterEventListener listener);
72 -
73 - /**
74 - * Removes the specified cluster event listener.
75 - *
76 - * @param listener the cluster listener
77 - */
78 - void removeListener(ClusterEventListener listener);
79 -
80 } 68 }
......
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
15 */ 15 */
16 package org.onosproject.cluster; 16 package org.onosproject.cluster;
17 17
18 +import org.onosproject.event.ListenerService;
19 +
18 import java.util.List; 20 import java.util.List;
19 import java.util.Map; 21 import java.util.Map;
20 import java.util.Set; 22 import java.util.Set;
...@@ -27,7 +29,8 @@ import java.util.concurrent.CompletableFuture; ...@@ -27,7 +29,8 @@ import java.util.concurrent.CompletableFuture;
27 * Listeners can be added to receive notifications asynchronously for various 29 * Listeners can be added to receive notifications asynchronously for various
28 * leadership contests. 30 * leadership contests.
29 */ 31 */
30 -public interface LeadershipService { 32 +public interface LeadershipService
33 + extends ListenerService<LeadershipEvent, LeadershipEventListener> {
31 34
32 /** 35 /**
33 * Returns the current leader for the topic. 36 * Returns the current leader for the topic.
...@@ -118,17 +121,4 @@ public interface LeadershipService { ...@@ -118,17 +121,4 @@ public interface LeadershipService {
118 */ 121 */
119 List<NodeId> getCandidates(String path); 122 List<NodeId> getCandidates(String path);
120 123
121 - /**
122 - * Registers a event listener to be notified of leadership events.
123 - *
124 - * @param listener listener that will asynchronously notified of leadership events.
125 - */
126 - void addListener(LeadershipEventListener listener);
127 -
128 - /**
129 - * Unregisters a event listener for leadership events.
130 - *
131 - * @param listener listener to be removed.
132 - */
133 - void removeListener(LeadershipEventListener listener);
134 } 124 }
......
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.event;
17 +
18 +import org.apache.felix.scr.annotations.Component;
19 +import org.apache.felix.scr.annotations.Reference;
20 +import org.apache.felix.scr.annotations.ReferenceCardinality;
21 +
22 +/**
23 + * Basis for components which need to export listener mechanism.
24 + */
25 +@Component(componentAbstract = true)
26 +public abstract class AbstractListenerManager<E extends Event, L extends EventListener<E>>
27 + implements ListenerService<E, L> {
28 +
29 + protected final ListenerRegistry<E, L> listenerRegistry = new ListenerRegistry<>();
30 +
31 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
32 + protected EventDeliveryService eventDispatcher;
33 +
34 + @Override
35 + public void addListener(L listener) {
36 + listenerRegistry.addListener(listener);
37 + }
38 +
39 + @Override
40 + public void removeListener(L listener) {
41 + listenerRegistry.removeListener(listener);
42 + }
43 +
44 +
45 + /**
46 + * Safely posts the specified event to the local event dispatcher.
47 + * If there is no event dispatcher or if the event is null, this method
48 + * is a noop.
49 + *
50 + * @param event event to be posted; may be null
51 + */
52 + protected void post(E event) {
53 + if (event != null && eventDispatcher != null) {
54 + eventDispatcher.post(event);
55 + }
56 + }
57 +
58 +}
...@@ -28,7 +28,7 @@ import static org.slf4j.LoggerFactory.getLogger; ...@@ -28,7 +28,7 @@ import static org.slf4j.LoggerFactory.getLogger;
28 * listeners and dispatching events to them as part of event sink processing. 28 * listeners and dispatching events to them as part of event sink processing.
29 */ 29 */
30 public class ListenerRegistry<E extends Event, L extends EventListener<E>> 30 public class ListenerRegistry<E extends Event, L extends EventListener<E>>
31 - implements EventSink<E> { 31 + implements ListenerService<E, L>, EventSink<E> {
32 32
33 private static final long LIMIT = 1_800; // ms 33 private static final long LIMIT = 1_800; // ms
34 34
...@@ -42,22 +42,13 @@ public class ListenerRegistry<E extends Event, L extends EventListener<E>> ...@@ -42,22 +42,13 @@ public class ListenerRegistry<E extends Event, L extends EventListener<E>>
42 */ 42 */
43 protected final Set<L> listeners = new CopyOnWriteArraySet<>(); 43 protected final Set<L> listeners = new CopyOnWriteArraySet<>();
44 44
45 - 45 + @Override
46 - /**
47 - * Adds the specified listener.
48 - *
49 - * @param listener listener to be added
50 - */
51 public void addListener(L listener) { 46 public void addListener(L listener) {
52 checkNotNull(listener, "Listener cannot be null"); 47 checkNotNull(listener, "Listener cannot be null");
53 listeners.add(listener); 48 listeners.add(listener);
54 } 49 }
55 50
56 - /** 51 + @Override
57 - * Removes the specified listener.
58 - *
59 - * @param listener listener to be removed
60 - */
61 public void removeListener(L listener) { 52 public void removeListener(L listener) {
62 checkNotNull(listener, "Listener cannot be null"); 53 checkNotNull(listener, "Listener cannot be null");
63 if (!listeners.remove(listener)) { 54 if (!listeners.remove(listener)) {
......
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.event;
17 +
18 +/**
19 + * Abstraction of a service capable of asynchronously notifying listeners.
20 + */
21 +public interface ListenerService<E extends Event, L extends EventListener<E>> {
22 +
23 + /**
24 + * Adds the specified listener.
25 + *
26 + * @param listener listener to be added
27 + */
28 + void addListener(L listener);
29 +
30 + /**
31 + * Removes the specified listener.
32 + *
33 + * @param listener listener to be removed
34 + */
35 + void removeListener(L listener);
36 +
37 +
38 +}
...@@ -20,6 +20,7 @@ import java.util.concurrent.CompletableFuture; ...@@ -20,6 +20,7 @@ import java.util.concurrent.CompletableFuture;
20 20
21 import org.onosproject.cluster.NodeId; 21 import org.onosproject.cluster.NodeId;
22 import org.onosproject.cluster.RoleInfo; 22 import org.onosproject.cluster.RoleInfo;
23 +import org.onosproject.event.ListenerService;
23 import org.onosproject.net.DeviceId; 24 import org.onosproject.net.DeviceId;
24 import org.onosproject.net.MastershipRole; 25 import org.onosproject.net.MastershipRole;
25 26
...@@ -29,7 +30,8 @@ import org.onosproject.net.MastershipRole; ...@@ -29,7 +30,8 @@ import org.onosproject.net.MastershipRole;
29 * determining mastership, but is not responsible for actually applying it 30 * determining mastership, but is not responsible for actually applying it
30 * to the devices; this falls on the device service. 31 * to the devices; this falls on the device service.
31 */ 32 */
32 -public interface MastershipService { 33 +public interface MastershipService
34 + extends ListenerService<MastershipEvent, MastershipListener> {
33 35
34 /** 36 /**
35 * Returns the role of the local node for the specified device, without 37 * Returns the role of the local node for the specified device, without
...@@ -84,18 +86,4 @@ public interface MastershipService { ...@@ -84,18 +86,4 @@ public interface MastershipService {
84 */ 86 */
85 Set<DeviceId> getDevicesOf(NodeId nodeId); 87 Set<DeviceId> getDevicesOf(NodeId nodeId);
86 88
87 - /**
88 - * Adds the specified mastership change listener.
89 - *
90 - * @param listener the mastership listener
91 - */
92 - void addListener(MastershipListener listener);
93 -
94 - /**
95 - * Removes the specified mastership change listener.
96 - *
97 - * @param listener the mastership listener
98 - */
99 - void removeListener(MastershipListener listener);
100 -
101 } 89 }
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
15 */ 15 */
16 package org.onosproject.net.device; 16 package org.onosproject.net.device;
17 17
18 +import org.onosproject.event.ListenerService;
18 import org.onosproject.net.Device; 19 import org.onosproject.net.Device;
19 import org.onosproject.net.DeviceId; 20 import org.onosproject.net.DeviceId;
20 import org.onosproject.net.MastershipRole; 21 import org.onosproject.net.MastershipRole;
...@@ -26,7 +27,8 @@ import java.util.List; ...@@ -26,7 +27,8 @@ import java.util.List;
26 /** 27 /**
27 * Service for interacting with the inventory of infrastructure devices. 28 * Service for interacting with the inventory of infrastructure devices.
28 */ 29 */
29 -public interface DeviceService { 30 +public interface DeviceService
31 + extends ListenerService<DeviceEvent, DeviceListener> {
30 32
31 /** 33 /**
32 * Returns the number of infrastructure devices known to the system. 34 * Returns the number of infrastructure devices known to the system.
...@@ -119,18 +121,4 @@ public interface DeviceService { ...@@ -119,18 +121,4 @@ public interface DeviceService {
119 */ 121 */
120 boolean isAvailable(DeviceId deviceId); 122 boolean isAvailable(DeviceId deviceId);
121 123
122 - /**
123 - * Adds the specified device listener.
124 - *
125 - * @param listener device listener
126 - */
127 - void addListener(DeviceListener listener);
128 -
129 - /**
130 - * Removes the specified device listener.
131 - *
132 - * @param listener device listener
133 - */
134 - void removeListener(DeviceListener listener);
135 -
136 } 124 }
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
15 */ 15 */
16 package org.onosproject.net.edge; 16 package org.onosproject.net.edge;
17 17
18 +import org.onosproject.event.ListenerService;
18 import org.onosproject.net.ConnectPoint; 19 import org.onosproject.net.ConnectPoint;
19 import org.onosproject.net.DeviceId; 20 import org.onosproject.net.DeviceId;
20 import org.onosproject.net.flow.TrafficTreatment; 21 import org.onosproject.net.flow.TrafficTreatment;
...@@ -27,7 +28,8 @@ import java.util.Optional; ...@@ -27,7 +28,8 @@ import java.util.Optional;
27 * is considered an edge port if it is an active port and does not have an 28 * is considered an edge port if it is an active port and does not have an
28 * infrastructure link associated with it. 29 * infrastructure link associated with it.
29 */ 30 */
30 -public interface EdgePortService { 31 +public interface EdgePortService
32 + extends ListenerService<EdgePortEvent, EdgePortListener> {
31 33
32 /** 34 /**
33 * Indicates whether or not the specified connection point is an edge point. 35 * Indicates whether or not the specified connection point is an edge point.
...@@ -70,18 +72,4 @@ public interface EdgePortService { ...@@ -70,18 +72,4 @@ public interface EdgePortService {
70 void emitPacket(DeviceId deviceId, ByteBuffer data, 72 void emitPacket(DeviceId deviceId, ByteBuffer data,
71 Optional<TrafficTreatment> treatment); 73 Optional<TrafficTreatment> treatment);
72 74
73 - /**
74 - * Adds a listener for edge port events.
75 - *
76 - * @param listener listener to be added
77 - */
78 - void addListener(EdgePortListener listener);
79 -
80 - /**
81 - * Removes the listener for edge port events.
82 - *
83 - * @param listener listener to be removed
84 - */
85 - void removeListener(EdgePortListener listener);
86 -
87 } 75 }
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
16 package org.onosproject.net.flow; 16 package org.onosproject.net.flow;
17 17
18 import org.onosproject.core.ApplicationId; 18 import org.onosproject.core.ApplicationId;
19 +import org.onosproject.event.ListenerService;
19 import org.onosproject.net.DeviceId; 20 import org.onosproject.net.DeviceId;
20 21
21 /** 22 /**
...@@ -25,7 +26,8 @@ import org.onosproject.net.DeviceId; ...@@ -25,7 +26,8 @@ import org.onosproject.net.DeviceId;
25 * of the flow rules lies with the controller and the devices hold only the 26 * of the flow rules lies with the controller and the devices hold only the
26 * 'cached' copy. 27 * 'cached' copy.
27 */ 28 */
28 -public interface FlowRuleService { 29 +public interface FlowRuleService
30 + extends ListenerService<FlowRuleEvent, FlowRuleListener> {
29 31
30 /** 32 /**
31 * The topic used for obtaining globally unique ids. 33 * The topic used for obtaining globally unique ids.
...@@ -102,17 +104,4 @@ public interface FlowRuleService { ...@@ -102,17 +104,4 @@ public interface FlowRuleService {
102 */ 104 */
103 void apply(FlowRuleOperations ops); 105 void apply(FlowRuleOperations ops);
104 106
105 - /**
106 - * Adds the specified flow rule listener.
107 - *
108 - * @param listener flow rule listener
109 - */
110 - void addListener(FlowRuleListener listener);
111 -
112 - /**
113 - * Removes the specified flow rule listener.
114 - *
115 - * @param listener flow rule listener
116 - */
117 - void removeListener(FlowRuleListener listener);
118 } 107 }
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
16 package org.onosproject.net.group; 16 package org.onosproject.net.group;
17 17
18 import org.onosproject.core.ApplicationId; 18 import org.onosproject.core.ApplicationId;
19 +import org.onosproject.event.ListenerService;
19 import org.onosproject.net.DeviceId; 20 import org.onosproject.net.DeviceId;
20 21
21 /** 22 /**
...@@ -32,7 +33,8 @@ import org.onosproject.net.DeviceId; ...@@ -32,7 +33,8 @@ import org.onosproject.net.DeviceId;
32 * where the master copy of the groups lies with the controller and 33 * where the master copy of the groups lies with the controller and
33 * the devices hold only the 'cached' copy. 34 * the devices hold only the 'cached' copy.
34 */ 35 */
35 -public interface GroupService { 36 +public interface GroupService
37 + extends ListenerService<GroupEvent, GroupListener> {
36 38
37 /** 39 /**
38 * Creates a group in the specified device with the provided buckets. 40 * Creates a group in the specified device with the provided buckets.
...@@ -134,17 +136,4 @@ public interface GroupService { ...@@ -134,17 +136,4 @@ public interface GroupService {
134 */ 136 */
135 Iterable<Group> getGroups(DeviceId deviceId); 137 Iterable<Group> getGroups(DeviceId deviceId);
136 138
137 - /**
138 - * Adds the specified group listener.
139 - *
140 - * @param listener group listener
141 - */
142 - void addListener(GroupListener listener);
143 -
144 - /**
145 - * Removes the specified group listener.
146 - *
147 - * @param listener group listener
148 - */
149 - void removeListener(GroupListener listener);
150 } 139 }
......
...@@ -17,6 +17,7 @@ package org.onosproject.net.host; ...@@ -17,6 +17,7 @@ package org.onosproject.net.host;
17 17
18 import java.util.Set; 18 import java.util.Set;
19 19
20 +import org.onosproject.event.ListenerService;
20 import org.onosproject.net.ConnectPoint; 21 import org.onosproject.net.ConnectPoint;
21 import org.onosproject.net.DeviceId; 22 import org.onosproject.net.DeviceId;
22 import org.onosproject.net.Host; 23 import org.onosproject.net.Host;
...@@ -28,7 +29,8 @@ import org.onlab.packet.VlanId; ...@@ -28,7 +29,8 @@ import org.onlab.packet.VlanId;
28 /** 29 /**
29 * Service for interacting with the inventory of end-station hosts. 30 * Service for interacting with the inventory of end-station hosts.
30 */ 31 */
31 -public interface HostService { 32 +public interface HostService
33 + extends ListenerService<HostEvent, HostListener> {
32 34
33 /** 35 /**
34 * Returns the number of end-station hosts known to the system. 36 * Returns the number of end-station hosts known to the system.
...@@ -137,18 +139,4 @@ public interface HostService { ...@@ -137,18 +139,4 @@ public interface HostService {
137 */ 139 */
138 Set<PortAddresses> getAddressBindingsForPort(ConnectPoint connectPoint); 140 Set<PortAddresses> getAddressBindingsForPort(ConnectPoint connectPoint);
139 141
140 - /**
141 - * Adds the specified host listener.
142 - *
143 - * @param listener host listener
144 - */
145 - void addListener(HostListener listener);
146 -
147 - /**
148 - * Removes the specified host listener.
149 - *
150 - * @param listener host listener
151 - */
152 - void removeListener(HostListener listener);
153 -
154 } 142 }
......
...@@ -17,6 +17,7 @@ package org.onosproject.net.intent; ...@@ -17,6 +17,7 @@ package org.onosproject.net.intent;
17 17
18 18
19 import com.google.common.annotations.Beta; 19 import com.google.common.annotations.Beta;
20 +import org.onosproject.event.ListenerService;
20 21
21 import java.util.List; 22 import java.util.List;
22 23
...@@ -24,7 +25,9 @@ import java.util.List; ...@@ -24,7 +25,9 @@ import java.util.List;
24 * Service for application submitting or withdrawing their intents. 25 * Service for application submitting or withdrawing their intents.
25 */ 26 */
26 @Beta 27 @Beta
27 -public interface IntentService { 28 +public interface IntentService
29 + extends ListenerService<IntentEvent, IntentListener> {
30 +
28 /** 31 /**
29 * Submits an intent into the system. 32 * Submits an intent into the system.
30 * <p> 33 * <p>
...@@ -117,17 +120,4 @@ public interface IntentService { ...@@ -117,17 +120,4 @@ public interface IntentService {
117 */ 120 */
118 Iterable<Intent> getPending(); 121 Iterable<Intent> getPending();
119 122
120 - /**
121 - * Adds the specified listener for intent events.
122 - *
123 - * @param listener listener to be added
124 - */
125 - void addListener(IntentListener listener);
126 -
127 - /**
128 - * Removes the specified listener for intent events.
129 - *
130 - * @param listener listener to be removed
131 - */
132 - void removeListener(IntentListener listener);
133 } 123 }
......
...@@ -17,12 +17,14 @@ package org.onosproject.net.intent; ...@@ -17,12 +17,14 @@ package org.onosproject.net.intent;
17 17
18 import com.google.common.annotations.Beta; 18 import com.google.common.annotations.Beta;
19 import org.onosproject.cluster.NodeId; 19 import org.onosproject.cluster.NodeId;
20 +import org.onosproject.event.ListenerService;
20 21
21 /** 22 /**
22 * Service for interacting with the partition-to-instance assignments. 23 * Service for interacting with the partition-to-instance assignments.
23 */ 24 */
24 @Beta 25 @Beta
25 -public interface PartitionService { 26 +public interface PartitionService
27 + extends ListenerService<PartitionEvent, PartitionEventListener> {
26 28
27 /** 29 /**
28 * Returns whether the given intent key is in a partition owned by this 30 * Returns whether the given intent key is in a partition owned by this
...@@ -43,17 +45,4 @@ public interface PartitionService { ...@@ -43,17 +45,4 @@ public interface PartitionService {
43 45
44 // TODO add API for rebalancing partitions 46 // TODO add API for rebalancing partitions
45 47
46 - /**
47 - * Registers a event listener to be notified of partition events.
48 - *
49 - * @param listener listener that will asynchronously notified of partition events.
50 - */
51 - void addListener(PartitionEventListener listener);
52 -
53 - /**
54 - * Unregisters a event listener for partition events.
55 - *
56 - * @param listener listener to be removed.
57 - */
58 - void removeListener(PartitionEventListener listener);
59 } 48 }
......
...@@ -17,6 +17,7 @@ package org.onosproject.net.link; ...@@ -17,6 +17,7 @@ package org.onosproject.net.link;
17 17
18 import java.util.Set; 18 import java.util.Set;
19 19
20 +import org.onosproject.event.ListenerService;
20 import org.onosproject.net.ConnectPoint; 21 import org.onosproject.net.ConnectPoint;
21 import org.onosproject.net.DeviceId; 22 import org.onosproject.net.DeviceId;
22 import org.onosproject.net.Link; 23 import org.onosproject.net.Link;
...@@ -24,7 +25,8 @@ import org.onosproject.net.Link; ...@@ -24,7 +25,8 @@ import org.onosproject.net.Link;
24 /** 25 /**
25 * Service for interacting with the inventory of infrastructure links. 26 * Service for interacting with the inventory of infrastructure links.
26 */ 27 */
27 -public interface LinkService { 28 +public interface LinkService
29 + extends ListenerService<LinkEvent, LinkListener> {
28 30
29 /** 31 /**
30 * Returns the count of all known infrastructure links. 32 * Returns the count of all known infrastructure links.
...@@ -111,18 +113,4 @@ public interface LinkService { ...@@ -111,18 +113,4 @@ public interface LinkService {
111 */ 113 */
112 Link getLink(ConnectPoint src, ConnectPoint dst); 114 Link getLink(ConnectPoint src, ConnectPoint dst);
113 115
114 - /**
115 - * Adds the specified link listener.
116 - *
117 - * @param listener link listener
118 - */
119 - void addListener(LinkListener listener);
120 -
121 - /**
122 - * Removes the specified link listener.
123 - *
124 - * @param listener link listener
125 - */
126 - void removeListener(LinkListener listener);
127 -
128 } 116 }
......
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.net.provider;
17 +
18 +import org.apache.felix.scr.annotations.Component;
19 +import org.apache.felix.scr.annotations.Reference;
20 +import org.apache.felix.scr.annotations.ReferenceCardinality;
21 +import org.onosproject.event.Event;
22 +import org.onosproject.event.EventDeliveryService;
23 +import org.onosproject.event.EventListener;
24 +import org.onosproject.event.ListenerRegistry;
25 +import org.onosproject.event.ListenerService;
26 +
27 +/**
28 + * Basis for components which need to export listener mechanism.
29 + */
30 +@Component(componentAbstract = true)
31 +public abstract class AbstractListenerProviderRegistry<E extends Event, L extends EventListener<E>,
32 + P extends Provider, S extends ProviderService<P>>
33 + extends AbstractProviderRegistry<P, S> implements ListenerService<E, L> {
34 +
35 + // If only Java supported mixins...
36 +
37 + protected final ListenerRegistry<E, L> listenerRegistry = new ListenerRegistry<>();
38 +
39 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
40 + protected EventDeliveryService eventDispatcher;
41 +
42 + @Override
43 + public void addListener(L listener) {
44 + listenerRegistry.addListener(listener);
45 + }
46 +
47 + @Override
48 + public void removeListener(L listener) {
49 + listenerRegistry.removeListener(listener);
50 + }
51 +
52 +
53 + /**
54 + * Safely posts the specified event to the local event dispatcher.
55 + * If there is no event dispatcher or if the event is null, this method
56 + * is a noop.
57 + *
58 + * @param event event to be posted; may be null
59 + */
60 + protected void post(E event) {
61 + if (event != null && eventDispatcher != null) {
62 + eventDispatcher.post(event);
63 + }
64 + }
65 +
66 +}
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
15 */ 15 */
16 package org.onosproject.net.resource.link; 16 package org.onosproject.net.resource.link;
17 17
18 +import org.onosproject.event.ListenerService;
18 import org.onosproject.net.Link; 19 import org.onosproject.net.Link;
19 import org.onosproject.net.intent.IntentId; 20 import org.onosproject.net.intent.IntentId;
20 import org.onosproject.net.resource.ResourceRequest; 21 import org.onosproject.net.resource.ResourceRequest;
...@@ -22,7 +23,8 @@ import org.onosproject.net.resource.ResourceRequest; ...@@ -22,7 +23,8 @@ import org.onosproject.net.resource.ResourceRequest;
22 /** 23 /**
23 * Service for providing link resource allocation. 24 * Service for providing link resource allocation.
24 */ 25 */
25 -public interface LinkResourceService { 26 +public interface LinkResourceService
27 + extends ListenerService<LinkResourceEvent, LinkResourceListener> {
26 28
27 /** 29 /**
28 * Requests resources. 30 * Requests resources.
...@@ -88,20 +90,6 @@ public interface LinkResourceService { ...@@ -88,20 +90,6 @@ public interface LinkResourceService {
88 * @return available resources for the target link 90 * @return available resources for the target link
89 */ 91 */
90 Iterable<ResourceRequest> getAvailableResources(Link link, 92 Iterable<ResourceRequest> getAvailableResources(Link link,
91 - LinkResourceAllocations allocations); 93 + LinkResourceAllocations allocations);
92 -
93 - /**
94 - * Adds a listener for resource related events.
95 - *
96 - * @param listener listener to add
97 - */
98 - void addListener(LinkResourceListener listener);
99 -
100 - /**
101 - * Removes a listener for resource related events.
102 - *
103 - * @param listener listener to remove.
104 - */
105 - void removeListener(LinkResourceListener listener);
106 94
107 } 95 }
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
15 */ 15 */
16 package org.onosproject.net.topology; 16 package org.onosproject.net.topology;
17 17
18 +import org.onosproject.event.ListenerService;
18 import org.onosproject.net.ConnectPoint; 19 import org.onosproject.net.ConnectPoint;
19 import org.onosproject.net.DeviceId; 20 import org.onosproject.net.DeviceId;
20 import org.onosproject.net.Link; 21 import org.onosproject.net.Link;
...@@ -25,7 +26,8 @@ import java.util.Set; ...@@ -25,7 +26,8 @@ import java.util.Set;
25 /** 26 /**
26 * Service for providing network topology information. 27 * Service for providing network topology information.
27 */ 28 */
28 -public interface TopologyService { 29 +public interface TopologyService
30 + extends ListenerService<TopologyEvent, TopologyListener> {
29 31
30 /** 32 /**
31 * Returns the current topology descriptor. 33 * Returns the current topology descriptor.
...@@ -130,18 +132,4 @@ public interface TopologyService { ...@@ -130,18 +132,4 @@ public interface TopologyService {
130 */ 132 */
131 boolean isBroadcastPoint(Topology topology, ConnectPoint connectPoint); 133 boolean isBroadcastPoint(Topology topology, ConnectPoint connectPoint);
132 134
133 - /**
134 - * Adds the specified topology listener.
135 - *
136 - * @param listener topology listener
137 - */
138 - void addListener(TopologyListener listener);
139 -
140 - /**
141 - * Removes the specified topology listener.
142 - *
143 - * @param listener topology listener
144 - */
145 - void removeListener(TopologyListener listener);
146 -
147 } 135 }
......
...@@ -15,22 +15,24 @@ ...@@ -15,22 +15,24 @@
15 */ 15 */
16 package org.onosproject.net; 16 package org.onosproject.net;
17 17
18 +import org.onlab.packet.ChassisId;
19 +import org.onlab.packet.IpAddress;
18 import org.onosproject.TestApplicationId; 20 import org.onosproject.TestApplicationId;
19 import org.onosproject.core.ApplicationId; 21 import org.onosproject.core.ApplicationId;
22 +import org.onosproject.event.EventDeliveryService;
20 import org.onosproject.net.provider.ProviderId; 23 import org.onosproject.net.provider.ProviderId;
21 -import org.onlab.packet.ChassisId;
22 -import org.onlab.packet.IpAddress;
23 24
25 +import java.lang.reflect.Field;
24 import java.util.ArrayList; 26 import java.util.ArrayList;
25 import java.util.HashSet; 27 import java.util.HashSet;
26 import java.util.List; 28 import java.util.List;
27 29
28 import static org.junit.Assert.assertEquals; 30 import static org.junit.Assert.assertEquals;
31 +import static org.onlab.packet.MacAddress.valueOf;
32 +import static org.onlab.packet.VlanId.vlanId;
29 import static org.onosproject.net.DeviceId.deviceId; 33 import static org.onosproject.net.DeviceId.deviceId;
30 import static org.onosproject.net.HostId.hostId; 34 import static org.onosproject.net.HostId.hostId;
31 import static org.onosproject.net.PortNumber.portNumber; 35 import static org.onosproject.net.PortNumber.portNumber;
32 -import static org.onlab.packet.MacAddress.valueOf;
33 -import static org.onlab.packet.VlanId.vlanId;
34 36
35 /** 37 /**
36 * Miscellaneous tools for testing core related to the network model. 38 * Miscellaneous tools for testing core related to the network model.
...@@ -98,8 +100,8 @@ public final class NetTestTools { ...@@ -98,8 +100,8 @@ public final class NetTestTools {
98 * Verifies that Annotations created by merging {@code annotations} is 100 * Verifies that Annotations created by merging {@code annotations} is
99 * equal to actual Annotations. 101 * equal to actual Annotations.
100 * 102 *
101 - * @param actual Annotations to check 103 + * @param actual annotations to check
102 - * @param annotations 104 + * @param annotations expected annotations
103 */ 105 */
104 public static void assertAnnotationsEquals(Annotations actual, SparseAnnotations... annotations) { 106 public static void assertAnnotationsEquals(Annotations actual, SparseAnnotations... annotations) {
105 DefaultAnnotations expected = DefaultAnnotations.builder().build(); 107 DefaultAnnotations expected = DefaultAnnotations.builder().build();
...@@ -112,4 +114,25 @@ public final class NetTestTools { ...@@ -112,4 +114,25 @@ public final class NetTestTools {
112 } 114 }
113 } 115 }
114 116
117 + /**
118 + * Injects the given event delivery service into the specified manager
119 + * component.
120 + *
121 + * @param manager manager component
122 + * @param svc service reference to be injected
123 + */
124 + public static void injectEventDispatcher(Object manager, EventDeliveryService svc) {
125 + Class mc = manager.getClass();
126 + for (Field f : mc.getSuperclass().getDeclaredFields()) {
127 + if (f.getType().equals(EventDeliveryService.class)) {
128 + try {
129 + f.setAccessible(true);
130 + f.set(manager, svc);
131 + } catch (IllegalAccessException e) {
132 + throw new IllegalArgumentException("Unable to inject reference", e);
133 + }
134 + }
135 + }
136 + }
137 +
115 } 138 }
......
...@@ -49,25 +49,6 @@ ...@@ -49,25 +49,6 @@
49 <artifactId>easymock</artifactId> 49 <artifactId>easymock</artifactId>
50 <scope>test</scope> 50 <scope>test</scope>
51 </dependency> 51 </dependency>
52 -
53 - <dependency>
54 - <groupId>org.osgi</groupId>
55 - <artifactId>org.osgi.compendium</artifactId>
56 - </dependency>
57 -
58 - <dependency>
59 - <groupId>org.apache.felix</groupId>
60 - <artifactId>org.apache.felix.scr.annotations</artifactId>
61 - </dependency>
62 </dependencies> 52 </dependencies>
63 53
64 - <build>
65 - <plugins>
66 - <plugin>
67 - <groupId>org.apache.felix</groupId>
68 - <artifactId>maven-scr-plugin</artifactId>
69 - </plugin>
70 - </plugins>
71 - </build>
72 -
73 </project> 54 </project>
......
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +/**
18 + * Miscellaneous common facilities used for construction of various core and
19 + * app subsystems.
20 + */
21 +package org.onosproject.common;
...\ No newline at end of file ...\ No newline at end of file
...@@ -78,11 +78,6 @@ ...@@ -78,11 +78,6 @@
78 </dependency> 78 </dependency>
79 79
80 <dependency> 80 <dependency>
81 - <groupId>org.apache.felix</groupId>
82 - <artifactId>org.apache.felix.scr.annotations</artifactId>
83 - </dependency>
84 -
85 - <dependency>
86 <groupId>org.apache.karaf.features</groupId> 81 <groupId>org.apache.karaf.features</groupId>
87 <artifactId>org.apache.karaf.features.core</artifactId> 82 <artifactId>org.apache.karaf.features.core</artifactId>
88 </dependency> 83 </dependency>
...@@ -93,13 +88,4 @@ ...@@ -93,13 +88,4 @@
93 </dependency> 88 </dependency>
94 </dependencies> 89 </dependencies>
95 90
96 - <build>
97 - <plugins>
98 - <plugin>
99 - <groupId>org.apache.felix</groupId>
100 - <artifactId>maven-scr-plugin</artifactId>
101 - </plugin>
102 - </plugins>
103 - </build>
104 -
105 </project> 91 </project>
......
...@@ -30,11 +30,10 @@ import org.onosproject.app.ApplicationService; ...@@ -30,11 +30,10 @@ import org.onosproject.app.ApplicationService;
30 import org.onosproject.app.ApplicationState; 30 import org.onosproject.app.ApplicationState;
31 import org.onosproject.app.ApplicationStore; 31 import org.onosproject.app.ApplicationStore;
32 import org.onosproject.app.ApplicationStoreDelegate; 32 import org.onosproject.app.ApplicationStoreDelegate;
33 +import org.onosproject.event.AbstractListenerManager;
33 import org.onosproject.core.Application; 34 import org.onosproject.core.Application;
34 import org.onosproject.core.ApplicationId; 35 import org.onosproject.core.ApplicationId;
35 import org.onosproject.core.Permission; 36 import org.onosproject.core.Permission;
36 -import org.onosproject.event.ListenerRegistry;
37 -import org.onosproject.event.EventDeliveryService;
38 import org.slf4j.Logger; 37 import org.slf4j.Logger;
39 38
40 import java.io.InputStream; 39 import java.io.InputStream;
...@@ -50,15 +49,14 @@ import static org.slf4j.LoggerFactory.getLogger; ...@@ -50,15 +49,14 @@ import static org.slf4j.LoggerFactory.getLogger;
50 */ 49 */
51 @Component(immediate = true) 50 @Component(immediate = true)
52 @Service 51 @Service
53 -public class ApplicationManager implements ApplicationService, ApplicationAdminService { 52 +public class ApplicationManager
53 + extends AbstractListenerManager<ApplicationEvent, ApplicationListener>
54 + implements ApplicationService, ApplicationAdminService {
54 55
55 private final Logger log = getLogger(getClass()); 56 private final Logger log = getLogger(getClass());
56 57
57 private static final String APP_ID_NULL = "Application ID cannot be null"; 58 private static final String APP_ID_NULL = "Application ID cannot be null";
58 59
59 - protected final ListenerRegistry<ApplicationEvent, ApplicationListener>
60 - listenerRegistry = new ListenerRegistry<>();
61 -
62 private final ApplicationStoreDelegate delegate = new InternalStoreDelegate(); 60 private final ApplicationStoreDelegate delegate = new InternalStoreDelegate();
63 61
64 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 62 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
...@@ -67,9 +65,6 @@ public class ApplicationManager implements ApplicationService, ApplicationAdminS ...@@ -67,9 +65,6 @@ public class ApplicationManager implements ApplicationService, ApplicationAdminS
67 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 65 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
68 protected FeaturesService featuresService; 66 protected FeaturesService featuresService;
69 67
70 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
71 - protected EventDeliveryService eventDispatcher;
72 -
73 private boolean initializing; 68 private boolean initializing;
74 69
75 @Activate 70 @Activate
...@@ -99,7 +94,6 @@ public class ApplicationManager implements ApplicationService, ApplicationAdminS ...@@ -99,7 +94,6 @@ public class ApplicationManager implements ApplicationService, ApplicationAdminS
99 @Override 94 @Override
100 public ApplicationId getId(String name) { 95 public ApplicationId getId(String name) {
101 checkPermission(Permission.APP_READ); 96 checkPermission(Permission.APP_READ);
102 -
103 checkNotNull(name, "Name cannot be null"); 97 checkNotNull(name, "Name cannot be null");
104 return store.getId(name); 98 return store.getId(name);
105 } 99 }
...@@ -160,18 +154,6 @@ public class ApplicationManager implements ApplicationService, ApplicationAdminS ...@@ -160,18 +154,6 @@ public class ApplicationManager implements ApplicationService, ApplicationAdminS
160 store.setPermissions(appId, permissions); 154 store.setPermissions(appId, permissions);
161 } 155 }
162 156
163 - @Override
164 - public void addListener(ApplicationListener listener) {
165 - checkPermission(Permission.APP_EVENT);
166 - listenerRegistry.addListener(listener);
167 - }
168 -
169 - @Override
170 - public void removeListener(ApplicationListener listener) {
171 - checkPermission(Permission.APP_EVENT);
172 - listenerRegistry.removeListener(listener);
173 - }
174 -
175 private class InternalStoreDelegate implements ApplicationStoreDelegate { 157 private class InternalStoreDelegate implements ApplicationStoreDelegate {
176 @Override 158 @Override
177 public void notify(ApplicationEvent event) { 159 public void notify(ApplicationEvent event) {
...@@ -199,7 +181,7 @@ public class ApplicationManager implements ApplicationService, ApplicationAdminS ...@@ -199,7 +181,7 @@ public class ApplicationManager implements ApplicationService, ApplicationAdminS
199 } 181 }
200 182
201 } 183 }
202 - eventDispatcher.post(event); 184 + post(event);
203 185
204 } catch (Exception e) { 186 } catch (Exception e) {
205 log.warn("Unable to perform operation on application " + app.id().name(), e); 187 log.warn("Unable to perform operation on application " + app.id().name(), e);
......
...@@ -33,17 +33,16 @@ import org.onosproject.cluster.ClusterStore; ...@@ -33,17 +33,16 @@ import org.onosproject.cluster.ClusterStore;
33 import org.onosproject.cluster.ClusterStoreDelegate; 33 import org.onosproject.cluster.ClusterStoreDelegate;
34 import org.onosproject.cluster.ControllerNode; 34 import org.onosproject.cluster.ControllerNode;
35 import org.onosproject.cluster.NodeId; 35 import org.onosproject.cluster.NodeId;
36 +import org.onosproject.event.AbstractListenerManager;
36 import org.onosproject.core.Permission; 37 import org.onosproject.core.Permission;
37 -import org.onosproject.event.ListenerRegistry;
38 -import org.onosproject.event.EventDeliveryService;
39 import org.slf4j.Logger; 38 import org.slf4j.Logger;
40 39
41 import java.util.Set; 40 import java.util.Set;
42 41
43 import static com.google.common.base.Preconditions.checkArgument; 42 import static com.google.common.base.Preconditions.checkArgument;
44 import static com.google.common.base.Preconditions.checkNotNull; 43 import static com.google.common.base.Preconditions.checkNotNull;
45 -import static org.slf4j.LoggerFactory.getLogger;
46 import static org.onosproject.security.AppGuard.checkPermission; 44 import static org.onosproject.security.AppGuard.checkPermission;
45 +import static org.slf4j.LoggerFactory.getLogger;
47 46
48 47
49 /** 48 /**
...@@ -51,16 +50,15 @@ import static org.onosproject.security.AppGuard.checkPermission; ...@@ -51,16 +50,15 @@ import static org.onosproject.security.AppGuard.checkPermission;
51 */ 50 */
52 @Component(immediate = true) 51 @Component(immediate = true)
53 @Service 52 @Service
54 -public class ClusterManager implements ClusterService, ClusterAdminService { 53 +public class ClusterManager
54 + extends AbstractListenerManager<ClusterEvent, ClusterEventListener>
55 + implements ClusterService, ClusterAdminService {
55 56
56 public static final String INSTANCE_ID_NULL = "Instance ID cannot be null"; 57 public static final String INSTANCE_ID_NULL = "Instance ID cannot be null";
57 private final Logger log = getLogger(getClass()); 58 private final Logger log = getLogger(getClass());
58 59
59 private ClusterStoreDelegate delegate = new InternalStoreDelegate(); 60 private ClusterStoreDelegate delegate = new InternalStoreDelegate();
60 61
61 - protected final ListenerRegistry<ClusterEvent, ClusterEventListener>
62 - listenerRegistry = new ListenerRegistry<>();
63 -
64 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 62 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
65 protected ClusterDefinitionService clusterDefinitionService; 63 protected ClusterDefinitionService clusterDefinitionService;
66 64
...@@ -68,9 +66,6 @@ public class ClusterManager implements ClusterService, ClusterAdminService { ...@@ -68,9 +66,6 @@ public class ClusterManager implements ClusterService, ClusterAdminService {
68 protected ClusterStore store; 66 protected ClusterStore store;
69 67
70 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 68 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
71 - protected EventDeliveryService eventDispatcher;
72 -
73 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
74 protected SystemService systemService; 69 protected SystemService systemService;
75 70
76 @Activate 71 @Activate
...@@ -150,24 +145,11 @@ public class ClusterManager implements ClusterService, ClusterAdminService { ...@@ -150,24 +145,11 @@ public class ClusterManager implements ClusterService, ClusterAdminService {
150 store.removeNode(nodeId); 145 store.removeNode(nodeId);
151 } 146 }
152 147
153 - @Override
154 - public void addListener(ClusterEventListener listener) {
155 - checkPermission(Permission.CLUSTER_EVENT);
156 - listenerRegistry.addListener(listener);
157 - }
158 -
159 - @Override
160 - public void removeListener(ClusterEventListener listener) {
161 - checkPermission(Permission.CLUSTER_EVENT);
162 - listenerRegistry.removeListener(listener);
163 - }
164 -
165 // Store delegate to re-post events emitted from the store. 148 // Store delegate to re-post events emitted from the store.
166 private class InternalStoreDelegate implements ClusterStoreDelegate { 149 private class InternalStoreDelegate implements ClusterStoreDelegate {
167 @Override 150 @Override
168 public void notify(ClusterEvent event) { 151 public void notify(ClusterEvent event) {
169 - checkNotNull(event, "Event cannot be null"); 152 + post(event);
170 - eventDispatcher.post(event);
171 } 153 }
172 } 154 }
173 } 155 }
......
...@@ -19,7 +19,6 @@ import com.codahale.metrics.Timer; ...@@ -19,7 +19,6 @@ import com.codahale.metrics.Timer;
19 import com.codahale.metrics.Timer.Context; 19 import com.codahale.metrics.Timer.Context;
20 import com.google.common.collect.Lists; 20 import com.google.common.collect.Lists;
21 import com.google.common.util.concurrent.Futures; 21 import com.google.common.util.concurrent.Futures;
22 -
23 import org.apache.felix.scr.annotations.Activate; 22 import org.apache.felix.scr.annotations.Activate;
24 import org.apache.felix.scr.annotations.Component; 23 import org.apache.felix.scr.annotations.Component;
25 import org.apache.felix.scr.annotations.Deactivate; 24 import org.apache.felix.scr.annotations.Deactivate;
...@@ -31,10 +30,9 @@ import org.onosproject.cluster.ClusterService; ...@@ -31,10 +30,9 @@ import org.onosproject.cluster.ClusterService;
31 import org.onosproject.cluster.ControllerNode; 30 import org.onosproject.cluster.ControllerNode;
32 import org.onosproject.cluster.NodeId; 31 import org.onosproject.cluster.NodeId;
33 import org.onosproject.cluster.RoleInfo; 32 import org.onosproject.cluster.RoleInfo;
33 +import org.onosproject.event.AbstractListenerManager;
34 import org.onosproject.core.MetricsHelper; 34 import org.onosproject.core.MetricsHelper;
35 import org.onosproject.core.Permission; 35 import org.onosproject.core.Permission;
36 -import org.onosproject.event.ListenerRegistry;
37 -import org.onosproject.event.EventDeliveryService;
38 import org.onosproject.mastership.MastershipAdminService; 36 import org.onosproject.mastership.MastershipAdminService;
39 import org.onosproject.mastership.MastershipEvent; 37 import org.onosproject.mastership.MastershipEvent;
40 import org.onosproject.mastership.MastershipListener; 38 import org.onosproject.mastership.MastershipListener;
...@@ -62,13 +60,14 @@ import static org.onlab.metrics.MetricsUtil.startTimer; ...@@ -62,13 +60,14 @@ import static org.onlab.metrics.MetricsUtil.startTimer;
62 import static org.onlab.metrics.MetricsUtil.stopTimer; 60 import static org.onlab.metrics.MetricsUtil.stopTimer;
63 import static org.onosproject.cluster.ControllerNode.State.ACTIVE; 61 import static org.onosproject.cluster.ControllerNode.State.ACTIVE;
64 import static org.onosproject.net.MastershipRole.MASTER; 62 import static org.onosproject.net.MastershipRole.MASTER;
65 -import static org.slf4j.LoggerFactory.getLogger;
66 import static org.onosproject.security.AppGuard.checkPermission; 63 import static org.onosproject.security.AppGuard.checkPermission;
64 +import static org.slf4j.LoggerFactory.getLogger;
67 65
68 66
69 @Component(immediate = true) 67 @Component(immediate = true)
70 @Service 68 @Service
71 public class MastershipManager 69 public class MastershipManager
70 + extends AbstractListenerManager<MastershipEvent, MastershipListener>
72 implements MastershipService, MastershipAdminService, MastershipTermService, 71 implements MastershipService, MastershipAdminService, MastershipTermService,
73 MetricsHelper { 72 MetricsHelper {
74 73
...@@ -78,18 +77,12 @@ public class MastershipManager ...@@ -78,18 +77,12 @@ public class MastershipManager
78 77
79 private final Logger log = getLogger(getClass()); 78 private final Logger log = getLogger(getClass());
80 79
81 - protected final ListenerRegistry<MastershipEvent, MastershipListener>
82 - listenerRegistry = new ListenerRegistry<>();
83 -
84 private final MastershipStoreDelegate delegate = new InternalDelegate(); 80 private final MastershipStoreDelegate delegate = new InternalDelegate();
85 81
86 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 82 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
87 protected MastershipStore store; 83 protected MastershipStore store;
88 84
89 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 85 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
90 - protected EventDeliveryService eventDispatcher;
91 -
92 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
93 protected ClusterService clusterService; 86 protected ClusterService clusterService;
94 87
95 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 88 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
...@@ -197,22 +190,6 @@ public class MastershipManager ...@@ -197,22 +190,6 @@ public class MastershipManager
197 } 190 }
198 191
199 @Override 192 @Override
200 - public void addListener(MastershipListener listener) {
201 - checkPermission(Permission.CLUSTER_EVENT);
202 -
203 - checkNotNull(listener);
204 - listenerRegistry.addListener(listener);
205 - }
206 -
207 - @Override
208 - public void removeListener(MastershipListener listener) {
209 - checkPermission(Permission.CLUSTER_EVENT);
210 -
211 - checkNotNull(listener);
212 - listenerRegistry.removeListener(listener);
213 - }
214 -
215 - @Override
216 public MetricsService metricsService() { 193 public MetricsService metricsService() {
217 return metricsService; 194 return metricsService;
218 } 195 }
...@@ -294,21 +271,11 @@ public class MastershipManager ...@@ -294,21 +271,11 @@ public class MastershipManager
294 } 271 }
295 272
296 273
297 - // Posts the specified event to the local event dispatcher.
298 - private void post(MastershipEvent event) {
299 - if (event != null && eventDispatcher != null) {
300 - eventDispatcher.post(event);
301 - }
302 - }
303 -
304 public class InternalDelegate implements MastershipStoreDelegate { 274 public class InternalDelegate implements MastershipStoreDelegate {
305 -
306 @Override 275 @Override
307 public void notify(MastershipEvent event) { 276 public void notify(MastershipEvent event) {
308 - log.trace("dispatching mastership event {}", event); 277 + post(event);
309 - eventDispatcher.post(event);
310 } 278 }
311 -
312 } 279 }
313 280
314 } 281 }
......
...@@ -26,9 +26,8 @@ import org.apache.felix.scr.annotations.Deactivate; ...@@ -26,9 +26,8 @@ import org.apache.felix.scr.annotations.Deactivate;
26 import org.apache.felix.scr.annotations.Reference; 26 import org.apache.felix.scr.annotations.Reference;
27 import org.apache.felix.scr.annotations.ReferenceCardinality; 27 import org.apache.felix.scr.annotations.ReferenceCardinality;
28 import org.apache.felix.scr.annotations.Service; 28 import org.apache.felix.scr.annotations.Service;
29 +import org.onosproject.event.AbstractListenerManager;
29 import org.onosproject.event.Event; 30 import org.onosproject.event.Event;
30 -import org.onosproject.event.EventDeliveryService;
31 -import org.onosproject.event.ListenerRegistry;
32 import org.onosproject.net.ConnectPoint; 31 import org.onosproject.net.ConnectPoint;
33 import org.onosproject.net.DeviceId; 32 import org.onosproject.net.DeviceId;
34 import org.onosproject.net.device.DeviceEvent; 33 import org.onosproject.net.device.DeviceEvent;
...@@ -64,7 +63,9 @@ import static org.slf4j.LoggerFactory.getLogger; ...@@ -64,7 +63,9 @@ import static org.slf4j.LoggerFactory.getLogger;
64 */ 63 */
65 @Component(immediate = true) 64 @Component(immediate = true)
66 @Service 65 @Service
67 -public class EdgeManager implements EdgePortService { 66 +public class EdgeManager
67 + extends AbstractListenerManager<EdgePortEvent, EdgePortListener>
68 + implements EdgePortService {
68 69
69 private final Logger log = getLogger(getClass()); 70 private final Logger log = getLogger(getClass());
70 71
...@@ -72,15 +73,9 @@ public class EdgeManager implements EdgePortService { ...@@ -72,15 +73,9 @@ public class EdgeManager implements EdgePortService {
72 73
73 private final Map<DeviceId, Set<ConnectPoint>> connectionPoints = Maps.newConcurrentMap(); 74 private final Map<DeviceId, Set<ConnectPoint>> connectionPoints = Maps.newConcurrentMap();
74 75
75 - private final ListenerRegistry<EdgePortEvent, EdgePortListener>
76 - listenerRegistry = new ListenerRegistry<>();
77 -
78 private final TopologyListener topologyListener = new InnerTopologyListener(); 76 private final TopologyListener topologyListener = new InnerTopologyListener();
79 77
80 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 78 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
81 - protected EventDeliveryService eventDispatcher;
82 -
83 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
84 protected PacketService packetService; 79 protected PacketService packetService;
85 80
86 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 81 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
...@@ -147,17 +142,6 @@ public class EdgeManager implements EdgePortService { ...@@ -147,17 +142,6 @@ public class EdgeManager implements EdgePortService {
147 return new DefaultOutboundPacket(point.deviceId(), builder.build(), data); 142 return new DefaultOutboundPacket(point.deviceId(), builder.build(), data);
148 } 143 }
149 144
150 - @Override
151 - public void addListener(EdgePortListener listener) {
152 - listenerRegistry.addListener(listener);
153 - }
154 -
155 - @Override
156 - public void removeListener(EdgePortListener listener) {
157 - listenerRegistry.removeListener(listener);
158 - }
159 -
160 -
161 // Internal listener for topo events used to keep our edge-port cache 145 // Internal listener for topo events used to keep our edge-port cache
162 // up to date. 146 // up to date.
163 private class InnerTopologyListener implements TopologyListener { 147 private class InnerTopologyListener implements TopologyListener {
...@@ -234,7 +218,7 @@ public class EdgeManager implements EdgePortService { ...@@ -234,7 +218,7 @@ public class EdgeManager implements EdgePortService {
234 connectionPoints.put(point.deviceId(), set); 218 connectionPoints.put(point.deviceId(), set);
235 } 219 }
236 if (set.add(point)) { 220 if (set.add(point)) {
237 - eventDispatcher.post(new EdgePortEvent(EDGE_PORT_ADDED, point)); 221 + post(new EdgePortEvent(EDGE_PORT_ADDED, point));
238 } 222 }
239 } 223 }
240 } 224 }
...@@ -247,7 +231,7 @@ public class EdgeManager implements EdgePortService { ...@@ -247,7 +231,7 @@ public class EdgeManager implements EdgePortService {
247 return; 231 return;
248 } 232 }
249 if (set.remove(point)) { 233 if (set.remove(point)) {
250 - eventDispatcher.post(new EdgePortEvent(EDGE_PORT_REMOVED, point)); 234 + post(new EdgePortEvent(EDGE_PORT_REMOVED, point));
251 } 235 }
252 if (set.isEmpty()) { 236 if (set.isEmpty()) {
253 connectionPoints.remove(point.deviceId()); 237 connectionPoints.remove(point.deviceId());
......
...@@ -32,12 +32,11 @@ import org.apache.felix.scr.annotations.ReferenceCardinality; ...@@ -32,12 +32,11 @@ import org.apache.felix.scr.annotations.ReferenceCardinality;
32 import org.apache.felix.scr.annotations.Service; 32 import org.apache.felix.scr.annotations.Service;
33 import org.onlab.util.Tools; 33 import org.onlab.util.Tools;
34 import org.onosproject.cfg.ComponentConfigService; 34 import org.onosproject.cfg.ComponentConfigService;
35 +import org.onosproject.net.provider.AbstractListenerProviderRegistry;
35 import org.onosproject.core.ApplicationId; 36 import org.onosproject.core.ApplicationId;
36 import org.onosproject.core.CoreService; 37 import org.onosproject.core.CoreService;
37 import org.onosproject.core.IdGenerator; 38 import org.onosproject.core.IdGenerator;
38 import org.onosproject.core.Permission; 39 import org.onosproject.core.Permission;
39 -import org.onosproject.event.ListenerRegistry;
40 -import org.onosproject.event.EventDeliveryService;
41 import org.onosproject.net.Device; 40 import org.onosproject.net.Device;
42 import org.onosproject.net.DeviceId; 41 import org.onosproject.net.DeviceId;
43 import org.onosproject.net.device.DeviceService; 42 import org.onosproject.net.device.DeviceService;
...@@ -60,7 +59,6 @@ import org.onosproject.net.flow.FlowRuleProviderService; ...@@ -60,7 +59,6 @@ import org.onosproject.net.flow.FlowRuleProviderService;
60 import org.onosproject.net.flow.FlowRuleService; 59 import org.onosproject.net.flow.FlowRuleService;
61 import org.onosproject.net.flow.FlowRuleStore; 60 import org.onosproject.net.flow.FlowRuleStore;
62 import org.onosproject.net.flow.FlowRuleStoreDelegate; 61 import org.onosproject.net.flow.FlowRuleStoreDelegate;
63 -import org.onosproject.net.provider.AbstractProviderRegistry;
64 import org.onosproject.net.provider.AbstractProviderService; 62 import org.onosproject.net.provider.AbstractProviderService;
65 import org.osgi.service.component.ComponentContext; 63 import org.osgi.service.component.ComponentContext;
66 import org.slf4j.Logger; 64 import org.slf4j.Logger;
...@@ -77,8 +75,10 @@ import java.util.concurrent.atomic.AtomicBoolean; ...@@ -77,8 +75,10 @@ import java.util.concurrent.atomic.AtomicBoolean;
77 75
78 import static com.google.common.base.Preconditions.checkNotNull; 76 import static com.google.common.base.Preconditions.checkNotNull;
79 import static org.onlab.util.Tools.groupedThreads; 77 import static org.onlab.util.Tools.groupedThreads;
80 -import static org.slf4j.LoggerFactory.getLogger; 78 +import static org.onosproject.net.flow.FlowRuleEvent.Type.RULE_ADD_REQUESTED;
79 +import static org.onosproject.net.flow.FlowRuleEvent.Type.RULE_REMOVE_REQUESTED;
81 import static org.onosproject.security.AppGuard.checkPermission; 80 import static org.onosproject.security.AppGuard.checkPermission;
81 +import static org.slf4j.LoggerFactory.getLogger;
82 82
83 83
84 /** 84 /**
...@@ -87,7 +87,8 @@ import static org.onosproject.security.AppGuard.checkPermission; ...@@ -87,7 +87,8 @@ import static org.onosproject.security.AppGuard.checkPermission;
87 @Component(immediate = true, enabled = true) 87 @Component(immediate = true, enabled = true)
88 @Service 88 @Service
89 public class FlowRuleManager 89 public class FlowRuleManager
90 - extends AbstractProviderRegistry<FlowRuleProvider, FlowRuleProviderService> 90 + extends AbstractListenerProviderRegistry<FlowRuleEvent, FlowRuleListener,
91 + FlowRuleProvider, FlowRuleProviderService>
91 implements FlowRuleService, FlowRuleProviderRegistry { 92 implements FlowRuleService, FlowRuleProviderRegistry {
92 93
93 public static final String FLOW_RULE_NULL = "FlowRule cannot be null"; 94 public static final String FLOW_RULE_NULL = "FlowRule cannot be null";
...@@ -99,9 +100,6 @@ public class FlowRuleManager ...@@ -99,9 +100,6 @@ public class FlowRuleManager
99 100
100 private final Logger log = getLogger(getClass()); 101 private final Logger log = getLogger(getClass());
101 102
102 - private final ListenerRegistry<FlowRuleEvent, FlowRuleListener>
103 - listenerRegistry = new ListenerRegistry<>();
104 -
105 private final FlowRuleStoreDelegate delegate = new InternalStoreDelegate(); 103 private final FlowRuleStoreDelegate delegate = new InternalStoreDelegate();
106 104
107 protected ExecutorService deviceInstallers = 105 protected ExecutorService deviceInstallers =
...@@ -119,9 +117,6 @@ public class FlowRuleManager ...@@ -119,9 +117,6 @@ public class FlowRuleManager
119 protected FlowRuleStore store; 117 protected FlowRuleStore store;
120 118
121 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 119 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
122 - protected EventDeliveryService eventDispatcher;
123 -
124 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
125 protected DeviceService deviceService; 120 protected DeviceService deviceService;
126 121
127 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 122 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
...@@ -171,14 +166,12 @@ public class FlowRuleManager ...@@ -171,14 +166,12 @@ public class FlowRuleManager
171 @Override 166 @Override
172 public int getFlowRuleCount() { 167 public int getFlowRuleCount() {
173 checkPermission(Permission.FLOWRULE_READ); 168 checkPermission(Permission.FLOWRULE_READ);
174 -
175 return store.getFlowRuleCount(); 169 return store.getFlowRuleCount();
176 } 170 }
177 171
178 @Override 172 @Override
179 public Iterable<FlowEntry> getFlowEntries(DeviceId deviceId) { 173 public Iterable<FlowEntry> getFlowEntries(DeviceId deviceId) {
180 checkPermission(Permission.FLOWRULE_READ); 174 checkPermission(Permission.FLOWRULE_READ);
181 -
182 return store.getFlowEntries(deviceId); 175 return store.getFlowEntries(deviceId);
183 } 176 }
184 177
...@@ -207,7 +200,6 @@ public class FlowRuleManager ...@@ -207,7 +200,6 @@ public class FlowRuleManager
207 @Override 200 @Override
208 public void removeFlowRulesById(ApplicationId id) { 201 public void removeFlowRulesById(ApplicationId id) {
209 checkPermission(Permission.FLOWRULE_WRITE); 202 checkPermission(Permission.FLOWRULE_WRITE);
210 -
211 removeFlowRules(Iterables.toArray(getFlowRulesById(id), FlowRule.class)); 203 removeFlowRules(Iterables.toArray(getFlowRulesById(id), FlowRule.class));
212 } 204 }
213 205
...@@ -245,25 +237,10 @@ public class FlowRuleManager ...@@ -245,25 +237,10 @@ public class FlowRuleManager
245 @Override 237 @Override
246 public void apply(FlowRuleOperations ops) { 238 public void apply(FlowRuleOperations ops) {
247 checkPermission(Permission.FLOWRULE_WRITE); 239 checkPermission(Permission.FLOWRULE_WRITE);
248 -
249 operationsService.submit(new FlowOperationsProcessor(ops)); 240 operationsService.submit(new FlowOperationsProcessor(ops));
250 } 241 }
251 242
252 @Override 243 @Override
253 - public void addListener(FlowRuleListener listener) {
254 - checkPermission(Permission.FLOWRULE_EVENT);
255 -
256 - listenerRegistry.addListener(listener);
257 - }
258 -
259 - @Override
260 - public void removeListener(FlowRuleListener listener) {
261 - checkPermission(Permission.FLOWRULE_EVENT);
262 -
263 - listenerRegistry.removeListener(listener);
264 - }
265 -
266 - @Override
267 protected FlowRuleProviderService createProviderService( 244 protected FlowRuleProviderService createProviderService(
268 FlowRuleProvider provider) { 245 FlowRuleProvider provider) {
269 return new InternalFlowRuleProviderService(provider); 246 return new InternalFlowRuleProviderService(provider);
...@@ -408,13 +385,6 @@ public class FlowRuleManager ...@@ -408,13 +385,6 @@ public class FlowRuleManager
408 return false; 385 return false;
409 } 386 }
410 387
411 - // Posts the specified event to the local event dispatcher.
412 - private void post(FlowRuleEvent event) {
413 - if (event != null) {
414 - eventDispatcher.post(event);
415 - }
416 - }
417 -
418 @Override 388 @Override
419 public void pushFlowMetrics(DeviceId deviceId, Iterable<FlowEntry> flowEntries) { 389 public void pushFlowMetrics(DeviceId deviceId, Iterable<FlowEntry> flowEntries) {
420 Set<FlowEntry> storedRules = Sets.newHashSet(store.getFlowEntries(deviceId)); 390 Set<FlowEntry> storedRules = Sets.newHashSet(store.getFlowEntries(deviceId));
...@@ -473,16 +443,12 @@ public class FlowRuleManager ...@@ -473,16 +443,12 @@ public class FlowRuleManager
473 switch (op.operator()) { 443 switch (op.operator()) {
474 444
475 case ADD: 445 case ADD:
476 - eventDispatcher.post( 446 + post(new FlowRuleEvent(RULE_ADD_REQUESTED,
477 - new FlowRuleEvent( 447 + op.target()));
478 - FlowRuleEvent.Type.RULE_ADD_REQUESTED,
479 - op.target()));
480 break; 448 break;
481 case REMOVE: 449 case REMOVE:
482 - eventDispatcher.post( 450 + post(new FlowRuleEvent(RULE_REMOVE_REQUESTED,
483 - new FlowRuleEvent( 451 + op.target()));
484 - FlowRuleEvent.Type.RULE_REMOVE_REQUESTED,
485 - op.target()));
486 break; 452 break;
487 case MODIFY: 453 case MODIFY:
488 //TODO: do something here when the time comes. 454 //TODO: do something here when the time comes.
......
...@@ -24,9 +24,8 @@ import org.apache.felix.scr.annotations.Service; ...@@ -24,9 +24,8 @@ import org.apache.felix.scr.annotations.Service;
24 import org.onlab.packet.IpAddress; 24 import org.onlab.packet.IpAddress;
25 import org.onlab.packet.MacAddress; 25 import org.onlab.packet.MacAddress;
26 import org.onlab.packet.VlanId; 26 import org.onlab.packet.VlanId;
27 +import org.onosproject.net.provider.AbstractListenerProviderRegistry;
27 import org.onosproject.core.Permission; 28 import org.onosproject.core.Permission;
28 -import org.onosproject.event.EventDeliveryService;
29 -import org.onosproject.event.ListenerRegistry;
30 import org.onosproject.incubator.net.config.NetworkConfigEvent; 29 import org.onosproject.incubator.net.config.NetworkConfigEvent;
31 import org.onosproject.incubator.net.config.NetworkConfigListener; 30 import org.onosproject.incubator.net.config.NetworkConfigListener;
32 import org.onosproject.incubator.net.config.NetworkConfigService; 31 import org.onosproject.incubator.net.config.NetworkConfigService;
...@@ -51,7 +50,6 @@ import org.onosproject.net.host.HostStore; ...@@ -51,7 +50,6 @@ import org.onosproject.net.host.HostStore;
51 import org.onosproject.net.host.HostStoreDelegate; 50 import org.onosproject.net.host.HostStoreDelegate;
52 import org.onosproject.net.host.PortAddresses; 51 import org.onosproject.net.host.PortAddresses;
53 import org.onosproject.net.packet.PacketService; 52 import org.onosproject.net.packet.PacketService;
54 -import org.onosproject.net.provider.AbstractProviderRegistry;
55 import org.onosproject.net.provider.AbstractProviderService; 53 import org.onosproject.net.provider.AbstractProviderService;
56 import org.slf4j.Logger; 54 import org.slf4j.Logger;
57 55
...@@ -59,9 +57,8 @@ import java.util.Set; ...@@ -59,9 +57,8 @@ import java.util.Set;
59 57
60 import static com.google.common.base.Preconditions.checkNotNull; 58 import static com.google.common.base.Preconditions.checkNotNull;
61 import static com.google.common.base.Preconditions.checkState; 59 import static com.google.common.base.Preconditions.checkState;
62 -import static org.slf4j.LoggerFactory.getLogger;
63 import static org.onosproject.security.AppGuard.checkPermission; 60 import static org.onosproject.security.AppGuard.checkPermission;
64 - 61 +import static org.slf4j.LoggerFactory.getLogger;
65 62
66 /** 63 /**
67 * Provides basic implementation of the host SB &amp; NB APIs. 64 * Provides basic implementation of the host SB &amp; NB APIs.
...@@ -69,14 +66,12 @@ import static org.onosproject.security.AppGuard.checkPermission; ...@@ -69,14 +66,12 @@ import static org.onosproject.security.AppGuard.checkPermission;
69 @Component(immediate = true) 66 @Component(immediate = true)
70 @Service 67 @Service
71 public class HostManager 68 public class HostManager
72 - extends AbstractProviderRegistry<HostProvider, HostProviderService> 69 + extends AbstractListenerProviderRegistry<HostEvent, HostListener, HostProvider, HostProviderService>
73 implements HostService, HostAdminService, HostProviderRegistry { 70 implements HostService, HostAdminService, HostProviderRegistry {
74 71
75 - public static final String HOST_ID_NULL = "Host ID cannot be null";
76 private final Logger log = getLogger(getClass()); 72 private final Logger log = getLogger(getClass());
77 73
78 - private final ListenerRegistry<HostEvent, HostListener> 74 + public static final String HOST_ID_NULL = "Host ID cannot be null";
79 - listenerRegistry = new ListenerRegistry<>();
80 75
81 private final NetworkConfigListener networkConfigListener = new InternalNetworkConfigListener(); 76 private final NetworkConfigListener networkConfigListener = new InternalNetworkConfigListener();
82 77
...@@ -86,9 +81,6 @@ public class HostManager ...@@ -86,9 +81,6 @@ public class HostManager
86 protected HostStore store; 81 protected HostStore store;
87 82
88 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 83 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
89 - protected EventDeliveryService eventDispatcher;
90 -
91 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
92 protected DeviceService deviceService; 84 protected DeviceService deviceService;
93 85
94 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 86 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
...@@ -101,12 +93,12 @@ public class HostManager ...@@ -101,12 +93,12 @@ public class HostManager
101 93
102 @Activate 94 @Activate
103 public void activate() { 95 public void activate() {
104 - log.info("Started");
105 store.setDelegate(delegate); 96 store.setDelegate(delegate);
106 eventDispatcher.addSink(HostEvent.class, listenerRegistry); 97 eventDispatcher.addSink(HostEvent.class, listenerRegistry);
107 networkConfigService.addListener(networkConfigListener); 98 networkConfigService.addListener(networkConfigListener);
108 - monitor = new HostMonitor(deviceService, packetService, this); 99 + monitor = new HostMonitor(deviceService, packetService, this);
109 monitor.start(); 100 monitor.start();
101 + log.info("Started");
110 } 102 }
111 103
112 @Deactivate 104 @Deactivate
...@@ -120,28 +112,24 @@ public class HostManager ...@@ -120,28 +112,24 @@ public class HostManager
120 @Override 112 @Override
121 protected HostProviderService createProviderService(HostProvider provider) { 113 protected HostProviderService createProviderService(HostProvider provider) {
122 monitor.registerHostProvider(provider); 114 monitor.registerHostProvider(provider);
123 -
124 return new InternalHostProviderService(provider); 115 return new InternalHostProviderService(provider);
125 } 116 }
126 117
127 @Override 118 @Override
128 public int getHostCount() { 119 public int getHostCount() {
129 checkPermission(Permission.HOST_READ); 120 checkPermission(Permission.HOST_READ);
130 -
131 return store.getHostCount(); 121 return store.getHostCount();
132 } 122 }
133 123
134 @Override 124 @Override
135 public Iterable<Host> getHosts() { 125 public Iterable<Host> getHosts() {
136 checkPermission(Permission.HOST_READ); 126 checkPermission(Permission.HOST_READ);
137 -
138 return store.getHosts(); 127 return store.getHosts();
139 } 128 }
140 129
141 @Override 130 @Override
142 public Host getHost(HostId hostId) { 131 public Host getHost(HostId hostId) {
143 checkPermission(Permission.HOST_READ); 132 checkPermission(Permission.HOST_READ);
144 -
145 checkNotNull(hostId, HOST_ID_NULL); 133 checkNotNull(hostId, HOST_ID_NULL);
146 return store.getHost(hostId); 134 return store.getHost(hostId);
147 } 135 }
...@@ -149,14 +137,12 @@ public class HostManager ...@@ -149,14 +137,12 @@ public class HostManager
149 @Override 137 @Override
150 public Set<Host> getHostsByVlan(VlanId vlanId) { 138 public Set<Host> getHostsByVlan(VlanId vlanId) {
151 checkPermission(Permission.HOST_READ); 139 checkPermission(Permission.HOST_READ);
152 -
153 return store.getHosts(vlanId); 140 return store.getHosts(vlanId);
154 } 141 }
155 142
156 @Override 143 @Override
157 public Set<Host> getHostsByMac(MacAddress mac) { 144 public Set<Host> getHostsByMac(MacAddress mac) {
158 checkPermission(Permission.HOST_READ); 145 checkPermission(Permission.HOST_READ);
159 -
160 checkNotNull(mac, "MAC address cannot be null"); 146 checkNotNull(mac, "MAC address cannot be null");
161 return store.getHosts(mac); 147 return store.getHosts(mac);
162 } 148 }
...@@ -164,7 +150,6 @@ public class HostManager ...@@ -164,7 +150,6 @@ public class HostManager
164 @Override 150 @Override
165 public Set<Host> getHostsByIp(IpAddress ip) { 151 public Set<Host> getHostsByIp(IpAddress ip) {
166 checkPermission(Permission.HOST_READ); 152 checkPermission(Permission.HOST_READ);
167 -
168 checkNotNull(ip, "IP address cannot be null"); 153 checkNotNull(ip, "IP address cannot be null");
169 return store.getHosts(ip); 154 return store.getHosts(ip);
170 } 155 }
...@@ -172,7 +157,6 @@ public class HostManager ...@@ -172,7 +157,6 @@ public class HostManager
172 @Override 157 @Override
173 public Set<Host> getConnectedHosts(ConnectPoint connectPoint) { 158 public Set<Host> getConnectedHosts(ConnectPoint connectPoint) {
174 checkPermission(Permission.HOST_READ); 159 checkPermission(Permission.HOST_READ);
175 -
176 checkNotNull(connectPoint, "Connection point cannot be null"); 160 checkNotNull(connectPoint, "Connection point cannot be null");
177 return store.getConnectedHosts(connectPoint); 161 return store.getConnectedHosts(connectPoint);
178 } 162 }
...@@ -180,7 +164,6 @@ public class HostManager ...@@ -180,7 +164,6 @@ public class HostManager
180 @Override 164 @Override
181 public Set<Host> getConnectedHosts(DeviceId deviceId) { 165 public Set<Host> getConnectedHosts(DeviceId deviceId) {
182 checkPermission(Permission.HOST_READ); 166 checkPermission(Permission.HOST_READ);
183 -
184 checkNotNull(deviceId, "Device ID cannot be null"); 167 checkNotNull(deviceId, "Device ID cannot be null");
185 return store.getConnectedHosts(deviceId); 168 return store.getConnectedHosts(deviceId);
186 } 169 }
...@@ -188,34 +171,18 @@ public class HostManager ...@@ -188,34 +171,18 @@ public class HostManager
188 @Override 171 @Override
189 public void startMonitoringIp(IpAddress ip) { 172 public void startMonitoringIp(IpAddress ip) {
190 checkPermission(Permission.HOST_EVENT); 173 checkPermission(Permission.HOST_EVENT);
191 -
192 monitor.addMonitoringFor(ip); 174 monitor.addMonitoringFor(ip);
193 } 175 }
194 176
195 @Override 177 @Override
196 public void stopMonitoringIp(IpAddress ip) { 178 public void stopMonitoringIp(IpAddress ip) {
197 checkPermission(Permission.HOST_EVENT); 179 checkPermission(Permission.HOST_EVENT);
198 -
199 monitor.stopMonitoring(ip); 180 monitor.stopMonitoring(ip);
200 } 181 }
201 182
202 @Override 183 @Override
203 public void requestMac(IpAddress ip) { 184 public void requestMac(IpAddress ip) {
204 - // TODO Auto-generated method stub 185 + // FIXME!!!! Auto-generated method stub
205 - }
206 -
207 - @Override
208 - public void addListener(HostListener listener) {
209 - checkPermission(Permission.HOST_EVENT);
210 -
211 - listenerRegistry.addListener(listener);
212 - }
213 -
214 - @Override
215 - public void removeListener(HostListener listener) {
216 - checkPermission(Permission.HOST_EVENT);
217 -
218 - listenerRegistry.removeListener(listener);
219 } 186 }
220 187
221 @Override 188 @Override
...@@ -245,14 +212,12 @@ public class HostManager ...@@ -245,14 +212,12 @@ public class HostManager
245 @Override 212 @Override
246 public Set<PortAddresses> getAddressBindings() { 213 public Set<PortAddresses> getAddressBindings() {
247 checkPermission(Permission.HOST_READ); 214 checkPermission(Permission.HOST_READ);
248 -
249 return store.getAddressBindings(); 215 return store.getAddressBindings();
250 } 216 }
251 217
252 @Override 218 @Override
253 public Set<PortAddresses> getAddressBindingsForPort(ConnectPoint connectPoint) { 219 public Set<PortAddresses> getAddressBindingsForPort(ConnectPoint connectPoint) {
254 checkPermission(Permission.HOST_READ); 220 checkPermission(Permission.HOST_READ);
255 -
256 return store.getAddressBindingsForPort(connectPoint); 221 return store.getAddressBindingsForPort(connectPoint);
257 } 222 }
258 223
...@@ -326,13 +291,6 @@ public class HostManager ...@@ -326,13 +291,6 @@ public class HostManager
326 return DefaultAnnotations.union(originalAnnotations, newAnnotations); 291 return DefaultAnnotations.union(originalAnnotations, newAnnotations);
327 } 292 }
328 293
329 - // Posts the specified event to the local event dispatcher.
330 - private void post(HostEvent event) {
331 - if (event != null) {
332 - eventDispatcher.post(event);
333 - }
334 - }
335 -
336 // Store delegate to re-post events emitted from the store. 294 // Store delegate to re-post events emitted from the store.
337 private class InternalStoreDelegate implements HostStoreDelegate { 295 private class InternalStoreDelegate implements HostStoreDelegate {
338 @Override 296 @Override
......
...@@ -22,11 +22,10 @@ import org.apache.felix.scr.annotations.Deactivate; ...@@ -22,11 +22,10 @@ import org.apache.felix.scr.annotations.Deactivate;
22 import org.apache.felix.scr.annotations.Reference; 22 import org.apache.felix.scr.annotations.Reference;
23 import org.apache.felix.scr.annotations.ReferenceCardinality; 23 import org.apache.felix.scr.annotations.ReferenceCardinality;
24 import org.apache.felix.scr.annotations.Service; 24 import org.apache.felix.scr.annotations.Service;
25 +import org.onosproject.event.AbstractListenerManager;
25 import org.onosproject.core.CoreService; 26 import org.onosproject.core.CoreService;
26 import org.onosproject.core.IdGenerator; 27 import org.onosproject.core.IdGenerator;
27 import org.onosproject.core.Permission; 28 import org.onosproject.core.Permission;
28 -import org.onosproject.event.ListenerRegistry;
29 -import org.onosproject.event.EventDeliveryService;
30 import org.onosproject.net.flow.FlowRule; 29 import org.onosproject.net.flow.FlowRule;
31 import org.onosproject.net.flow.FlowRuleOperations; 30 import org.onosproject.net.flow.FlowRuleOperations;
32 import org.onosproject.net.flow.FlowRuleOperationsContext; 31 import org.onosproject.net.flow.FlowRuleOperationsContext;
...@@ -65,9 +64,8 @@ import static java.util.concurrent.Executors.newSingleThreadExecutor; ...@@ -65,9 +64,8 @@ import static java.util.concurrent.Executors.newSingleThreadExecutor;
65 import static org.onlab.util.Tools.groupedThreads; 64 import static org.onlab.util.Tools.groupedThreads;
66 import static org.onosproject.net.intent.IntentState.*; 65 import static org.onosproject.net.intent.IntentState.*;
67 import static org.onosproject.net.intent.impl.phase.IntentProcessPhase.newInitialPhase; 66 import static org.onosproject.net.intent.impl.phase.IntentProcessPhase.newInitialPhase;
68 -import static org.slf4j.LoggerFactory.getLogger;
69 import static org.onosproject.security.AppGuard.checkPermission; 67 import static org.onosproject.security.AppGuard.checkPermission;
70 - 68 +import static org.slf4j.LoggerFactory.getLogger;
71 69
72 /** 70 /**
73 * An implementation of intent service. 71 * An implementation of intent service.
...@@ -75,7 +73,9 @@ import static org.onosproject.security.AppGuard.checkPermission; ...@@ -75,7 +73,9 @@ import static org.onosproject.security.AppGuard.checkPermission;
75 @Component(immediate = true) 73 @Component(immediate = true)
76 @Service 74 @Service
77 public class IntentManager 75 public class IntentManager
76 + extends AbstractListenerManager<IntentEvent, IntentListener>
78 implements IntentService, IntentExtensionService { 77 implements IntentService, IntentExtensionService {
78 +
79 private static final Logger log = getLogger(IntentManager.class); 79 private static final Logger log = getLogger(IntentManager.class);
80 80
81 public static final String INTENT_NULL = "Intent cannot be null"; 81 public static final String INTENT_NULL = "Intent cannot be null";
...@@ -86,9 +86,6 @@ public class IntentManager ...@@ -86,9 +86,6 @@ public class IntentManager
86 private static final EnumSet<IntentState> RECOMPILE 86 private static final EnumSet<IntentState> RECOMPILE
87 = EnumSet.of(INSTALL_REQ, FAILED, WITHDRAW_REQ); 87 = EnumSet.of(INSTALL_REQ, FAILED, WITHDRAW_REQ);
88 88
89 - private final ListenerRegistry<IntentEvent, IntentListener>
90 - listenerRegistry = new ListenerRegistry<>();
91 -
92 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 89 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
93 protected CoreService coreService; 90 protected CoreService coreService;
94 91
...@@ -99,12 +96,8 @@ public class IntentManager ...@@ -99,12 +96,8 @@ public class IntentManager
99 protected ObjectiveTrackerService trackerService; 96 protected ObjectiveTrackerService trackerService;
100 97
101 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 98 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
102 - protected EventDeliveryService eventDispatcher;
103 -
104 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
105 protected FlowRuleService flowRuleService; 99 protected FlowRuleService flowRuleService;
106 100
107 -
108 private ExecutorService batchExecutor; 101 private ExecutorService batchExecutor;
109 private ExecutorService workerExecutor; 102 private ExecutorService workerExecutor;
110 103
...@@ -143,7 +136,6 @@ public class IntentManager ...@@ -143,7 +136,6 @@ public class IntentManager
143 @Override 136 @Override
144 public void submit(Intent intent) { 137 public void submit(Intent intent) {
145 checkPermission(Permission.INTENT_WRITE); 138 checkPermission(Permission.INTENT_WRITE);
146 -
147 checkNotNull(intent, INTENT_NULL); 139 checkNotNull(intent, INTENT_NULL);
148 IntentData data = new IntentData(intent, IntentState.INSTALL_REQ, null); 140 IntentData data = new IntentData(intent, IntentState.INSTALL_REQ, null);
149 store.addPending(data); 141 store.addPending(data);
...@@ -152,7 +144,6 @@ public class IntentManager ...@@ -152,7 +144,6 @@ public class IntentManager
152 @Override 144 @Override
153 public void withdraw(Intent intent) { 145 public void withdraw(Intent intent) {
154 checkPermission(Permission.INTENT_WRITE); 146 checkPermission(Permission.INTENT_WRITE);
155 -
156 checkNotNull(intent, INTENT_NULL); 147 checkNotNull(intent, INTENT_NULL);
157 IntentData data = new IntentData(intent, IntentState.WITHDRAW_REQ, null); 148 IntentData data = new IntentData(intent, IntentState.WITHDRAW_REQ, null);
158 store.addPending(data); 149 store.addPending(data);
...@@ -161,7 +152,6 @@ public class IntentManager ...@@ -161,7 +152,6 @@ public class IntentManager
161 @Override 152 @Override
162 public void purge(Intent intent) { 153 public void purge(Intent intent) {
163 checkPermission(Permission.INTENT_WRITE); 154 checkPermission(Permission.INTENT_WRITE);
164 -
165 checkNotNull(intent, INTENT_NULL); 155 checkNotNull(intent, INTENT_NULL);
166 IntentData data = new IntentData(intent, IntentState.PURGE_REQ, null); 156 IntentData data = new IntentData(intent, IntentState.PURGE_REQ, null);
167 store.addPending(data); 157 store.addPending(data);
...@@ -170,14 +160,12 @@ public class IntentManager ...@@ -170,14 +160,12 @@ public class IntentManager
170 @Override 160 @Override
171 public Intent getIntent(Key key) { 161 public Intent getIntent(Key key) {
172 checkPermission(Permission.INTENT_READ); 162 checkPermission(Permission.INTENT_READ);
173 -
174 return store.getIntent(key); 163 return store.getIntent(key);
175 } 164 }
176 165
177 @Override 166 @Override
178 public Iterable<Intent> getIntents() { 167 public Iterable<Intent> getIntents() {
179 checkPermission(Permission.INTENT_READ); 168 checkPermission(Permission.INTENT_READ);
180 -
181 return store.getIntents(); 169 return store.getIntents();
182 } 170 }
183 171
...@@ -190,14 +178,12 @@ public class IntentManager ...@@ -190,14 +178,12 @@ public class IntentManager
190 @Override 178 @Override
191 public long getIntentCount() { 179 public long getIntentCount() {
192 checkPermission(Permission.INTENT_READ); 180 checkPermission(Permission.INTENT_READ);
193 -
194 return store.getIntentCount(); 181 return store.getIntentCount();
195 } 182 }
196 183
197 @Override 184 @Override
198 public IntentState getIntentState(Key intentKey) { 185 public IntentState getIntentState(Key intentKey) {
199 checkPermission(Permission.INTENT_READ); 186 checkPermission(Permission.INTENT_READ);
200 -
201 checkNotNull(intentKey, INTENT_ID_NULL); 187 checkNotNull(intentKey, INTENT_ID_NULL);
202 return store.getIntentState(intentKey); 188 return store.getIntentState(intentKey);
203 } 189 }
...@@ -205,7 +191,6 @@ public class IntentManager ...@@ -205,7 +191,6 @@ public class IntentManager
205 @Override 191 @Override
206 public List<Intent> getInstallableIntents(Key intentKey) { 192 public List<Intent> getInstallableIntents(Key intentKey) {
207 checkPermission(Permission.INTENT_READ); 193 checkPermission(Permission.INTENT_READ);
208 -
209 checkNotNull(intentKey, INTENT_ID_NULL); 194 checkNotNull(intentKey, INTENT_ID_NULL);
210 return store.getInstallableIntents(intentKey); 195 return store.getInstallableIntents(intentKey);
211 } 196 }
...@@ -213,25 +198,10 @@ public class IntentManager ...@@ -213,25 +198,10 @@ public class IntentManager
213 @Override 198 @Override
214 public boolean isLocal(Key intentKey) { 199 public boolean isLocal(Key intentKey) {
215 checkPermission(Permission.INTENT_READ); 200 checkPermission(Permission.INTENT_READ);
216 -
217 return store.isMaster(intentKey); 201 return store.isMaster(intentKey);
218 } 202 }
219 203
220 @Override 204 @Override
221 - public void addListener(IntentListener listener) {
222 - checkPermission(Permission.INTENT_EVENT);
223 -
224 - listenerRegistry.addListener(listener);
225 - }
226 -
227 - @Override
228 - public void removeListener(IntentListener listener) {
229 - checkPermission(Permission.INTENT_EVENT);
230 -
231 - listenerRegistry.removeListener(listener);
232 - }
233 -
234 - @Override
235 public <T extends Intent> void registerCompiler(Class<T> cls, IntentCompiler<T> compiler) { 205 public <T extends Intent> void registerCompiler(Class<T> cls, IntentCompiler<T> compiler) {
236 compilerRegistry.registerCompiler(cls, compiler); 206 compilerRegistry.registerCompiler(cls, compiler);
237 } 207 }
...@@ -257,7 +227,7 @@ public class IntentManager ...@@ -257,7 +227,7 @@ public class IntentManager
257 private class InternalStoreDelegate implements IntentStoreDelegate { 227 private class InternalStoreDelegate implements IntentStoreDelegate {
258 @Override 228 @Override
259 public void notify(IntentEvent event) { 229 public void notify(IntentEvent event) {
260 - eventDispatcher.post(event); 230 + post(event);
261 } 231 }
262 232
263 @Override 233 @Override
......
...@@ -24,9 +24,8 @@ import org.apache.felix.scr.annotations.Deactivate; ...@@ -24,9 +24,8 @@ import org.apache.felix.scr.annotations.Deactivate;
24 import org.apache.felix.scr.annotations.Reference; 24 import org.apache.felix.scr.annotations.Reference;
25 import org.apache.felix.scr.annotations.ReferenceCardinality; 25 import org.apache.felix.scr.annotations.ReferenceCardinality;
26 import org.apache.felix.scr.annotations.Service; 26 import org.apache.felix.scr.annotations.Service;
27 +import org.onosproject.net.provider.AbstractListenerProviderRegistry;
27 import org.onosproject.core.Permission; 28 import org.onosproject.core.Permission;
28 -import org.onosproject.event.EventDeliveryService;
29 -import org.onosproject.event.ListenerRegistry;
30 import org.onosproject.incubator.net.config.NetworkConfigEvent; 29 import org.onosproject.incubator.net.config.NetworkConfigEvent;
31 import org.onosproject.incubator.net.config.NetworkConfigListener; 30 import org.onosproject.incubator.net.config.NetworkConfigListener;
32 import org.onosproject.incubator.net.config.NetworkConfigService; 31 import org.onosproject.incubator.net.config.NetworkConfigService;
...@@ -53,7 +52,6 @@ import org.onosproject.net.link.LinkProviderService; ...@@ -53,7 +52,6 @@ import org.onosproject.net.link.LinkProviderService;
53 import org.onosproject.net.link.LinkService; 52 import org.onosproject.net.link.LinkService;
54 import org.onosproject.net.link.LinkStore; 53 import org.onosproject.net.link.LinkStore;
55 import org.onosproject.net.link.LinkStoreDelegate; 54 import org.onosproject.net.link.LinkStoreDelegate;
56 -import org.onosproject.net.provider.AbstractProviderRegistry;
57 import org.onosproject.net.provider.AbstractProviderService; 55 import org.onosproject.net.provider.AbstractProviderService;
58 import org.slf4j.Logger; 56 import org.slf4j.Logger;
59 57
...@@ -63,8 +61,8 @@ import java.util.Set; ...@@ -63,8 +61,8 @@ import java.util.Set;
63 import static com.google.common.base.Preconditions.checkNotNull; 61 import static com.google.common.base.Preconditions.checkNotNull;
64 import static com.google.common.base.Preconditions.checkState; 62 import static com.google.common.base.Preconditions.checkState;
65 import static org.onosproject.net.LinkKey.linkKey; 63 import static org.onosproject.net.LinkKey.linkKey;
66 -import static org.slf4j.LoggerFactory.getLogger;
67 import static org.onosproject.security.AppGuard.checkPermission; 64 import static org.onosproject.security.AppGuard.checkPermission;
65 +import static org.slf4j.LoggerFactory.getLogger;
68 66
69 67
70 /** 68 /**
...@@ -73,7 +71,7 @@ import static org.onosproject.security.AppGuard.checkPermission; ...@@ -73,7 +71,7 @@ import static org.onosproject.security.AppGuard.checkPermission;
73 @Component(immediate = true) 71 @Component(immediate = true)
74 @Service 72 @Service
75 public class LinkManager 73 public class LinkManager
76 - extends AbstractProviderRegistry<LinkProvider, LinkProviderService> 74 + extends AbstractListenerProviderRegistry<LinkEvent, LinkListener, LinkProvider, LinkProviderService>
77 implements LinkService, LinkAdminService, LinkProviderRegistry { 75 implements LinkService, LinkAdminService, LinkProviderRegistry {
78 76
79 private static final String DEVICE_ID_NULL = "Device ID cannot be null"; 77 private static final String DEVICE_ID_NULL = "Device ID cannot be null";
...@@ -82,9 +80,6 @@ public class LinkManager ...@@ -82,9 +80,6 @@ public class LinkManager
82 80
83 private final Logger log = getLogger(getClass()); 81 private final Logger log = getLogger(getClass());
84 82
85 - protected final ListenerRegistry<LinkEvent, LinkListener>
86 - listenerRegistry = new ListenerRegistry<>();
87 -
88 private final LinkStoreDelegate delegate = new InternalStoreDelegate(); 83 private final LinkStoreDelegate delegate = new InternalStoreDelegate();
89 84
90 private final DeviceListener deviceListener = new InternalDeviceListener(); 85 private final DeviceListener deviceListener = new InternalDeviceListener();
...@@ -98,9 +93,6 @@ public class LinkManager ...@@ -98,9 +93,6 @@ public class LinkManager
98 protected DeviceService deviceService; 93 protected DeviceService deviceService;
99 94
100 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 95 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
101 - protected EventDeliveryService eventDispatcher;
102 -
103 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
104 protected NetworkConfigService networkConfigService; 96 protected NetworkConfigService networkConfigService;
105 97
106 @Activate 98 @Activate
...@@ -124,21 +116,18 @@ public class LinkManager ...@@ -124,21 +116,18 @@ public class LinkManager
124 @Override 116 @Override
125 public int getLinkCount() { 117 public int getLinkCount() {
126 checkPermission(Permission.LINK_READ); 118 checkPermission(Permission.LINK_READ);
127 -
128 return store.getLinkCount(); 119 return store.getLinkCount();
129 } 120 }
130 121
131 @Override 122 @Override
132 public Iterable<Link> getLinks() { 123 public Iterable<Link> getLinks() {
133 checkPermission(Permission.LINK_READ); 124 checkPermission(Permission.LINK_READ);
134 -
135 return store.getLinks(); 125 return store.getLinks();
136 } 126 }
137 127
138 @Override 128 @Override
139 public Iterable<Link> getActiveLinks() { 129 public Iterable<Link> getActiveLinks() {
140 checkPermission(Permission.LINK_READ); 130 checkPermission(Permission.LINK_READ);
141 -
142 return FluentIterable.from(getLinks()) 131 return FluentIterable.from(getLinks())
143 .filter(new Predicate<Link>() { 132 .filter(new Predicate<Link>() {
144 133
...@@ -152,7 +141,6 @@ public class LinkManager ...@@ -152,7 +141,6 @@ public class LinkManager
152 @Override 141 @Override
153 public Set<Link> getDeviceLinks(DeviceId deviceId) { 142 public Set<Link> getDeviceLinks(DeviceId deviceId) {
154 checkPermission(Permission.LINK_READ); 143 checkPermission(Permission.LINK_READ);
155 -
156 checkNotNull(deviceId, DEVICE_ID_NULL); 144 checkNotNull(deviceId, DEVICE_ID_NULL);
157 return Sets.union(store.getDeviceEgressLinks(deviceId), 145 return Sets.union(store.getDeviceEgressLinks(deviceId),
158 store.getDeviceIngressLinks(deviceId)); 146 store.getDeviceIngressLinks(deviceId));
...@@ -161,7 +149,6 @@ public class LinkManager ...@@ -161,7 +149,6 @@ public class LinkManager
161 @Override 149 @Override
162 public Set<Link> getDeviceEgressLinks(DeviceId deviceId) { 150 public Set<Link> getDeviceEgressLinks(DeviceId deviceId) {
163 checkPermission(Permission.LINK_READ); 151 checkPermission(Permission.LINK_READ);
164 -
165 checkNotNull(deviceId, DEVICE_ID_NULL); 152 checkNotNull(deviceId, DEVICE_ID_NULL);
166 return store.getDeviceEgressLinks(deviceId); 153 return store.getDeviceEgressLinks(deviceId);
167 } 154 }
...@@ -169,7 +156,6 @@ public class LinkManager ...@@ -169,7 +156,6 @@ public class LinkManager
169 @Override 156 @Override
170 public Set<Link> getDeviceIngressLinks(DeviceId deviceId) { 157 public Set<Link> getDeviceIngressLinks(DeviceId deviceId) {
171 checkPermission(Permission.LINK_READ); 158 checkPermission(Permission.LINK_READ);
172 -
173 checkNotNull(deviceId, DEVICE_ID_NULL); 159 checkNotNull(deviceId, DEVICE_ID_NULL);
174 return store.getDeviceIngressLinks(deviceId); 160 return store.getDeviceIngressLinks(deviceId);
175 } 161 }
...@@ -177,7 +163,6 @@ public class LinkManager ...@@ -177,7 +163,6 @@ public class LinkManager
177 @Override 163 @Override
178 public Set<Link> getLinks(ConnectPoint connectPoint) { 164 public Set<Link> getLinks(ConnectPoint connectPoint) {
179 checkPermission(Permission.LINK_READ); 165 checkPermission(Permission.LINK_READ);
180 -
181 checkNotNull(connectPoint, CONNECT_POINT_NULL); 166 checkNotNull(connectPoint, CONNECT_POINT_NULL);
182 return Sets.union(store.getEgressLinks(connectPoint), 167 return Sets.union(store.getEgressLinks(connectPoint),
183 store.getIngressLinks(connectPoint)); 168 store.getIngressLinks(connectPoint));
...@@ -186,7 +171,6 @@ public class LinkManager ...@@ -186,7 +171,6 @@ public class LinkManager
186 @Override 171 @Override
187 public Set<Link> getEgressLinks(ConnectPoint connectPoint) { 172 public Set<Link> getEgressLinks(ConnectPoint connectPoint) {
188 checkPermission(Permission.LINK_READ); 173 checkPermission(Permission.LINK_READ);
189 -
190 checkNotNull(connectPoint, CONNECT_POINT_NULL); 174 checkNotNull(connectPoint, CONNECT_POINT_NULL);
191 return store.getEgressLinks(connectPoint); 175 return store.getEgressLinks(connectPoint);
192 } 176 }
...@@ -194,7 +178,6 @@ public class LinkManager ...@@ -194,7 +178,6 @@ public class LinkManager
194 @Override 178 @Override
195 public Set<Link> getIngressLinks(ConnectPoint connectPoint) { 179 public Set<Link> getIngressLinks(ConnectPoint connectPoint) {
196 checkPermission(Permission.LINK_READ); 180 checkPermission(Permission.LINK_READ);
197 -
198 checkNotNull(connectPoint, CONNECT_POINT_NULL); 181 checkNotNull(connectPoint, CONNECT_POINT_NULL);
199 return store.getIngressLinks(connectPoint); 182 return store.getIngressLinks(connectPoint);
200 } 183 }
...@@ -202,7 +185,6 @@ public class LinkManager ...@@ -202,7 +185,6 @@ public class LinkManager
202 @Override 185 @Override
203 public Link getLink(ConnectPoint src, ConnectPoint dst) { 186 public Link getLink(ConnectPoint src, ConnectPoint dst) {
204 checkPermission(Permission.LINK_READ); 187 checkPermission(Permission.LINK_READ);
205 -
206 checkNotNull(src, CONNECT_POINT_NULL); 188 checkNotNull(src, CONNECT_POINT_NULL);
207 checkNotNull(dst, CONNECT_POINT_NULL); 189 checkNotNull(dst, CONNECT_POINT_NULL);
208 return store.getLink(src, dst); 190 return store.getLink(src, dst);
...@@ -228,18 +210,6 @@ public class LinkManager ...@@ -228,18 +210,6 @@ public class LinkManager
228 post(store.removeLink(src, dst)); 210 post(store.removeLink(src, dst));
229 } 211 }
230 212
231 - @Override
232 - public void addListener(LinkListener listener) {
233 - checkPermission(Permission.LINK_EVENT);
234 - listenerRegistry.addListener(listener);
235 - }
236 -
237 - @Override
238 - public void removeListener(LinkListener listener) {
239 - checkPermission(Permission.LINK_EVENT);
240 - listenerRegistry.removeListener(listener);
241 - }
242 -
243 // Auxiliary interceptor for device remove events to prune links that 213 // Auxiliary interceptor for device remove events to prune links that
244 // are associated with the removed device or its port. 214 // are associated with the removed device or its port.
245 private class InternalDeviceListener implements DeviceListener { 215 private class InternalDeviceListener implements DeviceListener {
...@@ -376,13 +346,6 @@ public class LinkManager ...@@ -376,13 +346,6 @@ public class LinkManager
376 } 346 }
377 } 347 }
378 348
379 - // Posts the specified event to the local event dispatcher.
380 - private void post(LinkEvent event) {
381 - if (event != null) {
382 - eventDispatcher.post(event);
383 - }
384 - }
385 -
386 // Store delegate to re-post events emitted from the store. 349 // Store delegate to re-post events emitted from the store.
387 private class InternalStoreDelegate implements LinkStoreDelegate { 350 private class InternalStoreDelegate implements LinkStoreDelegate {
388 @Override 351 @Override
......
...@@ -22,11 +22,13 @@ import org.apache.felix.scr.annotations.Deactivate; ...@@ -22,11 +22,13 @@ import org.apache.felix.scr.annotations.Deactivate;
22 import org.apache.felix.scr.annotations.Reference; 22 import org.apache.felix.scr.annotations.Reference;
23 import org.apache.felix.scr.annotations.ReferenceCardinality; 23 import org.apache.felix.scr.annotations.ReferenceCardinality;
24 import org.apache.felix.scr.annotations.Service; 24 import org.apache.felix.scr.annotations.Service;
25 +import org.onosproject.event.AbstractListenerManager;
25 import org.onosproject.core.Permission; 26 import org.onosproject.core.Permission;
26 -import org.onosproject.event.ListenerRegistry;
27 -import org.onosproject.event.EventDeliveryService;
28 import org.onosproject.net.Link; 27 import org.onosproject.net.Link;
29 import org.onosproject.net.intent.IntentId; 28 import org.onosproject.net.intent.IntentId;
29 +import org.onosproject.net.resource.ResourceAllocation;
30 +import org.onosproject.net.resource.ResourceRequest;
31 +import org.onosproject.net.resource.ResourceType;
30 import org.onosproject.net.resource.link.BandwidthResourceAllocation; 32 import org.onosproject.net.resource.link.BandwidthResourceAllocation;
31 import org.onosproject.net.resource.link.BandwidthResourceRequest; 33 import org.onosproject.net.resource.link.BandwidthResourceRequest;
32 import org.onosproject.net.resource.link.DefaultLinkResourceAllocations; 34 import org.onosproject.net.resource.link.DefaultLinkResourceAllocations;
...@@ -43,9 +45,6 @@ import org.onosproject.net.resource.link.LinkResourceStoreDelegate; ...@@ -43,9 +45,6 @@ import org.onosproject.net.resource.link.LinkResourceStoreDelegate;
43 import org.onosproject.net.resource.link.MplsLabel; 45 import org.onosproject.net.resource.link.MplsLabel;
44 import org.onosproject.net.resource.link.MplsLabelResourceAllocation; 46 import org.onosproject.net.resource.link.MplsLabelResourceAllocation;
45 import org.onosproject.net.resource.link.MplsLabelResourceRequest; 47 import org.onosproject.net.resource.link.MplsLabelResourceRequest;
46 -import org.onosproject.net.resource.ResourceAllocation;
47 -import org.onosproject.net.resource.ResourceRequest;
48 -import org.onosproject.net.resource.ResourceType;
49 import org.slf4j.Logger; 48 import org.slf4j.Logger;
50 49
51 import java.util.Collections; 50 import java.util.Collections;
...@@ -57,8 +56,8 @@ import java.util.Set; ...@@ -57,8 +56,8 @@ import java.util.Set;
57 56
58 import static com.google.common.base.Preconditions.checkArgument; 57 import static com.google.common.base.Preconditions.checkArgument;
59 import static com.google.common.base.Preconditions.checkNotNull; 58 import static com.google.common.base.Preconditions.checkNotNull;
60 -import static org.slf4j.LoggerFactory.getLogger;
61 import static org.onosproject.security.AppGuard.checkPermission; 59 import static org.onosproject.security.AppGuard.checkPermission;
60 +import static org.slf4j.LoggerFactory.getLogger;
62 61
63 62
64 /** 63 /**
...@@ -66,19 +65,15 @@ import static org.onosproject.security.AppGuard.checkPermission; ...@@ -66,19 +65,15 @@ import static org.onosproject.security.AppGuard.checkPermission;
66 */ 65 */
67 @Component(immediate = true) 66 @Component(immediate = true)
68 @Service 67 @Service
69 -public class LinkResourceManager implements LinkResourceService { 68 +public class LinkResourceManager
69 + extends AbstractListenerManager<LinkResourceEvent, LinkResourceListener>
70 + implements LinkResourceService {
70 71
71 private final Logger log = getLogger(getClass()); 72 private final Logger log = getLogger(getClass());
72 73
73 - protected final ListenerRegistry<LinkResourceEvent, LinkResourceListener>
74 - listenerRegistry = new ListenerRegistry<>();
75 -
76 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 74 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
77 private LinkResourceStore store; 75 private LinkResourceStore store;
78 76
79 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
80 - protected EventDeliveryService eventDispatcher;
81 -
82 @Activate 77 @Activate
83 public void activate() { 78 public void activate() {
84 eventDispatcher.addSink(LinkResourceEvent.class, listenerRegistry); 79 eventDispatcher.addSink(LinkResourceEvent.class, listenerRegistry);
...@@ -87,6 +82,7 @@ public class LinkResourceManager implements LinkResourceService { ...@@ -87,6 +82,7 @@ public class LinkResourceManager implements LinkResourceService {
87 82
88 @Deactivate 83 @Deactivate
89 public void deactivate() { 84 public void deactivate() {
85 + eventDispatcher.removeSink(LinkResourceEvent.class);
90 log.info("Stopped"); 86 log.info("Stopped");
91 } 87 }
92 88
...@@ -218,7 +214,6 @@ public class LinkResourceManager implements LinkResourceService { ...@@ -218,7 +214,6 @@ public class LinkResourceManager implements LinkResourceService {
218 @Override 214 @Override
219 public void releaseResources(LinkResourceAllocations allocations) { 215 public void releaseResources(LinkResourceAllocations allocations) {
220 checkPermission(Permission.LINK_WRITE); 216 checkPermission(Permission.LINK_WRITE);
221 -
222 final LinkResourceEvent event = store.releaseResources(allocations); 217 final LinkResourceEvent event = store.releaseResources(allocations);
223 if (event != null) { 218 if (event != null) {
224 post(event); 219 post(event);
...@@ -229,7 +224,6 @@ public class LinkResourceManager implements LinkResourceService { ...@@ -229,7 +224,6 @@ public class LinkResourceManager implements LinkResourceService {
229 public LinkResourceAllocations updateResources(LinkResourceRequest req, 224 public LinkResourceAllocations updateResources(LinkResourceRequest req,
230 LinkResourceAllocations oldAllocations) { 225 LinkResourceAllocations oldAllocations) {
231 checkPermission(Permission.LINK_WRITE); 226 checkPermission(Permission.LINK_WRITE);
232 -
233 releaseResources(oldAllocations); 227 releaseResources(oldAllocations);
234 return requestResources(req); 228 return requestResources(req);
235 } 229 }
...@@ -237,21 +231,18 @@ public class LinkResourceManager implements LinkResourceService { ...@@ -237,21 +231,18 @@ public class LinkResourceManager implements LinkResourceService {
237 @Override 231 @Override
238 public Iterable<LinkResourceAllocations> getAllocations() { 232 public Iterable<LinkResourceAllocations> getAllocations() {
239 checkPermission(Permission.LINK_READ); 233 checkPermission(Permission.LINK_READ);
240 -
241 return store.getAllocations(); 234 return store.getAllocations();
242 } 235 }
243 236
244 @Override 237 @Override
245 public Iterable<LinkResourceAllocations> getAllocations(Link link) { 238 public Iterable<LinkResourceAllocations> getAllocations(Link link) {
246 checkPermission(Permission.LINK_READ); 239 checkPermission(Permission.LINK_READ);
247 -
248 return store.getAllocations(link); 240 return store.getAllocations(link);
249 } 241 }
250 242
251 @Override 243 @Override
252 public LinkResourceAllocations getAllocations(IntentId intentId) { 244 public LinkResourceAllocations getAllocations(IntentId intentId) {
253 checkPermission(Permission.LINK_READ); 245 checkPermission(Permission.LINK_READ);
254 -
255 return store.getAllocations(intentId); 246 return store.getAllocations(intentId);
256 } 247 }
257 248
...@@ -291,29 +282,6 @@ public class LinkResourceManager implements LinkResourceService { ...@@ -291,29 +282,6 @@ public class LinkResourceManager implements LinkResourceService {
291 return result; 282 return result;
292 } 283 }
293 284
294 - @Override
295 - public void addListener(LinkResourceListener listener) {
296 - checkPermission(Permission.LINK_EVENT);
297 -
298 - listenerRegistry.addListener(listener);
299 - }
300 -
301 - @Override
302 - public void removeListener(LinkResourceListener listener) {
303 - checkPermission(Permission.LINK_EVENT);
304 -
305 - listenerRegistry.removeListener(listener);
306 - }
307 -
308 - /**
309 - * Posts the specified event to the local event dispatcher.
310 - */
311 - private void post(LinkResourceEvent event) {
312 - if (event != null) {
313 - eventDispatcher.post(event);
314 - }
315 - }
316 -
317 /** 285 /**
318 * Store delegate to re-post events emitted from the store. 286 * Store delegate to re-post events emitted from the store.
319 */ 287 */
......
...@@ -21,15 +21,13 @@ import org.apache.felix.scr.annotations.Deactivate; ...@@ -21,15 +21,13 @@ import org.apache.felix.scr.annotations.Deactivate;
21 import org.apache.felix.scr.annotations.Reference; 21 import org.apache.felix.scr.annotations.Reference;
22 import org.apache.felix.scr.annotations.ReferenceCardinality; 22 import org.apache.felix.scr.annotations.ReferenceCardinality;
23 import org.apache.felix.scr.annotations.Service; 23 import org.apache.felix.scr.annotations.Service;
24 +import org.onosproject.net.provider.AbstractListenerProviderRegistry;
24 import org.onosproject.core.Permission; 25 import org.onosproject.core.Permission;
25 -import org.onosproject.event.ListenerRegistry;
26 import org.onosproject.event.Event; 26 import org.onosproject.event.Event;
27 -import org.onosproject.event.EventDeliveryService;
28 import org.onosproject.net.ConnectPoint; 27 import org.onosproject.net.ConnectPoint;
29 import org.onosproject.net.DeviceId; 28 import org.onosproject.net.DeviceId;
30 import org.onosproject.net.Link; 29 import org.onosproject.net.Link;
31 import org.onosproject.net.Path; 30 import org.onosproject.net.Path;
32 -import org.onosproject.net.provider.AbstractProviderRegistry;
33 import org.onosproject.net.provider.AbstractProviderService; 31 import org.onosproject.net.provider.AbstractProviderService;
34 import org.onosproject.net.topology.ClusterId; 32 import org.onosproject.net.topology.ClusterId;
35 import org.onosproject.net.topology.GraphDescription; 33 import org.onosproject.net.topology.GraphDescription;
...@@ -51,8 +49,8 @@ import java.util.List; ...@@ -51,8 +49,8 @@ import java.util.List;
51 import java.util.Set; 49 import java.util.Set;
52 50
53 import static com.google.common.base.Preconditions.checkNotNull; 51 import static com.google.common.base.Preconditions.checkNotNull;
54 -import static org.slf4j.LoggerFactory.getLogger;
55 import static org.onosproject.security.AppGuard.checkPermission; 52 import static org.onosproject.security.AppGuard.checkPermission;
53 +import static org.slf4j.LoggerFactory.getLogger;
56 54
57 /** 55 /**
58 * Provides basic implementation of the topology SB &amp; NB APIs. 56 * Provides basic implementation of the topology SB &amp; NB APIs.
...@@ -60,7 +58,8 @@ import static org.onosproject.security.AppGuard.checkPermission; ...@@ -60,7 +58,8 @@ import static org.onosproject.security.AppGuard.checkPermission;
60 @Component(immediate = true) 58 @Component(immediate = true)
61 @Service 59 @Service
62 public class TopologyManager 60 public class TopologyManager
63 - extends AbstractProviderRegistry<TopologyProvider, TopologyProviderService> 61 + extends AbstractListenerProviderRegistry<TopologyEvent, TopologyListener,
62 + TopologyProvider, TopologyProviderService>
64 implements TopologyService, TopologyProviderRegistry { 63 implements TopologyService, TopologyProviderRegistry {
65 64
66 public static final String TOPOLOGY_NULL = "Topology cannot be null"; 65 public static final String TOPOLOGY_NULL = "Topology cannot be null";
...@@ -71,18 +70,11 @@ public class TopologyManager ...@@ -71,18 +70,11 @@ public class TopologyManager
71 70
72 private final Logger log = getLogger(getClass()); 71 private final Logger log = getLogger(getClass());
73 72
74 - private final ListenerRegistry<TopologyEvent, TopologyListener>
75 - listenerRegistry = new ListenerRegistry<>();
76 -
77 private TopologyStoreDelegate delegate = new InternalStoreDelegate(); 73 private TopologyStoreDelegate delegate = new InternalStoreDelegate();
78 74
79 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 75 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
80 protected TopologyStore store; 76 protected TopologyStore store;
81 77
82 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
83 - protected EventDeliveryService eventDispatcher;
84 -
85 -
86 @Activate 78 @Activate
87 public void activate() { 79 public void activate() {
88 store.setDelegate(delegate); 80 store.setDelegate(delegate);
...@@ -100,14 +92,12 @@ public class TopologyManager ...@@ -100,14 +92,12 @@ public class TopologyManager
100 @Override 92 @Override
101 public Topology currentTopology() { 93 public Topology currentTopology() {
102 checkPermission(Permission.TOPOLOGY_READ); 94 checkPermission(Permission.TOPOLOGY_READ);
103 -
104 return store.currentTopology(); 95 return store.currentTopology();
105 } 96 }
106 97
107 @Override 98 @Override
108 public boolean isLatest(Topology topology) { 99 public boolean isLatest(Topology topology) {
109 checkPermission(Permission.TOPOLOGY_READ); 100 checkPermission(Permission.TOPOLOGY_READ);
110 -
111 checkNotNull(topology, TOPOLOGY_NULL); 101 checkNotNull(topology, TOPOLOGY_NULL);
112 return store.isLatest(topology); 102 return store.isLatest(topology);
113 } 103 }
...@@ -115,7 +105,6 @@ public class TopologyManager ...@@ -115,7 +105,6 @@ public class TopologyManager
115 @Override 105 @Override
116 public Set<TopologyCluster> getClusters(Topology topology) { 106 public Set<TopologyCluster> getClusters(Topology topology) {
117 checkPermission(Permission.TOPOLOGY_READ); 107 checkPermission(Permission.TOPOLOGY_READ);
118 -
119 checkNotNull(topology, TOPOLOGY_NULL); 108 checkNotNull(topology, TOPOLOGY_NULL);
120 return store.getClusters(topology); 109 return store.getClusters(topology);
121 } 110 }
...@@ -123,7 +112,6 @@ public class TopologyManager ...@@ -123,7 +112,6 @@ public class TopologyManager
123 @Override 112 @Override
124 public TopologyCluster getCluster(Topology topology, ClusterId clusterId) { 113 public TopologyCluster getCluster(Topology topology, ClusterId clusterId) {
125 checkPermission(Permission.TOPOLOGY_READ); 114 checkPermission(Permission.TOPOLOGY_READ);
126 -
127 checkNotNull(topology, TOPOLOGY_NULL); 115 checkNotNull(topology, TOPOLOGY_NULL);
128 checkNotNull(topology, CLUSTER_ID_NULL); 116 checkNotNull(topology, CLUSTER_ID_NULL);
129 return store.getCluster(topology, clusterId); 117 return store.getCluster(topology, clusterId);
...@@ -132,7 +120,6 @@ public class TopologyManager ...@@ -132,7 +120,6 @@ public class TopologyManager
132 @Override 120 @Override
133 public Set<DeviceId> getClusterDevices(Topology topology, TopologyCluster cluster) { 121 public Set<DeviceId> getClusterDevices(Topology topology, TopologyCluster cluster) {
134 checkPermission(Permission.TOPOLOGY_READ); 122 checkPermission(Permission.TOPOLOGY_READ);
135 -
136 checkNotNull(topology, TOPOLOGY_NULL); 123 checkNotNull(topology, TOPOLOGY_NULL);
137 checkNotNull(topology, CLUSTER_NULL); 124 checkNotNull(topology, CLUSTER_NULL);
138 return store.getClusterDevices(topology, cluster); 125 return store.getClusterDevices(topology, cluster);
...@@ -141,7 +128,6 @@ public class TopologyManager ...@@ -141,7 +128,6 @@ public class TopologyManager
141 @Override 128 @Override
142 public Set<Link> getClusterLinks(Topology topology, TopologyCluster cluster) { 129 public Set<Link> getClusterLinks(Topology topology, TopologyCluster cluster) {
143 checkPermission(Permission.TOPOLOGY_READ); 130 checkPermission(Permission.TOPOLOGY_READ);
144 -
145 checkNotNull(topology, TOPOLOGY_NULL); 131 checkNotNull(topology, TOPOLOGY_NULL);
146 checkNotNull(topology, CLUSTER_NULL); 132 checkNotNull(topology, CLUSTER_NULL);
147 return store.getClusterLinks(topology, cluster); 133 return store.getClusterLinks(topology, cluster);
...@@ -150,7 +136,6 @@ public class TopologyManager ...@@ -150,7 +136,6 @@ public class TopologyManager
150 @Override 136 @Override
151 public TopologyGraph getGraph(Topology topology) { 137 public TopologyGraph getGraph(Topology topology) {
152 checkPermission(Permission.TOPOLOGY_READ); 138 checkPermission(Permission.TOPOLOGY_READ);
153 -
154 checkNotNull(topology, TOPOLOGY_NULL); 139 checkNotNull(topology, TOPOLOGY_NULL);
155 return store.getGraph(topology); 140 return store.getGraph(topology);
156 } 141 }
...@@ -158,7 +143,6 @@ public class TopologyManager ...@@ -158,7 +143,6 @@ public class TopologyManager
158 @Override 143 @Override
159 public Set<Path> getPaths(Topology topology, DeviceId src, DeviceId dst) { 144 public Set<Path> getPaths(Topology topology, DeviceId src, DeviceId dst) {
160 checkPermission(Permission.TOPOLOGY_READ); 145 checkPermission(Permission.TOPOLOGY_READ);
161 -
162 checkNotNull(topology, TOPOLOGY_NULL); 146 checkNotNull(topology, TOPOLOGY_NULL);
163 checkNotNull(src, DEVICE_ID_NULL); 147 checkNotNull(src, DEVICE_ID_NULL);
164 checkNotNull(dst, DEVICE_ID_NULL); 148 checkNotNull(dst, DEVICE_ID_NULL);
...@@ -179,7 +163,6 @@ public class TopologyManager ...@@ -179,7 +163,6 @@ public class TopologyManager
179 @Override 163 @Override
180 public boolean isInfrastructure(Topology topology, ConnectPoint connectPoint) { 164 public boolean isInfrastructure(Topology topology, ConnectPoint connectPoint) {
181 checkPermission(Permission.TOPOLOGY_READ); 165 checkPermission(Permission.TOPOLOGY_READ);
182 -
183 checkNotNull(topology, TOPOLOGY_NULL); 166 checkNotNull(topology, TOPOLOGY_NULL);
184 checkNotNull(connectPoint, CONNECTION_POINT_NULL); 167 checkNotNull(connectPoint, CONNECTION_POINT_NULL);
185 return store.isInfrastructure(topology, connectPoint); 168 return store.isInfrastructure(topology, connectPoint);
...@@ -188,26 +171,11 @@ public class TopologyManager ...@@ -188,26 +171,11 @@ public class TopologyManager
188 @Override 171 @Override
189 public boolean isBroadcastPoint(Topology topology, ConnectPoint connectPoint) { 172 public boolean isBroadcastPoint(Topology topology, ConnectPoint connectPoint) {
190 checkPermission(Permission.TOPOLOGY_READ); 173 checkPermission(Permission.TOPOLOGY_READ);
191 -
192 checkNotNull(topology, TOPOLOGY_NULL); 174 checkNotNull(topology, TOPOLOGY_NULL);
193 checkNotNull(connectPoint, CONNECTION_POINT_NULL); 175 checkNotNull(connectPoint, CONNECTION_POINT_NULL);
194 return store.isBroadcastPoint(topology, connectPoint); 176 return store.isBroadcastPoint(topology, connectPoint);
195 } 177 }
196 178
197 - @Override
198 - public void addListener(TopologyListener listener) {
199 - checkPermission(Permission.TOPOLOGY_EVENT);
200 -
201 - listenerRegistry.addListener(listener);
202 - }
203 -
204 - @Override
205 - public void removeListener(TopologyListener listener) {
206 - checkPermission(Permission.TOPOLOGY_EVENT);
207 -
208 - listenerRegistry.removeListener(listener);
209 - }
210 -
211 // Personalized host provider service issued to the supplied provider. 179 // Personalized host provider service issued to the supplied provider.
212 @Override 180 @Override
213 protected TopologyProviderService createProviderService(TopologyProvider provider) { 181 protected TopologyProviderService createProviderService(TopologyProvider provider) {
...@@ -231,7 +199,7 @@ public class TopologyManager ...@@ -231,7 +199,7 @@ public class TopologyManager
231 topoDescription, reasons); 199 topoDescription, reasons);
232 if (event != null) { 200 if (event != null) {
233 log.info("Topology {} changed", event.subject()); 201 log.info("Topology {} changed", event.subject());
234 - eventDispatcher.post(event); 202 + post(event);
235 } 203 }
236 } 204 }
237 } 205 }
...@@ -240,7 +208,7 @@ public class TopologyManager ...@@ -240,7 +208,7 @@ public class TopologyManager
240 private class InternalStoreDelegate implements TopologyStoreDelegate { 208 private class InternalStoreDelegate implements TopologyStoreDelegate {
241 @Override 209 @Override
242 public void notify(TopologyEvent event) { 210 public void notify(TopologyEvent event) {
243 - eventDispatcher.post(event); 211 + post(event);
244 } 212 }
245 } 213 }
246 } 214 }
......
...@@ -41,6 +41,7 @@ import static org.onosproject.app.ApplicationEvent.Type.*; ...@@ -41,6 +41,7 @@ import static org.onosproject.app.ApplicationEvent.Type.*;
41 import static org.onosproject.app.ApplicationState.ACTIVE; 41 import static org.onosproject.app.ApplicationState.ACTIVE;
42 import static org.onosproject.app.ApplicationState.INSTALLED; 42 import static org.onosproject.app.ApplicationState.INSTALLED;
43 import static org.onosproject.app.DefaultApplicationDescriptionTest.*; 43 import static org.onosproject.app.DefaultApplicationDescriptionTest.*;
44 +import static org.onosproject.net.NetTestTools.injectEventDispatcher;
44 45
45 /** 46 /**
46 * Test of the application manager implementation. 47 * Test of the application manager implementation.
...@@ -54,7 +55,7 @@ public class ApplicationManagerTest { ...@@ -54,7 +55,7 @@ public class ApplicationManagerTest {
54 55
55 @Before 56 @Before
56 public void setUp() { 57 public void setUp() {
57 - mgr.eventDispatcher = new TestEventDispatcher(); 58 + injectEventDispatcher(mgr, new TestEventDispatcher());
58 mgr.featuresService = new TestFeaturesService(); 59 mgr.featuresService = new TestFeaturesService();
59 mgr.store = new TestStore(); 60 mgr.store = new TestStore();
60 mgr.activate(); 61 mgr.activate();
......
...@@ -41,6 +41,7 @@ import static org.junit.Assert.assertNull; ...@@ -41,6 +41,7 @@ import static org.junit.Assert.assertNull;
41 import static org.onosproject.net.MastershipRole.MASTER; 41 import static org.onosproject.net.MastershipRole.MASTER;
42 import static org.onosproject.net.MastershipRole.NONE; 42 import static org.onosproject.net.MastershipRole.NONE;
43 import static org.onosproject.net.MastershipRole.STANDBY; 43 import static org.onosproject.net.MastershipRole.STANDBY;
44 +import static org.onosproject.net.NetTestTools.injectEventDispatcher;
44 45
45 /** 46 /**
46 * Test codifying the mastership service contracts. 47 * Test codifying the mastership service contracts.
...@@ -60,7 +61,7 @@ public class MastershipManagerTest { ...@@ -60,7 +61,7 @@ public class MastershipManagerTest {
60 public void setUp() { 61 public void setUp() {
61 mgr = new MastershipManager(); 62 mgr = new MastershipManager();
62 service = mgr; 63 service = mgr;
63 - mgr.eventDispatcher = new TestEventDispatcher(); 64 + injectEventDispatcher(mgr, new TestEventDispatcher());
64 mgr.clusterService = new TestClusterService(); 65 mgr.clusterService = new TestClusterService();
65 mgr.store = new TestSimpleMastershipStore(mgr.clusterService); 66 mgr.store = new TestSimpleMastershipStore(mgr.clusterService);
66 mgr.activate(); 67 mgr.activate();
...@@ -70,7 +71,7 @@ public class MastershipManagerTest { ...@@ -70,7 +71,7 @@ public class MastershipManagerTest {
70 public void tearDown() { 71 public void tearDown() {
71 mgr.deactivate(); 72 mgr.deactivate();
72 mgr.clusterService = null; 73 mgr.clusterService = null;
73 - mgr.eventDispatcher = null; 74 + injectEventDispatcher(mgr, null);
74 mgr.store = null; 75 mgr.store = null;
75 } 76 }
76 77
......
...@@ -15,12 +15,7 @@ ...@@ -15,12 +15,7 @@
15 */ 15 */
16 package org.onosproject.net.device.impl; 16 package org.onosproject.net.device.impl;
17 17
18 -import java.util.ArrayList; 18 +import com.google.common.collect.Sets;
19 -import java.util.Iterator;
20 -import java.util.List;
21 -import java.util.Set;
22 -import java.util.concurrent.CompletableFuture;
23 -
24 import org.junit.After; 19 import org.junit.After;
25 import org.junit.Before; 20 import org.junit.Before;
26 import org.junit.Test; 21 import org.junit.Test;
...@@ -30,8 +25,8 @@ import org.onosproject.cluster.ClusterServiceAdapter; ...@@ -30,8 +25,8 @@ import org.onosproject.cluster.ClusterServiceAdapter;
30 import org.onosproject.cluster.ControllerNode; 25 import org.onosproject.cluster.ControllerNode;
31 import org.onosproject.cluster.DefaultControllerNode; 26 import org.onosproject.cluster.DefaultControllerNode;
32 import org.onosproject.cluster.NodeId; 27 import org.onosproject.cluster.NodeId;
33 -import org.onosproject.event.Event;
34 import org.onosproject.common.event.impl.TestEventDispatcher; 28 import org.onosproject.common.event.impl.TestEventDispatcher;
29 +import org.onosproject.event.Event;
35 import org.onosproject.incubator.net.config.NetworkConfigServiceAdapter; 30 import org.onosproject.incubator.net.config.NetworkConfigServiceAdapter;
36 import org.onosproject.mastership.MastershipServiceAdapter; 31 import org.onosproject.mastership.MastershipServiceAdapter;
37 import org.onosproject.mastership.MastershipTerm; 32 import org.onosproject.mastership.MastershipTerm;
...@@ -57,21 +52,17 @@ import org.onosproject.net.provider.AbstractProvider; ...@@ -57,21 +52,17 @@ import org.onosproject.net.provider.AbstractProvider;
57 import org.onosproject.net.provider.ProviderId; 52 import org.onosproject.net.provider.ProviderId;
58 import org.onosproject.store.trivial.SimpleDeviceStore; 53 import org.onosproject.store.trivial.SimpleDeviceStore;
59 54
60 -import com.google.common.collect.Sets; 55 +import java.util.ArrayList;
56 +import java.util.Iterator;
57 +import java.util.List;
58 +import java.util.Set;
59 +import java.util.concurrent.CompletableFuture;
61 60
62 -import static org.junit.Assert.assertEquals; 61 +import static org.junit.Assert.*;
63 -import static org.junit.Assert.assertFalse;
64 -import static org.junit.Assert.assertNotNull;
65 -import static org.junit.Assert.assertNull;
66 -import static org.junit.Assert.assertTrue;
67 import static org.onosproject.net.Device.Type.SWITCH; 62 import static org.onosproject.net.Device.Type.SWITCH;
68 import static org.onosproject.net.DeviceId.deviceId; 63 import static org.onosproject.net.DeviceId.deviceId;
69 -import static org.onosproject.net.device.DeviceEvent.Type.DEVICE_ADDED; 64 +import static org.onosproject.net.NetTestTools.injectEventDispatcher;
70 -import static org.onosproject.net.device.DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED; 65 +import static org.onosproject.net.device.DeviceEvent.Type.*;
71 -import static org.onosproject.net.device.DeviceEvent.Type.DEVICE_UPDATED;
72 -import static org.onosproject.net.device.DeviceEvent.Type.PORT_ADDED;
73 -import static org.onosproject.net.device.DeviceEvent.Type.PORT_REMOVED;
74 -import static org.onosproject.net.device.DeviceEvent.Type.PORT_UPDATED;
75 66
76 /** 67 /**
77 * Test codifying the device service & device provider service contracts. 68 * Test codifying the device service & device provider service contracts.
...@@ -110,7 +101,7 @@ public class DeviceManagerTest { ...@@ -110,7 +101,7 @@ public class DeviceManagerTest {
110 admin = mgr; 101 admin = mgr;
111 registry = mgr; 102 registry = mgr;
112 mgr.store = new SimpleDeviceStore(); 103 mgr.store = new SimpleDeviceStore();
113 - mgr.eventDispatcher = new TestEventDispatcher(); 104 + injectEventDispatcher(mgr, new TestEventDispatcher());
114 TestMastershipManager mastershipManager = new TestMastershipManager(); 105 TestMastershipManager mastershipManager = new TestMastershipManager();
115 mgr.mastershipService = mastershipManager; 106 mgr.mastershipService = mastershipManager;
116 mgr.termService = mastershipManager; 107 mgr.termService = mastershipManager;
......
...@@ -52,6 +52,7 @@ import java.util.Optional; ...@@ -52,6 +52,7 @@ import java.util.Optional;
52 import java.util.Set; 52 import java.util.Set;
53 53
54 import static org.junit.Assert.*; 54 import static org.junit.Assert.*;
55 +import static org.onosproject.net.NetTestTools.injectEventDispatcher;
55 import static org.onosproject.net.device.DeviceEvent.Type.*; 56 import static org.onosproject.net.device.DeviceEvent.Type.*;
56 import static org.onosproject.net.edge.EdgePortEvent.Type.EDGE_PORT_ADDED; 57 import static org.onosproject.net.edge.EdgePortEvent.Type.EDGE_PORT_ADDED;
57 import static org.onosproject.net.edge.EdgePortEvent.Type.EDGE_PORT_REMOVED; 58 import static org.onosproject.net.edge.EdgePortEvent.Type.EDGE_PORT_REMOVED;
...@@ -78,7 +79,7 @@ public class EdgeManagerTest { ...@@ -78,7 +79,7 @@ public class EdgeManagerTest {
78 @Before 79 @Before
79 public void setUp() { 80 public void setUp() {
80 mgr = new EdgeManager(); 81 mgr = new EdgeManager();
81 - mgr.eventDispatcher = new TestEventDispatcher(); 82 + injectEventDispatcher(mgr, new TestEventDispatcher());
82 testTopologyManager = new TestTopologyManager(infrastructurePorts); 83 testTopologyManager = new TestTopologyManager(infrastructurePorts);
83 mgr.topologyService = testTopologyManager; 84 mgr.topologyService = testTopologyManager;
84 mgr.deviceService = new TestDeviceManager(devices); 85 mgr.deviceService = new TestDeviceManager(devices);
......
...@@ -80,6 +80,7 @@ import static org.junit.Assert.assertEquals; ...@@ -80,6 +80,7 @@ import static org.junit.Assert.assertEquals;
80 import static org.junit.Assert.assertFalse; 80 import static org.junit.Assert.assertFalse;
81 import static org.junit.Assert.assertNotNull; 81 import static org.junit.Assert.assertNotNull;
82 import static org.junit.Assert.assertTrue; 82 import static org.junit.Assert.assertTrue;
83 +import static org.onosproject.net.NetTestTools.injectEventDispatcher;
83 import static org.onosproject.net.flow.FlowRuleEvent.Type.RULE_ADDED; 84 import static org.onosproject.net.flow.FlowRuleEvent.Type.RULE_ADDED;
84 import static org.onosproject.net.flow.FlowRuleEvent.Type.RULE_ADD_REQUESTED; 85 import static org.onosproject.net.flow.FlowRuleEvent.Type.RULE_ADD_REQUESTED;
85 import static org.onosproject.net.flow.FlowRuleEvent.Type.RULE_REMOVED; 86 import static org.onosproject.net.flow.FlowRuleEvent.Type.RULE_REMOVED;
...@@ -112,7 +113,7 @@ public class FlowRuleManagerTest { ...@@ -112,7 +113,7 @@ public class FlowRuleManagerTest {
112 public void setUp() { 113 public void setUp() {
113 mgr = new FlowRuleManager(); 114 mgr = new FlowRuleManager();
114 mgr.store = new SimpleFlowRuleStore(); 115 mgr.store = new SimpleFlowRuleStore();
115 - mgr.eventDispatcher = new TestEventDispatcher(); 116 + injectEventDispatcher(mgr, new TestEventDispatcher());
116 mgr.deviceService = new TestDeviceService(); 117 mgr.deviceService = new TestDeviceService();
117 mgr.coreService = new TestCoreService(); 118 mgr.coreService = new TestCoreService();
118 mgr.operationsService = MoreExecutors.newDirectExecutorService(); 119 mgr.operationsService = MoreExecutors.newDirectExecutorService();
...@@ -137,7 +138,7 @@ public class FlowRuleManagerTest { ...@@ -137,7 +138,7 @@ public class FlowRuleManagerTest {
137 registry.getProviders().contains(provider.id())); 138 registry.getProviders().contains(provider.id()));
138 service.removeListener(listener); 139 service.removeListener(listener);
139 mgr.deactivate(); 140 mgr.deactivate();
140 - mgr.eventDispatcher = null; 141 + injectEventDispatcher(mgr, null);
141 mgr.deviceService = null; 142 mgr.deviceService = null;
142 } 143 }
143 144
......
...@@ -20,6 +20,7 @@ import static org.junit.Assert.assertFalse; ...@@ -20,6 +20,7 @@ import static org.junit.Assert.assertFalse;
20 import static org.junit.Assert.assertNotEquals; 20 import static org.junit.Assert.assertNotEquals;
21 import static org.junit.Assert.assertNotNull; 21 import static org.junit.Assert.assertNotNull;
22 import static org.junit.Assert.assertTrue; 22 import static org.junit.Assert.assertTrue;
23 +import static org.onosproject.net.NetTestTools.injectEventDispatcher;
23 24
24 import java.util.ArrayList; 25 import java.util.ArrayList;
25 import java.util.Arrays; 26 import java.util.Arrays;
...@@ -89,7 +90,7 @@ public class GroupManagerTest { ...@@ -89,7 +90,7 @@ public class GroupManagerTest {
89 groupService = mgr; 90 groupService = mgr;
90 mgr.deviceService = new DeviceManager(); 91 mgr.deviceService = new DeviceManager();
91 mgr.store = new SimpleGroupStore(); 92 mgr.store = new SimpleGroupStore();
92 - mgr.eventDispatcher = new TestEventDispatcher(); 93 + injectEventDispatcher(mgr, new TestEventDispatcher());
93 providerRegistry = mgr; 94 providerRegistry = mgr;
94 95
95 mgr.activate(); 96 mgr.activate();
...@@ -110,7 +111,7 @@ public class GroupManagerTest { ...@@ -110,7 +111,7 @@ public class GroupManagerTest {
110 providerRegistry.getProviders().contains(provider.id())); 111 providerRegistry.getProviders().contains(provider.id()));
111 mgr.removeListener(listener); 112 mgr.removeListener(listener);
112 mgr.deactivate(); 113 mgr.deactivate();
113 - mgr.eventDispatcher = null; 114 + injectEventDispatcher(mgr, null);
114 } 115 }
115 116
116 /** 117 /**
......
...@@ -20,6 +20,7 @@ import static org.junit.Assert.assertFalse; ...@@ -20,6 +20,7 @@ import static org.junit.Assert.assertFalse;
20 import static org.junit.Assert.assertNotNull; 20 import static org.junit.Assert.assertNotNull;
21 import static org.junit.Assert.assertNull; 21 import static org.junit.Assert.assertNull;
22 import static org.junit.Assert.assertTrue; 22 import static org.junit.Assert.assertTrue;
23 +import static org.onosproject.net.NetTestTools.injectEventDispatcher;
23 import static org.onosproject.net.host.HostEvent.Type.HOST_ADDED; 24 import static org.onosproject.net.host.HostEvent.Type.HOST_ADDED;
24 import static org.onosproject.net.host.HostEvent.Type.HOST_MOVED; 25 import static org.onosproject.net.host.HostEvent.Type.HOST_MOVED;
25 import static org.onosproject.net.host.HostEvent.Type.HOST_REMOVED; 26 import static org.onosproject.net.host.HostEvent.Type.HOST_REMOVED;
...@@ -122,7 +123,7 @@ public class HostManagerTest { ...@@ -122,7 +123,7 @@ public class HostManagerTest {
122 public void setUp() { 123 public void setUp() {
123 mgr = new HostManager(); 124 mgr = new HostManager();
124 mgr.store = new SimpleHostStore(); 125 mgr.store = new SimpleHostStore();
125 - mgr.eventDispatcher = new TestEventDispatcher(); 126 + injectEventDispatcher(mgr, new TestEventDispatcher());
126 registry = mgr; 127 registry = mgr;
127 mgr.networkConfigService = new TestNetworkConfigService(); 128 mgr.networkConfigService = new TestNetworkConfigService();
128 mgr.activate(); 129 mgr.activate();
...@@ -143,7 +144,7 @@ public class HostManagerTest { ...@@ -143,7 +144,7 @@ public class HostManagerTest {
143 144
144 mgr.removeListener(listener); 145 mgr.removeListener(listener);
145 mgr.deactivate(); 146 mgr.deactivate();
146 - mgr.eventDispatcher = null; 147 + injectEventDispatcher(mgr, null);
147 } 148 }
148 149
149 private void detect(HostId hid, MacAddress mac, VlanId vlan, 150 private void detect(HostId hid, MacAddress mac, VlanId vlan,
......
...@@ -63,6 +63,7 @@ import static org.hamcrest.Matchers.is; ...@@ -63,6 +63,7 @@ import static org.hamcrest.Matchers.is;
63 import static org.junit.Assert.*; 63 import static org.junit.Assert.*;
64 import static org.onlab.junit.TestTools.assertAfter; 64 import static org.onlab.junit.TestTools.assertAfter;
65 import static org.onlab.util.Tools.delay; 65 import static org.onlab.util.Tools.delay;
66 +import static org.onosproject.net.NetTestTools.injectEventDispatcher;
66 import static org.onosproject.net.intent.IntentState.*; 67 import static org.onosproject.net.intent.IntentState.*;
67 import static org.onosproject.net.intent.IntentTestsMocks.MockFlowRule; 68 import static org.onosproject.net.intent.IntentTestsMocks.MockFlowRule;
68 import static org.onosproject.net.intent.IntentTestsMocks.MockIntent; 69 import static org.onosproject.net.intent.IntentTestsMocks.MockIntent;
...@@ -226,7 +227,7 @@ public class IntentManagerTest { ...@@ -226,7 +227,7 @@ public class IntentManagerTest {
226 manager = new IntentManager(); 227 manager = new IntentManager();
227 flowRuleService = new MockFlowRuleService(); 228 flowRuleService = new MockFlowRuleService();
228 manager.store = new SimpleIntentStore(); 229 manager.store = new SimpleIntentStore();
229 - manager.eventDispatcher = new TestEventDispatcher(); 230 + injectEventDispatcher(manager, new TestEventDispatcher());
230 manager.trackerService = new TestIntentTracker(); 231 manager.trackerService = new TestIntentTracker();
231 manager.flowRuleService = flowRuleService; 232 manager.flowRuleService = flowRuleService;
232 manager.coreService = new TestCoreManager(); 233 manager.coreService = new TestCoreManager();
......
...@@ -53,6 +53,7 @@ import static org.junit.Assert.*; ...@@ -53,6 +53,7 @@ import static org.junit.Assert.*;
53 import static org.onosproject.net.DeviceId.deviceId; 53 import static org.onosproject.net.DeviceId.deviceId;
54 import static org.onosproject.net.Link.Type.DIRECT; 54 import static org.onosproject.net.Link.Type.DIRECT;
55 import static org.onosproject.net.Link.Type.INDIRECT; 55 import static org.onosproject.net.Link.Type.INDIRECT;
56 +import static org.onosproject.net.NetTestTools.injectEventDispatcher;
56 import static org.onosproject.net.link.LinkEvent.Type.*; 57 import static org.onosproject.net.link.LinkEvent.Type.*;
57 58
58 /** 59 /**
...@@ -95,7 +96,7 @@ public class LinkManagerTest { ...@@ -95,7 +96,7 @@ public class LinkManagerTest {
95 admin = mgr; 96 admin = mgr;
96 registry = mgr; 97 registry = mgr;
97 mgr.store = new SimpleLinkStore(); 98 mgr.store = new SimpleLinkStore();
98 - mgr.eventDispatcher = new TestEventDispatcher(); 99 + injectEventDispatcher(mgr, new TestEventDispatcher());
99 mgr.deviceService = devmgr; 100 mgr.deviceService = devmgr;
100 mgr.networkConfigService = new TestNetworkConfigService(); 101 mgr.networkConfigService = new TestNetworkConfigService();
101 mgr.activate(); 102 mgr.activate();
......
...@@ -100,8 +100,8 @@ public class DefaultTopologyProviderTest { ...@@ -100,8 +100,8 @@ public class DefaultTopologyProviderTest {
100 assertEquals(1, topologyChangedCounts.awaitAdvanceInterruptibly(0, 1, TimeUnit.SECONDS)); 100 assertEquals(1, topologyChangedCounts.awaitAdvanceInterruptibly(0, 1, TimeUnit.SECONDS));
101 validateSubmission(); 101 validateSubmission();
102 102
103 - deviceService.post(new DeviceEvent(DEVICE_ADDED, device("z"), null)); 103 + deviceService.postEvent(new DeviceEvent(DEVICE_ADDED, device("z"), null));
104 - linkService.post(new LinkEvent(LINK_ADDED, link("z", 1, "a", 4))); 104 + linkService.postEvent(new LinkEvent(LINK_ADDED, link("z", 1, "a", 4)));
105 assertThat(topologyChangedCounts.awaitAdvanceInterruptibly(1, 1, TimeUnit.SECONDS), 105 assertThat(topologyChangedCounts.awaitAdvanceInterruptibly(1, 1, TimeUnit.SECONDS),
106 is(greaterThanOrEqualTo(2))); 106 is(greaterThanOrEqualTo(2)));
107 // Note: posting event, to trigger topologyChanged call, 107 // Note: posting event, to trigger topologyChanged call,
...@@ -162,7 +162,7 @@ public class DefaultTopologyProviderTest { ...@@ -162,7 +162,7 @@ public class DefaultTopologyProviderTest {
162 return getDevices(); 162 return getDevices();
163 } 163 }
164 164
165 - void post(DeviceEvent event) { 165 + void postEvent(DeviceEvent event) {
166 eventDispatcher.post(event); 166 eventDispatcher.post(event);
167 } 167 }
168 } 168 }
...@@ -187,7 +187,7 @@ public class DefaultTopologyProviderTest { ...@@ -187,7 +187,7 @@ public class DefaultTopologyProviderTest {
187 return getLinks(); 187 return getLinks();
188 } 188 }
189 189
190 - void post(LinkEvent event) { 190 + void postEvent(LinkEvent event) {
191 eventDispatcher.post(event); 191 eventDispatcher.post(event);
192 } 192 }
193 } 193 }
......
...@@ -73,7 +73,7 @@ public class TopologyManagerTest { ...@@ -73,7 +73,7 @@ public class TopologyManagerTest {
73 registry = mgr; 73 registry = mgr;
74 74
75 mgr.store = new SimpleTopologyStore(); 75 mgr.store = new SimpleTopologyStore();
76 - mgr.eventDispatcher = new TestEventDispatcher(); 76 + injectEventDispatcher(mgr, new TestEventDispatcher());
77 mgr.activate(); 77 mgr.activate();
78 78
79 service.addListener(listener); 79 service.addListener(listener);
......
...@@ -57,6 +57,10 @@ ...@@ -57,6 +57,10 @@
57 <groupId>org.osgi</groupId> 57 <groupId>org.osgi</groupId>
58 <artifactId>org.osgi.compendium</artifactId> 58 <artifactId>org.osgi.compendium</artifactId>
59 </dependency> 59 </dependency>
60 + <dependency>
61 + <groupId>org.apache.felix</groupId>
62 + <artifactId>org.apache.felix.scr.annotations</artifactId>
63 + </dependency>
60 </dependencies> 64 </dependencies>
61 65
62 <build> 66 <build>
...@@ -70,6 +74,11 @@ ...@@ -70,6 +74,11 @@
70 <groupId>org.onosproject</groupId> 74 <groupId>org.onosproject</groupId>
71 <artifactId>onos-maven-plugin</artifactId> 75 <artifactId>onos-maven-plugin</artifactId>
72 </plugin> 76 </plugin>
77 +
78 + <plugin>
79 + <groupId>org.apache.felix</groupId>
80 + <artifactId>maven-scr-plugin</artifactId>
81 + </plugin>
73 </plugins> 82 </plugins>
74 </build> 83 </build>
75 84
......
...@@ -37,14 +37,6 @@ ...@@ -37,14 +37,6 @@
37 <artifactId>org.osgi.core</artifactId> 37 <artifactId>org.osgi.core</artifactId>
38 </dependency> 38 </dependency>
39 <dependency> 39 <dependency>
40 - <groupId>org.osgi</groupId>
41 - <artifactId>org.osgi.compendium</artifactId>
42 - </dependency>
43 - <dependency>
44 - <groupId>org.apache.felix</groupId>
45 - <artifactId>org.apache.felix.scr.annotations</artifactId>
46 - </dependency>
47 - <dependency>
48 <groupId>org.onosproject</groupId> 40 <groupId>org.onosproject</groupId>
49 <artifactId>onos-api</artifactId> 41 <artifactId>onos-api</artifactId>
50 </dependency> 42 </dependency>
...@@ -54,14 +46,4 @@ ...@@ -54,14 +46,4 @@
54 </dependency> 46 </dependency>
55 </dependencies> 47 </dependencies>
56 48
57 - <build>
58 - <plugins>
59 - <plugin>
60 - <groupId>org.apache.felix</groupId>
61 - <artifactId>maven-scr-plugin</artifactId>
62 - </plugin>
63 - </plugins>
64 - </build>
65 -
66 -
67 </project> 49 </project>
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -49,20 +49,6 @@ ...@@ -49,20 +49,6 @@
49 <classifier>tests</classifier> 49 <classifier>tests</classifier>
50 <scope>test</scope> 50 <scope>test</scope>
51 </dependency> 51 </dependency>
52 -
53 - <dependency>
54 - <groupId>org.apache.felix</groupId>
55 - <artifactId>org.apache.felix.scr.annotations</artifactId>
56 - </dependency>
57 </dependencies> 52 </dependencies>
58 53
59 - <build>
60 - <plugins>
61 - <plugin>
62 - <groupId>org.apache.felix</groupId>
63 - <artifactId>maven-scr-plugin</artifactId>
64 - </plugin>
65 - </plugins>
66 - </build>
67 -
68 </project> 54 </project>
......
...@@ -17,6 +17,7 @@ package org.onosproject.incubator.net.config; ...@@ -17,6 +17,7 @@ package org.onosproject.incubator.net.config;
17 17
18 import com.fasterxml.jackson.databind.node.ObjectNode; 18 import com.fasterxml.jackson.databind.node.ObjectNode;
19 import com.google.common.annotations.Beta; 19 import com.google.common.annotations.Beta;
20 +import org.onosproject.event.ListenerService;
20 21
21 import java.util.Set; 22 import java.util.Set;
22 23
...@@ -26,7 +27,8 @@ import java.util.Set; ...@@ -26,7 +27,8 @@ import java.util.Set;
26 * should act on or configure the network. 27 * should act on or configure the network.
27 */ 28 */
28 @Beta 29 @Beta
29 -public interface NetworkConfigService { 30 +public interface NetworkConfigService
31 + extends ListenerService<NetworkConfigEvent, NetworkConfigListener> {
30 32
31 /** 33 /**
32 * Returns the set of subject classes for which configuration may be 34 * Returns the set of subject classes for which configuration may be
...@@ -140,17 +142,4 @@ public interface NetworkConfigService { ...@@ -140,17 +142,4 @@ public interface NetworkConfigService {
140 */ 142 */
141 <S, C extends Config<S>> void removeConfig(S subject, Class<C> configClass); 143 <S, C extends Config<S>> void removeConfig(S subject, Class<C> configClass);
142 144
143 - /**
144 - * Adds the specified network config listener.
145 - *
146 - * @param listener network config listener
147 - */
148 - void addListener(NetworkConfigListener listener);
149 -
150 - /**
151 - * Removes the specified network config listener.
152 - *
153 - * @param listener network config listener
154 - */
155 - void removeListener(NetworkConfigListener listener);
156 } 145 }
......
...@@ -4,6 +4,7 @@ import java.util.Collection; ...@@ -4,6 +4,7 @@ import java.util.Collection;
4 import java.util.Set; 4 import java.util.Set;
5 5
6 import com.google.common.annotations.Beta; 6 import com.google.common.annotations.Beta;
7 +import org.onosproject.event.ListenerService;
7 import org.onosproject.net.DeviceId; 8 import org.onosproject.net.DeviceId;
8 9
9 import com.google.common.collect.Multimap; 10 import com.google.common.collect.Multimap;
...@@ -12,7 +13,8 @@ import com.google.common.collect.Multimap; ...@@ -12,7 +13,8 @@ import com.google.common.collect.Multimap;
12 * Service for providing label resource allocation. 13 * Service for providing label resource allocation.
13 */ 14 */
14 @Beta 15 @Beta
15 -public interface LabelResourceService { 16 +public interface LabelResourceService
17 + extends ListenerService<LabelResourceEvent, LabelResourceListener> {
16 18
17 /** 19 /**
18 * Returns labels from resource pool by a specific device id. 20 * Returns labels from resource pool by a specific device id.
...@@ -95,17 +97,4 @@ public interface LabelResourceService { ...@@ -95,17 +97,4 @@ public interface LabelResourceService {
95 */ 97 */
96 LabelResourcePool getGlobalLabelResourcePool(); 98 LabelResourcePool getGlobalLabelResourcePool();
97 99
98 - /**
99 - * Adds the specified label resource listener.
100 - *
101 - * @param listener label resource listener
102 - */
103 - void addListener(LabelResourceListener listener);
104 -
105 - /**
106 - * Removes the specified label resource listener.
107 - *
108 - * @param listener label resource listener
109 - */
110 - void removeListener(LabelResourceListener listener);
111 } 100 }
......
...@@ -19,6 +19,7 @@ import java.util.Collection; ...@@ -19,6 +19,7 @@ import java.util.Collection;
19 19
20 import com.google.common.annotations.Beta; 20 import com.google.common.annotations.Beta;
21 import org.onosproject.core.ApplicationId; 21 import org.onosproject.core.ApplicationId;
22 +import org.onosproject.event.ListenerService;
22 import org.onosproject.incubator.net.tunnel.Tunnel.Type; 23 import org.onosproject.incubator.net.tunnel.Tunnel.Type;
23 import org.onosproject.net.Annotations; 24 import org.onosproject.net.Annotations;
24 import org.onosproject.net.DeviceId; 25 import org.onosproject.net.DeviceId;
...@@ -27,7 +28,8 @@ import org.onosproject.net.DeviceId; ...@@ -27,7 +28,8 @@ import org.onosproject.net.DeviceId;
27 * Service for interacting with the inventory of tunnels. 28 * Service for interacting with the inventory of tunnels.
28 */ 29 */
29 @Beta 30 @Beta
30 -public interface TunnelService { 31 +public interface TunnelService
32 + extends ListenerService<TunnelEvent, TunnelListener> {
31 33
32 /** 34 /**
33 * Borrows a specific tunnel. Annotations parameter is reserved.If there 35 * Borrows a specific tunnel. Annotations parameter is reserved.If there
...@@ -196,17 +198,4 @@ public interface TunnelService { ...@@ -196,17 +198,4 @@ public interface TunnelService {
196 */ 198 */
197 Iterable<Tunnel> getTunnels(DeviceId deviceId); 199 Iterable<Tunnel> getTunnels(DeviceId deviceId);
198 200
199 - /**
200 - * Adds the specified tunnel listener.
201 - *
202 - * @param listener tunnel listener
203 - */
204 - void addListener(TunnelListener listener);
205 -
206 - /**
207 - * Removes the specified tunnel listener.
208 - *
209 - * @param listener tunnel listener
210 - */
211 - void removeListener(TunnelListener listener);
212 } 201 }
......
...@@ -56,6 +56,11 @@ ...@@ -56,6 +56,11 @@
56 </dependency> 56 </dependency>
57 57
58 <dependency> 58 <dependency>
59 + <groupId>org.onosproject</groupId>
60 + <artifactId>onos-core-common</artifactId>
61 + </dependency>
62 +
63 + <dependency>
59 <groupId>org.easymock</groupId> 64 <groupId>org.easymock</groupId>
60 <artifactId>easymock</artifactId> 65 <artifactId>easymock</artifactId>
61 <scope>test</scope> 66 <scope>test</scope>
......
...@@ -24,8 +24,7 @@ import org.apache.felix.scr.annotations.Deactivate; ...@@ -24,8 +24,7 @@ import org.apache.felix.scr.annotations.Deactivate;
24 import org.apache.felix.scr.annotations.Reference; 24 import org.apache.felix.scr.annotations.Reference;
25 import org.apache.felix.scr.annotations.ReferenceCardinality; 25 import org.apache.felix.scr.annotations.ReferenceCardinality;
26 import org.apache.felix.scr.annotations.Service; 26 import org.apache.felix.scr.annotations.Service;
27 -import org.onosproject.event.EventDeliveryService; 27 +import org.onosproject.event.AbstractListenerManager;
28 -import org.onosproject.event.ListenerRegistry;
29 import org.onosproject.incubator.net.config.Config; 28 import org.onosproject.incubator.net.config.Config;
30 import org.onosproject.incubator.net.config.ConfigFactory; 29 import org.onosproject.incubator.net.config.ConfigFactory;
31 import org.onosproject.incubator.net.config.NetworkConfigEvent; 30 import org.onosproject.incubator.net.config.NetworkConfigEvent;
...@@ -49,7 +48,9 @@ import static com.google.common.base.Preconditions.checkNotNull; ...@@ -49,7 +48,9 @@ import static com.google.common.base.Preconditions.checkNotNull;
49 */ 48 */
50 @Component(immediate = true) 49 @Component(immediate = true)
51 @Service 50 @Service
52 -public class NetworkConfigManager implements NetworkConfigRegistry, NetworkConfigService { 51 +public class NetworkConfigManager
52 + extends AbstractListenerManager<NetworkConfigEvent, NetworkConfigListener>
53 + implements NetworkConfigRegistry, NetworkConfigService {
53 54
54 private final Logger log = LoggerFactory.getLogger(getClass()); 55 private final Logger log = LoggerFactory.getLogger(getClass());
55 56
...@@ -66,17 +67,11 @@ public class NetworkConfigManager implements NetworkConfigRegistry, NetworkConfi ...@@ -66,17 +67,11 @@ public class NetworkConfigManager implements NetworkConfigRegistry, NetworkConfi
66 private final Map<Class, SubjectFactory> subjectClassKeys = Maps.newConcurrentMap(); 67 private final Map<Class, SubjectFactory> subjectClassKeys = Maps.newConcurrentMap();
67 private final Map<ConfigIdentifier, Class<? extends Config>> configClasses = Maps.newConcurrentMap(); 68 private final Map<ConfigIdentifier, Class<? extends Config>> configClasses = Maps.newConcurrentMap();
68 69
69 - private final ListenerRegistry<NetworkConfigEvent, NetworkConfigListener>
70 - listenerRegistry = new ListenerRegistry<>();
71 -
72 private final NetworkConfigStoreDelegate storeDelegate = new InternalStoreDelegate(); 70 private final NetworkConfigStoreDelegate storeDelegate = new InternalStoreDelegate();
73 71
74 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 72 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
75 protected NetworkConfigStore store; 73 protected NetworkConfigStore store;
76 74
77 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
78 - protected EventDeliveryService eventDispatcher;
79 -
80 75
81 @Activate 76 @Activate
82 public void activate() { 77 public void activate() {
...@@ -215,23 +210,12 @@ public class NetworkConfigManager implements NetworkConfigRegistry, NetworkConfi ...@@ -215,23 +210,12 @@ public class NetworkConfigManager implements NetworkConfigRegistry, NetworkConfi
215 store.clearConfig(subject, configClass); 210 store.clearConfig(subject, configClass);
216 } 211 }
217 212
218 - @Override
219 - public void addListener(NetworkConfigListener listener) {
220 - listenerRegistry.addListener(listener);
221 - }
222 -
223 - @Override
224 - public void removeListener(NetworkConfigListener listener) {
225 - listenerRegistry.removeListener(listener);
226 - }
227 -
228 -
229 // Auxiliary store delegate to receive notification about changes in 213 // Auxiliary store delegate to receive notification about changes in
230 // the network configuration store state - by the store itself. 214 // the network configuration store state - by the store itself.
231 private class InternalStoreDelegate implements NetworkConfigStoreDelegate { 215 private class InternalStoreDelegate implements NetworkConfigStoreDelegate {
232 @Override 216 @Override
233 public void notify(NetworkConfigEvent event) { 217 public void notify(NetworkConfigEvent event) {
234 - eventDispatcher.post(event); 218 + post(event);
235 } 219 }
236 } 220 }
237 221
......
1 package org.onosproject.incubator.net.resource.label.impl; 1 package org.onosproject.incubator.net.resource.label.impl;
2 2
3 -import static org.slf4j.LoggerFactory.getLogger; 3 +import com.google.common.collect.Multimap;
4 -
5 -import java.util.Collection;
6 -import java.util.Set;
7 -
8 import org.apache.felix.scr.annotations.Activate; 4 import org.apache.felix.scr.annotations.Activate;
9 import org.apache.felix.scr.annotations.Component; 5 import org.apache.felix.scr.annotations.Component;
10 import org.apache.felix.scr.annotations.Deactivate; 6 import org.apache.felix.scr.annotations.Deactivate;
11 import org.apache.felix.scr.annotations.Reference; 7 import org.apache.felix.scr.annotations.Reference;
12 import org.apache.felix.scr.annotations.ReferenceCardinality; 8 import org.apache.felix.scr.annotations.ReferenceCardinality;
13 import org.apache.felix.scr.annotations.Service; 9 import org.apache.felix.scr.annotations.Service;
14 -import org.onosproject.event.EventDeliveryService; 10 +import org.onosproject.net.provider.AbstractListenerProviderRegistry;
15 -import org.onosproject.event.ListenerRegistry;
16 -import org.onosproject.net.Device;
17 -import org.onosproject.net.DeviceId;
18 -import org.onosproject.net.device.DeviceEvent;
19 -import org.onosproject.net.device.DeviceEvent.Type;
20 -import org.onosproject.net.device.DeviceListener;
21 -import org.onosproject.net.device.DeviceService;
22 -import org.onosproject.net.provider.AbstractProviderRegistry;
23 -import org.onosproject.net.provider.AbstractProviderService;
24 import org.onosproject.incubator.net.resource.label.LabelResource; 11 import org.onosproject.incubator.net.resource.label.LabelResource;
25 import org.onosproject.incubator.net.resource.label.LabelResourceAdminService; 12 import org.onosproject.incubator.net.resource.label.LabelResourceAdminService;
26 import org.onosproject.incubator.net.resource.label.LabelResourceDelegate; 13 import org.onosproject.incubator.net.resource.label.LabelResourceDelegate;
...@@ -33,11 +20,21 @@ import org.onosproject.incubator.net.resource.label.LabelResourceProviderRegistr ...@@ -33,11 +20,21 @@ import org.onosproject.incubator.net.resource.label.LabelResourceProviderRegistr
33 import org.onosproject.incubator.net.resource.label.LabelResourceProviderService; 20 import org.onosproject.incubator.net.resource.label.LabelResourceProviderService;
34 import org.onosproject.incubator.net.resource.label.LabelResourceService; 21 import org.onosproject.incubator.net.resource.label.LabelResourceService;
35 import org.onosproject.incubator.net.resource.label.LabelResourceStore; 22 import org.onosproject.incubator.net.resource.label.LabelResourceStore;
23 +import org.onosproject.net.Device;
24 +import org.onosproject.net.DeviceId;
25 +import org.onosproject.net.device.DeviceEvent;
26 +import org.onosproject.net.device.DeviceEvent.Type;
27 +import org.onosproject.net.device.DeviceListener;
28 +import org.onosproject.net.device.DeviceService;
29 +import org.onosproject.net.provider.AbstractProviderService;
36 import org.slf4j.Logger; 30 import org.slf4j.Logger;
37 -import static com.google.common.base.Preconditions.checkNotNull;
38 -import static com.google.common.base.Preconditions.checkArgument;
39 31
40 -import com.google.common.collect.Multimap; 32 +import java.util.Collection;
33 +import java.util.Set;
34 +
35 +import static com.google.common.base.Preconditions.checkArgument;
36 +import static com.google.common.base.Preconditions.checkNotNull;
37 +import static org.slf4j.LoggerFactory.getLogger;
41 38
42 /** 39 /**
43 * provides implementation of the label resource NB &amp; SB APIs. 40 * provides implementation of the label resource NB &amp; SB APIs.
...@@ -46,23 +43,16 @@ import com.google.common.collect.Multimap; ...@@ -46,23 +43,16 @@ import com.google.common.collect.Multimap;
46 @Component(immediate = true) 43 @Component(immediate = true)
47 @Service 44 @Service
48 public class LabelResourceManager 45 public class LabelResourceManager
49 - extends 46 + extends AbstractListenerProviderRegistry<LabelResourceEvent, LabelResourceListener,
50 - AbstractProviderRegistry<LabelResourceProvider, LabelResourceProviderService> 47 + LabelResourceProvider, LabelResourceProviderService>
51 - implements LabelResourceService, LabelResourceAdminService, 48 + implements LabelResourceService, LabelResourceAdminService, LabelResourceProviderRegistry {
52 - LabelResourceProviderRegistry {
53 private final Logger log = getLogger(getClass()); 49 private final Logger log = getLogger(getClass());
54 private final LabelResourceDelegate delegate = new InternalLabelResourceDelegate(); 50 private final LabelResourceDelegate delegate = new InternalLabelResourceDelegate();
55 51
56 - private final ListenerRegistry<LabelResourceEvent, LabelResourceListener> listenerRegistry
57 - = new ListenerRegistry<>();
58 -
59 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 52 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
60 protected LabelResourceStore store; 53 protected LabelResourceStore store;
61 54
62 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 55 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
63 - protected EventDeliveryService eventDispatcher;
64 -
65 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
66 protected DeviceService deviceService; 56 protected DeviceService deviceService;
67 57
68 private DeviceListener deviceListener = new InternalDeviceListener(); 58 private DeviceListener deviceListener = new InternalDeviceListener();
...@@ -104,9 +94,9 @@ public class LabelResourceManager ...@@ -104,9 +94,9 @@ public class LabelResourceManager
104 checkNotNull(beginLabel, "beginLabel is not null"); 94 checkNotNull(beginLabel, "beginLabel is not null");
105 checkNotNull(endLabel, "beginLabel is not null"); 95 checkNotNull(endLabel, "beginLabel is not null");
106 checkArgument(beginLabel.labelId() >= 0 && endLabel.labelId() >= 0, 96 checkArgument(beginLabel.labelId() >= 0 && endLabel.labelId() >= 0,
107 - "The value of beginLabel and the value of endLabel must be both positive number."); 97 + "The value of beginLabel and the value of endLabel must be both positive number.");
108 checkArgument(beginLabel.labelId() <= endLabel.labelId(), 98 checkArgument(beginLabel.labelId() <= endLabel.labelId(),
109 - "The value of endLabel must be greater than the value of endLabel."); 99 + "The value of endLabel must be greater than the value of endLabel.");
110 return store.createGlobalPool(beginLabel, endLabel); 100 return store.createGlobalPool(beginLabel, endLabel);
111 } 101 }
112 102
...@@ -180,26 +170,7 @@ public class LabelResourceManager ...@@ -180,26 +170,7 @@ public class LabelResourceManager
180 return store.getGlobalLabelResourcePool(); 170 return store.getGlobalLabelResourcePool();
181 } 171 }
182 172
183 - @Override 173 + private class InternalLabelResourceDelegate implements LabelResourceDelegate {
184 - public void addListener(LabelResourceListener listener) {
185 - listenerRegistry.addListener(listener);
186 - }
187 -
188 - @Override
189 - public void removeListener(LabelResourceListener listener) {
190 - listenerRegistry.removeListener(listener);
191 -
192 - }
193 -
194 - private void post(LabelResourceEvent event) {
195 - if (event != null) {
196 - eventDispatcher.post(event);
197 - }
198 - }
199 -
200 - private class InternalLabelResourceDelegate
201 - implements LabelResourceDelegate {
202 -
203 @Override 174 @Override
204 public void notify(LabelResourceEvent event) { 175 public void notify(LabelResourceEvent event) {
205 post(event); 176 post(event);
...@@ -208,7 +179,6 @@ public class LabelResourceManager ...@@ -208,7 +179,6 @@ public class LabelResourceManager
208 } 179 }
209 180
210 private class InternalDeviceListener implements DeviceListener { 181 private class InternalDeviceListener implements DeviceListener {
211 -
212 @Override 182 @Override
213 public void event(DeviceEvent event) { 183 public void event(DeviceEvent event) {
214 Device device = event.subject(); 184 Device device = event.subject();
......
...@@ -15,25 +15,17 @@ ...@@ -15,25 +15,17 @@
15 */ 15 */
16 package org.onosproject.incubator.net.tunnel.impl; 16 package org.onosproject.incubator.net.tunnel.impl;
17 17
18 -import static com.google.common.base.Preconditions.checkNotNull;
19 -import static org.slf4j.LoggerFactory.getLogger;
20 -
21 -import java.util.Collection;
22 -import java.util.Collections;
23 -import java.util.Set;
24 -
25 import org.apache.felix.scr.annotations.Activate; 18 import org.apache.felix.scr.annotations.Activate;
26 import org.apache.felix.scr.annotations.Component; 19 import org.apache.felix.scr.annotations.Component;
27 import org.apache.felix.scr.annotations.Deactivate; 20 import org.apache.felix.scr.annotations.Deactivate;
28 import org.apache.felix.scr.annotations.Reference; 21 import org.apache.felix.scr.annotations.Reference;
29 import org.apache.felix.scr.annotations.ReferenceCardinality; 22 import org.apache.felix.scr.annotations.ReferenceCardinality;
30 import org.apache.felix.scr.annotations.Service; 23 import org.apache.felix.scr.annotations.Service;
24 +import org.onosproject.net.provider.AbstractListenerProviderRegistry;
31 import org.onosproject.core.ApplicationId; 25 import org.onosproject.core.ApplicationId;
32 -import org.onosproject.event.EventDeliveryService;
33 -import org.onosproject.event.ListenerRegistry;
34 import org.onosproject.incubator.net.tunnel.DefaultTunnel; 26 import org.onosproject.incubator.net.tunnel.DefaultTunnel;
35 -import org.onosproject.incubator.net.tunnel.Tunnel.Type;
36 import org.onosproject.incubator.net.tunnel.Tunnel; 27 import org.onosproject.incubator.net.tunnel.Tunnel;
28 +import org.onosproject.incubator.net.tunnel.Tunnel.Type;
37 import org.onosproject.incubator.net.tunnel.TunnelAdminService; 29 import org.onosproject.incubator.net.tunnel.TunnelAdminService;
38 import org.onosproject.incubator.net.tunnel.TunnelDescription; 30 import org.onosproject.incubator.net.tunnel.TunnelDescription;
39 import org.onosproject.incubator.net.tunnel.TunnelEndPoint; 31 import org.onosproject.incubator.net.tunnel.TunnelEndPoint;
...@@ -51,35 +43,36 @@ import org.onosproject.incubator.net.tunnel.TunnelSubscription; ...@@ -51,35 +43,36 @@ import org.onosproject.incubator.net.tunnel.TunnelSubscription;
51 import org.onosproject.net.Annotations; 43 import org.onosproject.net.Annotations;
52 import org.onosproject.net.DeviceId; 44 import org.onosproject.net.DeviceId;
53 import org.onosproject.net.Path; 45 import org.onosproject.net.Path;
54 -import org.onosproject.net.provider.AbstractProviderRegistry;
55 import org.onosproject.net.provider.AbstractProviderService; 46 import org.onosproject.net.provider.AbstractProviderService;
56 import org.onosproject.net.provider.ProviderId; 47 import org.onosproject.net.provider.ProviderId;
57 import org.slf4j.Logger; 48 import org.slf4j.Logger;
58 49
50 +import java.util.Collection;
51 +import java.util.Collections;
52 +import java.util.Set;
53 +
54 +import static com.google.common.base.Preconditions.checkNotNull;
55 +import static org.slf4j.LoggerFactory.getLogger;
56 +
59 /** 57 /**
60 * Provides implementation of the tunnel NB/SB APIs. 58 * Provides implementation of the tunnel NB/SB APIs.
61 */ 59 */
62 @Component(immediate = true, enabled = true) 60 @Component(immediate = true, enabled = true)
63 @Service 61 @Service
64 public class TunnelManager 62 public class TunnelManager
65 - extends AbstractProviderRegistry<TunnelProvider, TunnelProviderService> 63 + extends AbstractListenerProviderRegistry<TunnelEvent, TunnelListener,
64 + TunnelProvider, TunnelProviderService>
66 implements TunnelService, TunnelAdminService, TunnelProviderRegistry { 65 implements TunnelService, TunnelAdminService, TunnelProviderRegistry {
67 66
68 private static final String TUNNNEL_ID_NULL = "Tunnel ID cannot be null"; 67 private static final String TUNNNEL_ID_NULL = "Tunnel ID cannot be null";
69 68
70 private final Logger log = getLogger(getClass()); 69 private final Logger log = getLogger(getClass());
71 70
72 - protected final ListenerRegistry<TunnelEvent, TunnelListener>
73 - listenerRegistry = new ListenerRegistry<>();
74 -
75 private final TunnelStoreDelegate delegate = new InternalStoreDelegate(); 71 private final TunnelStoreDelegate delegate = new InternalStoreDelegate();
76 72
77 -
78 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 73 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
79 protected TunnelStore store; 74 protected TunnelStore store;
80 75
81 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
82 - protected EventDeliveryService eventDispatcher;
83 76
84 @Activate 77 @Activate
85 public void activate() { 78 public void activate() {
...@@ -294,16 +287,6 @@ public class TunnelManager ...@@ -294,16 +287,6 @@ public class TunnelManager
294 return new InternalTunnelProviderService(provider); 287 return new InternalTunnelProviderService(provider);
295 } 288 }
296 289
297 - @Override
298 - public void addListener(TunnelListener listener) {
299 - listenerRegistry.addListener(listener);
300 - }
301 -
302 - @Override
303 - public void removeListener(TunnelListener listener) {
304 - listenerRegistry.removeListener(listener);
305 - }
306 -
307 private class InternalTunnelProviderService 290 private class InternalTunnelProviderService
308 extends AbstractProviderService<TunnelProvider> 291 extends AbstractProviderService<TunnelProvider>
309 implements TunnelProviderService { 292 implements TunnelProviderService {
...@@ -370,7 +353,7 @@ public class TunnelManager ...@@ -370,7 +353,7 @@ public class TunnelManager
370 @Override 353 @Override
371 public void notify(TunnelEvent event) { 354 public void notify(TunnelEvent event) {
372 if (event != null) { 355 if (event != null) {
373 - eventDispatcher.post(event); 356 + post(event);
374 } 357 }
375 } 358 }
376 } 359 }
......