Showing
14 changed files
with
91 additions
and
17 deletions
... | @@ -4,12 +4,13 @@ import java.util.Set; | ... | @@ -4,12 +4,13 @@ import java.util.Set; |
4 | 4 | ||
5 | import org.onlab.onos.net.DeviceId; | 5 | import org.onlab.onos.net.DeviceId; |
6 | import org.onlab.onos.net.MastershipRole; | 6 | import org.onlab.onos.net.MastershipRole; |
7 | +import org.onlab.onos.store.Store; | ||
7 | 8 | ||
8 | /** | 9 | /** |
9 | * Manages inventory of mastership roles for devices, across controller | 10 | * Manages inventory of mastership roles for devices, across controller |
10 | * instances; not intended for direct use. | 11 | * instances; not intended for direct use. |
11 | */ | 12 | */ |
12 | -public interface MastershipStore { | 13 | +public interface MastershipStore extends Store<MastershipEvent, MastershipStoreDelegate> { |
13 | 14 | ||
14 | // three things to map: NodeId, DeviceId, MastershipRole | 15 | // three things to map: NodeId, DeviceId, MastershipRole |
15 | 16 | ... | ... |
... | @@ -5,13 +5,14 @@ import org.onlab.onos.net.DeviceId; | ... | @@ -5,13 +5,14 @@ import org.onlab.onos.net.DeviceId; |
5 | import org.onlab.onos.net.Port; | 5 | import org.onlab.onos.net.Port; |
6 | import org.onlab.onos.net.PortNumber; | 6 | import org.onlab.onos.net.PortNumber; |
7 | import org.onlab.onos.net.provider.ProviderId; | 7 | import org.onlab.onos.net.provider.ProviderId; |
8 | +import org.onlab.onos.store.Store; | ||
8 | 9 | ||
9 | import java.util.List; | 10 | import java.util.List; |
10 | 11 | ||
11 | /** | 12 | /** |
12 | * Manages inventory of infrastructure devices; not intended for direct use. | 13 | * Manages inventory of infrastructure devices; not intended for direct use. |
13 | */ | 14 | */ |
14 | -public interface DeviceStore { | 15 | +public interface DeviceStore extends Store<DeviceEvent, DeviceStoreDelegate> { |
15 | 16 | ||
16 | /** | 17 | /** |
17 | * Returns the number of devices known to the system. | 18 | * Returns the number of devices known to the system. | ... | ... |
1 | package org.onlab.onos.net.host; | 1 | package org.onlab.onos.net.host; |
2 | 2 | ||
3 | -import java.util.Set; | ||
4 | - | ||
5 | import org.onlab.onos.net.ConnectPoint; | 3 | import org.onlab.onos.net.ConnectPoint; |
6 | import org.onlab.onos.net.DeviceId; | 4 | import org.onlab.onos.net.DeviceId; |
7 | import org.onlab.onos.net.Host; | 5 | import org.onlab.onos.net.Host; |
8 | import org.onlab.onos.net.HostId; | 6 | import org.onlab.onos.net.HostId; |
9 | import org.onlab.onos.net.provider.ProviderId; | 7 | import org.onlab.onos.net.provider.ProviderId; |
8 | +import org.onlab.onos.store.Store; | ||
10 | import org.onlab.packet.IpPrefix; | 9 | import org.onlab.packet.IpPrefix; |
11 | import org.onlab.packet.MacAddress; | 10 | import org.onlab.packet.MacAddress; |
12 | import org.onlab.packet.VlanId; | 11 | import org.onlab.packet.VlanId; |
13 | 12 | ||
13 | +import java.util.Set; | ||
14 | + | ||
14 | /** | 15 | /** |
15 | * Manages inventory of end-station hosts; not intended for direct use. | 16 | * Manages inventory of end-station hosts; not intended for direct use. |
16 | */ | 17 | */ |
17 | -public interface HostStore { | 18 | +public interface HostStore extends Store<HostEvent, HostStoreDelegate> { |
18 | 19 | ||
19 | /** | 20 | /** |
20 | * Creates a new host or updates the existing one based on the specified | 21 | * Creates a new host or updates the existing one based on the specified |
... | @@ -133,7 +134,7 @@ public interface HostStore { | ... | @@ -133,7 +134,7 @@ public interface HostStore { |
133 | * Returns the address bindings for a particular connection point. | 134 | * Returns the address bindings for a particular connection point. |
134 | * | 135 | * |
135 | * @param connectPoint the connection point to return address information | 136 | * @param connectPoint the connection point to return address information |
136 | - * for | 137 | + * for |
137 | * @return address information for the connection point | 138 | * @return address information for the connection point |
138 | */ | 139 | */ |
139 | PortAddresses getAddressBindingsForPort(ConnectPoint connectPoint); | 140 | PortAddresses getAddressBindingsForPort(ConnectPoint connectPoint); | ... | ... |
... | @@ -4,13 +4,14 @@ import org.onlab.onos.net.ConnectPoint; | ... | @@ -4,13 +4,14 @@ import org.onlab.onos.net.ConnectPoint; |
4 | import org.onlab.onos.net.DeviceId; | 4 | import org.onlab.onos.net.DeviceId; |
5 | import org.onlab.onos.net.Link; | 5 | import org.onlab.onos.net.Link; |
6 | import org.onlab.onos.net.provider.ProviderId; | 6 | import org.onlab.onos.net.provider.ProviderId; |
7 | +import org.onlab.onos.store.Store; | ||
7 | 8 | ||
8 | import java.util.Set; | 9 | import java.util.Set; |
9 | 10 | ||
10 | /** | 11 | /** |
11 | * Manages inventory of infrastructure links; not intended for direct use. | 12 | * Manages inventory of infrastructure links; not intended for direct use. |
12 | */ | 13 | */ |
13 | -public interface LinkStore { | 14 | +public interface LinkStore extends Store<LinkEvent, LinkStoreDelegate> { |
14 | 15 | ||
15 | /** | 16 | /** |
16 | * Returns the number of links in the store. | 17 | * Returns the number of links in the store. | ... | ... |
... | @@ -2,6 +2,8 @@ package org.onlab.onos.store; | ... | @@ -2,6 +2,8 @@ package org.onlab.onos.store; |
2 | 2 | ||
3 | import org.onlab.onos.event.Event; | 3 | import org.onlab.onos.event.Event; |
4 | 4 | ||
5 | +import static com.google.common.base.Preconditions.checkState; | ||
6 | + | ||
5 | /** | 7 | /** |
6 | * Base implementation of a store. | 8 | * Base implementation of a store. |
7 | */ | 9 | */ |
... | @@ -12,12 +14,21 @@ public class AbstractStore<E extends Event, D extends StoreDelegate<E>> | ... | @@ -12,12 +14,21 @@ public class AbstractStore<E extends Event, D extends StoreDelegate<E>> |
12 | 14 | ||
13 | @Override | 15 | @Override |
14 | public void setDelegate(D delegate) { | 16 | public void setDelegate(D delegate) { |
17 | + checkState(this.delegate == null || this.delegate == delegate, | ||
18 | + "Store delegate already set"); | ||
15 | this.delegate = delegate; | 19 | this.delegate = delegate; |
16 | } | 20 | } |
17 | 21 | ||
18 | @Override | 22 | @Override |
19 | - public D getDelegate() { | 23 | + public void unsetDelegate(D delegate) { |
20 | - return delegate; | 24 | + if (this.delegate == delegate) { |
25 | + this.delegate = null; | ||
26 | + } | ||
27 | + } | ||
28 | + | ||
29 | + @Override | ||
30 | + public boolean hasDelegate() { | ||
31 | + return delegate != null; | ||
21 | } | 32 | } |
22 | 33 | ||
23 | /** | 34 | /** | ... | ... |
... | @@ -12,14 +12,25 @@ public interface Store<E extends Event, D extends StoreDelegate<E>> { | ... | @@ -12,14 +12,25 @@ public interface Store<E extends Event, D extends StoreDelegate<E>> { |
12 | * Sets the delegate on the store. | 12 | * Sets the delegate on the store. |
13 | * | 13 | * |
14 | * @param delegate new store delegate | 14 | * @param delegate new store delegate |
15 | + * @throws java.lang.IllegalStateException if a delegate is already | ||
16 | + * currently set on the store and is a different one that | ||
15 | */ | 17 | */ |
16 | void setDelegate(D delegate); | 18 | void setDelegate(D delegate); |
17 | 19 | ||
18 | /** | 20 | /** |
19 | - * Get the current store delegate. | 21 | + * Withdraws the delegate from the store. |
20 | * | 22 | * |
21 | - * @return store delegate | 23 | + * @param delegate store delegate to withdraw |
24 | + * @throws java.lang.IllegalArgumentException if the delegate is not | ||
25 | + * currently set on the store | ||
22 | */ | 26 | */ |
23 | - D getDelegate(); | 27 | + void unsetDelegate(D delegate); |
28 | + | ||
29 | + /** | ||
30 | + * Indicates whether the store has a delegate. | ||
31 | + * | ||
32 | + * @return true if delegate is set | ||
33 | + */ | ||
34 | + boolean hasDelegate(); | ||
24 | 35 | ||
25 | } | 36 | } | ... | ... |
... | @@ -53,6 +53,7 @@ public class ClusterManager implements ClusterService, ClusterAdminService { | ... | @@ -53,6 +53,7 @@ public class ClusterManager implements ClusterService, ClusterAdminService { |
53 | 53 | ||
54 | @Deactivate | 54 | @Deactivate |
55 | public void deactivate() { | 55 | public void deactivate() { |
56 | + store.unsetDelegate(delegate); | ||
56 | eventDispatcher.removeSink(ClusterEvent.class); | 57 | eventDispatcher.removeSink(ClusterEvent.class); |
57 | log.info("Stopped"); | 58 | log.info("Stopped"); |
58 | } | 59 | } | ... | ... |
... | @@ -26,6 +26,7 @@ import org.onlab.onos.net.device.DeviceProviderRegistry; | ... | @@ -26,6 +26,7 @@ import org.onlab.onos.net.device.DeviceProviderRegistry; |
26 | import org.onlab.onos.net.device.DeviceProviderService; | 26 | import org.onlab.onos.net.device.DeviceProviderService; |
27 | import org.onlab.onos.net.device.DeviceService; | 27 | import org.onlab.onos.net.device.DeviceService; |
28 | import org.onlab.onos.net.device.DeviceStore; | 28 | import org.onlab.onos.net.device.DeviceStore; |
29 | +import org.onlab.onos.net.device.DeviceStoreDelegate; | ||
29 | import org.onlab.onos.net.device.PortDescription; | 30 | import org.onlab.onos.net.device.PortDescription; |
30 | import org.onlab.onos.net.provider.AbstractProviderRegistry; | 31 | import org.onlab.onos.net.provider.AbstractProviderRegistry; |
31 | import org.onlab.onos.net.provider.AbstractProviderService; | 32 | import org.onlab.onos.net.provider.AbstractProviderService; |
... | @@ -33,8 +34,8 @@ import org.slf4j.Logger; | ... | @@ -33,8 +34,8 @@ import org.slf4j.Logger; |
33 | 34 | ||
34 | import java.util.List; | 35 | import java.util.List; |
35 | 36 | ||
36 | -import static org.onlab.onos.net.device.DeviceEvent.Type.*; | ||
37 | import static com.google.common.base.Preconditions.checkNotNull; | 37 | import static com.google.common.base.Preconditions.checkNotNull; |
38 | +import static org.onlab.onos.net.device.DeviceEvent.Type.DEVICE_MASTERSHIP_CHANGED; | ||
38 | import static org.slf4j.LoggerFactory.getLogger; | 39 | import static org.slf4j.LoggerFactory.getLogger; |
39 | 40 | ||
40 | /** | 41 | /** |
... | @@ -57,6 +58,8 @@ public class DeviceManager | ... | @@ -57,6 +58,8 @@ public class DeviceManager |
57 | protected final AbstractListenerRegistry<DeviceEvent, DeviceListener> | 58 | protected final AbstractListenerRegistry<DeviceEvent, DeviceListener> |
58 | listenerRegistry = new AbstractListenerRegistry<>(); | 59 | listenerRegistry = new AbstractListenerRegistry<>(); |
59 | 60 | ||
61 | + private DeviceStoreDelegate delegate = new InternalStoreDelegate(); | ||
62 | + | ||
60 | private final MastershipListener mastershipListener = new InnerMastershipListener(); | 63 | private final MastershipListener mastershipListener = new InnerMastershipListener(); |
61 | 64 | ||
62 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 65 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
... | @@ -73,6 +76,7 @@ public class DeviceManager | ... | @@ -73,6 +76,7 @@ public class DeviceManager |
73 | 76 | ||
74 | @Activate | 77 | @Activate |
75 | public void activate() { | 78 | public void activate() { |
79 | + store.setDelegate(delegate); | ||
76 | eventDispatcher.addSink(DeviceEvent.class, listenerRegistry); | 80 | eventDispatcher.addSink(DeviceEvent.class, listenerRegistry); |
77 | mastershipService.addListener(mastershipListener); | 81 | mastershipService.addListener(mastershipListener); |
78 | log.info("Started"); | 82 | log.info("Started"); |
... | @@ -80,6 +84,7 @@ public class DeviceManager | ... | @@ -80,6 +84,7 @@ public class DeviceManager |
80 | 84 | ||
81 | @Deactivate | 85 | @Deactivate |
82 | public void deactivate() { | 86 | public void deactivate() { |
87 | + store.unsetDelegate(delegate); | ||
83 | mastershipService.removeListener(mastershipListener); | 88 | mastershipService.removeListener(mastershipListener); |
84 | eventDispatcher.removeSink(DeviceEvent.class); | 89 | eventDispatcher.removeSink(DeviceEvent.class); |
85 | log.info("Stopped"); | 90 | log.info("Stopped"); |
... | @@ -248,4 +253,12 @@ public class DeviceManager | ... | @@ -248,4 +253,12 @@ public class DeviceManager |
248 | } | 253 | } |
249 | } | 254 | } |
250 | } | 255 | } |
256 | + | ||
257 | + // Store delegate to re-post events emitted from the store. | ||
258 | + private class InternalStoreDelegate implements DeviceStoreDelegate { | ||
259 | + @Override | ||
260 | + public void notify(DeviceEvent event) { | ||
261 | + post(event); | ||
262 | + } | ||
263 | + } | ||
251 | } | 264 | } | ... | ... |
... | @@ -15,8 +15,10 @@ import org.onlab.onos.net.PortNumber; | ... | @@ -15,8 +15,10 @@ import org.onlab.onos.net.PortNumber; |
15 | import org.onlab.onos.net.device.DeviceDescription; | 15 | import org.onlab.onos.net.device.DeviceDescription; |
16 | import org.onlab.onos.net.device.DeviceEvent; | 16 | import org.onlab.onos.net.device.DeviceEvent; |
17 | import org.onlab.onos.net.device.DeviceStore; | 17 | import org.onlab.onos.net.device.DeviceStore; |
18 | +import org.onlab.onos.net.device.DeviceStoreDelegate; | ||
18 | import org.onlab.onos.net.device.PortDescription; | 19 | import org.onlab.onos.net.device.PortDescription; |
19 | import org.onlab.onos.net.provider.ProviderId; | 20 | import org.onlab.onos.net.provider.ProviderId; |
21 | +import org.onlab.onos.store.AbstractStore; | ||
20 | import org.slf4j.Logger; | 22 | import org.slf4j.Logger; |
21 | 23 | ||
22 | import java.util.ArrayList; | 24 | import java.util.ArrayList; |
... | @@ -40,7 +42,9 @@ import static org.slf4j.LoggerFactory.getLogger; | ... | @@ -40,7 +42,9 @@ import static org.slf4j.LoggerFactory.getLogger; |
40 | */ | 42 | */ |
41 | @Component(immediate = true) | 43 | @Component(immediate = true) |
42 | @Service | 44 | @Service |
43 | -public class SimpleDeviceStore implements DeviceStore { | 45 | +public class SimpleDeviceStore |
46 | + extends AbstractStore<DeviceEvent, DeviceStoreDelegate> | ||
47 | + implements DeviceStore { | ||
44 | 48 | ||
45 | private final Logger log = getLogger(getClass()); | 49 | private final Logger log = getLogger(getClass()); |
46 | 50 | ... | ... |
... | @@ -24,8 +24,10 @@ import org.onlab.onos.net.HostId; | ... | @@ -24,8 +24,10 @@ import org.onlab.onos.net.HostId; |
24 | import org.onlab.onos.net.host.HostDescription; | 24 | import org.onlab.onos.net.host.HostDescription; |
25 | import org.onlab.onos.net.host.HostEvent; | 25 | import org.onlab.onos.net.host.HostEvent; |
26 | import org.onlab.onos.net.host.HostStore; | 26 | import org.onlab.onos.net.host.HostStore; |
27 | +import org.onlab.onos.net.host.HostStoreDelegate; | ||
27 | import org.onlab.onos.net.host.PortAddresses; | 28 | import org.onlab.onos.net.host.PortAddresses; |
28 | import org.onlab.onos.net.provider.ProviderId; | 29 | import org.onlab.onos.net.provider.ProviderId; |
30 | +import org.onlab.onos.store.AbstractStore; | ||
29 | import org.onlab.packet.IpPrefix; | 31 | import org.onlab.packet.IpPrefix; |
30 | import org.onlab.packet.MacAddress; | 32 | import org.onlab.packet.MacAddress; |
31 | import org.onlab.packet.VlanId; | 33 | import org.onlab.packet.VlanId; |
... | @@ -41,7 +43,9 @@ import com.google.common.collect.Multimap; | ... | @@ -41,7 +43,9 @@ import com.google.common.collect.Multimap; |
41 | */ | 43 | */ |
42 | @Component(immediate = true) | 44 | @Component(immediate = true) |
43 | @Service | 45 | @Service |
44 | -public class SimpleHostStore implements HostStore { | 46 | +public class SimpleHostStore |
47 | + extends AbstractStore<HostEvent, HostStoreDelegate> | ||
48 | + implements HostStore { | ||
45 | 49 | ||
46 | private final Logger log = getLogger(getClass()); | 50 | private final Logger log = getLogger(getClass()); |
47 | 51 | ... | ... |
... | @@ -14,7 +14,9 @@ import org.onlab.onos.net.Link; | ... | @@ -14,7 +14,9 @@ import org.onlab.onos.net.Link; |
14 | import org.onlab.onos.net.link.LinkDescription; | 14 | import org.onlab.onos.net.link.LinkDescription; |
15 | import org.onlab.onos.net.link.LinkEvent; | 15 | import org.onlab.onos.net.link.LinkEvent; |
16 | import org.onlab.onos.net.link.LinkStore; | 16 | import org.onlab.onos.net.link.LinkStore; |
17 | +import org.onlab.onos.net.link.LinkStoreDelegate; | ||
17 | import org.onlab.onos.net.provider.ProviderId; | 18 | import org.onlab.onos.net.provider.ProviderId; |
19 | +import org.onlab.onos.store.AbstractStore; | ||
18 | import org.slf4j.Logger; | 20 | import org.slf4j.Logger; |
19 | 21 | ||
20 | import java.util.Collections; | 22 | import java.util.Collections; |
... | @@ -35,7 +37,9 @@ import static org.slf4j.LoggerFactory.getLogger; | ... | @@ -35,7 +37,9 @@ import static org.slf4j.LoggerFactory.getLogger; |
35 | */ | 37 | */ |
36 | @Component(immediate = true) | 38 | @Component(immediate = true) |
37 | @Service | 39 | @Service |
38 | -public class SimpleLinkStore implements LinkStore { | 40 | +public class SimpleLinkStore |
41 | + extends AbstractStore<LinkEvent, LinkStoreDelegate> | ||
42 | + implements LinkStore { | ||
39 | 43 | ||
40 | private final Logger log = getLogger(getClass()); | 44 | private final Logger log = getLogger(getClass()); |
41 | 45 | ... | ... |
... | @@ -15,9 +15,11 @@ import org.onlab.onos.cluster.ControllerNode; | ... | @@ -15,9 +15,11 @@ import org.onlab.onos.cluster.ControllerNode; |
15 | import org.onlab.onos.cluster.DefaultControllerNode; | 15 | import org.onlab.onos.cluster.DefaultControllerNode; |
16 | import org.onlab.onos.cluster.MastershipEvent; | 16 | import org.onlab.onos.cluster.MastershipEvent; |
17 | import org.onlab.onos.cluster.MastershipStore; | 17 | import org.onlab.onos.cluster.MastershipStore; |
18 | +import org.onlab.onos.cluster.MastershipStoreDelegate; | ||
18 | import org.onlab.onos.cluster.NodeId; | 19 | import org.onlab.onos.cluster.NodeId; |
19 | import org.onlab.onos.net.DeviceId; | 20 | import org.onlab.onos.net.DeviceId; |
20 | import org.onlab.onos.net.MastershipRole; | 21 | import org.onlab.onos.net.MastershipRole; |
22 | +import org.onlab.onos.store.AbstractStore; | ||
21 | import org.onlab.packet.IpPrefix; | 23 | import org.onlab.packet.IpPrefix; |
22 | import org.slf4j.Logger; | 24 | import org.slf4j.Logger; |
23 | 25 | ||
... | @@ -29,7 +31,9 @@ import static org.onlab.onos.cluster.MastershipEvent.Type.*; | ... | @@ -29,7 +31,9 @@ import static org.onlab.onos.cluster.MastershipEvent.Type.*; |
29 | */ | 31 | */ |
30 | @Component(immediate = true) | 32 | @Component(immediate = true) |
31 | @Service | 33 | @Service |
32 | -public class SimpleMastershipStore implements MastershipStore { | 34 | +public class SimpleMastershipStore |
35 | + extends AbstractStore<MastershipEvent, MastershipStoreDelegate> | ||
36 | + implements MastershipStore { | ||
33 | 37 | ||
34 | public static final IpPrefix LOCALHOST = IpPrefix.valueOf("127.0.0.1"); | 38 | public static final IpPrefix LOCALHOST = IpPrefix.valueOf("127.0.0.1"); |
35 | 39 | ... | ... |
-
Please register or login to post a comment