Converted UiSharedTopologyModel to be a @Service.
Change-Id: Idc8df1b9c0a52db01ac545567dacc0e1c770f84a
Showing
13 changed files
with
335 additions
and
140 deletions
... | @@ -16,6 +16,7 @@ | ... | @@ -16,6 +16,7 @@ |
16 | 16 | ||
17 | package org.onosproject.net.region; | 17 | package org.onosproject.net.region; |
18 | 18 | ||
19 | +import org.onosproject.event.ListenerService; | ||
19 | import org.onosproject.net.DeviceId; | 20 | import org.onosproject.net.DeviceId; |
20 | 21 | ||
21 | import java.util.Set; | 22 | import java.util.Set; |
... | @@ -23,7 +24,7 @@ import java.util.Set; | ... | @@ -23,7 +24,7 @@ import java.util.Set; |
23 | /** | 24 | /** |
24 | * Service for interacting with inventory of network control regions. | 25 | * Service for interacting with inventory of network control regions. |
25 | */ | 26 | */ |
26 | -public interface RegionService { | 27 | +public interface RegionService extends ListenerService<RegionEvent, RegionListener> { |
27 | 28 | ||
28 | /** | 29 | /** |
29 | * Returns set of all regions. | 30 | * Returns set of all regions. | ... | ... |
... | @@ -19,5 +19,5 @@ package org.onosproject.ui.model.topo; | ... | @@ -19,5 +19,5 @@ package org.onosproject.ui.model.topo; |
19 | /** | 19 | /** |
20 | * Encapsulates the notion of the ONOS cluster. | 20 | * Encapsulates the notion of the ONOS cluster. |
21 | */ | 21 | */ |
22 | -public class UiCluster { | 22 | +public class UiCluster extends UiElement { |
23 | } | 23 | } | ... | ... |
... | @@ -19,5 +19,5 @@ package org.onosproject.ui.model.topo; | ... | @@ -19,5 +19,5 @@ package org.onosproject.ui.model.topo; |
19 | /** | 19 | /** |
20 | * Represents an individual member of the cluster (ONOS instance). | 20 | * Represents an individual member of the cluster (ONOS instance). |
21 | */ | 21 | */ |
22 | -public class UiClusterMember { | 22 | +public class UiClusterMember extends UiElement { |
23 | } | 23 | } | ... | ... |
1 | +/* | ||
2 | + * Copyright 2016 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 | +package org.onosproject.ui.model.topo; | ||
18 | + | ||
19 | +/** | ||
20 | + * Abstract base class of all elements in the UI topology model. | ||
21 | + */ | ||
22 | +public class UiElement { | ||
23 | +} |
... | @@ -19,5 +19,5 @@ package org.onosproject.ui.model.topo; | ... | @@ -19,5 +19,5 @@ package org.onosproject.ui.model.topo; |
19 | /** | 19 | /** |
20 | * Represents a bi-directional link backed by two uni-directional links. | 20 | * Represents a bi-directional link backed by two uni-directional links. |
21 | */ | 21 | */ |
22 | -public class UiLink { | 22 | +public class UiLink extends UiElement { |
23 | } | 23 | } | ... | ... |
... | @@ -19,5 +19,5 @@ package org.onosproject.ui.model.topo; | ... | @@ -19,5 +19,5 @@ package org.onosproject.ui.model.topo; |
19 | /** | 19 | /** |
20 | * Represents a node drawn on the topology view (region, device, host). | 20 | * Represents a node drawn on the topology view (region, device, host). |
21 | */ | 21 | */ |
22 | -public abstract class UiNode { | 22 | +public abstract class UiNode extends UiElement { |
23 | } | 23 | } | ... | ... |
... | @@ -19,5 +19,5 @@ package org.onosproject.ui.model.topo; | ... | @@ -19,5 +19,5 @@ package org.onosproject.ui.model.topo; |
19 | /** | 19 | /** |
20 | * Represents the overall network topology. | 20 | * Represents the overall network topology. |
21 | */ | 21 | */ |
22 | -public class UiTopology { | 22 | +public class UiTopology extends UiElement { |
23 | } | 23 | } | ... | ... |
... | @@ -29,6 +29,7 @@ import org.onosproject.ui.UiMessageHandlerFactory; | ... | @@ -29,6 +29,7 @@ import org.onosproject.ui.UiMessageHandlerFactory; |
29 | import org.onosproject.ui.UiMessageHandler; | 29 | import org.onosproject.ui.UiMessageHandler; |
30 | import org.onosproject.ui.UiTopoOverlayFactory; | 30 | import org.onosproject.ui.UiTopoOverlayFactory; |
31 | import org.onosproject.ui.impl.topo.UiTopoSession; | 31 | import org.onosproject.ui.impl.topo.UiTopoSession; |
32 | +import org.onosproject.ui.impl.topo.model.UiSharedTopologyModel; | ||
32 | import org.onosproject.ui.topo.TopoConstants; | 33 | import org.onosproject.ui.topo.TopoConstants; |
33 | import org.slf4j.Logger; | 34 | import org.slf4j.Logger; |
34 | import org.slf4j.LoggerFactory; | 35 | import org.slf4j.LoggerFactory; |
... | @@ -65,7 +66,7 @@ public class UiWebSocket | ... | @@ -65,7 +66,7 @@ public class UiWebSocket |
65 | private TopoOverlayCache overlayCache; | 66 | private TopoOverlayCache overlayCache; |
66 | 67 | ||
67 | /** | 68 | /** |
68 | - * Creates a new web-socket for serving data to GUI. | 69 | + * Creates a new web-socket for serving data to the Web UI. |
69 | * | 70 | * |
70 | * @param directory service directory | 71 | * @param directory service directory |
71 | * @param userName user name of the logged-in user | 72 | * @param userName user name of the logged-in user |
... | @@ -73,7 +74,8 @@ public class UiWebSocket | ... | @@ -73,7 +74,8 @@ public class UiWebSocket |
73 | public UiWebSocket(ServiceDirectory directory, String userName) { | 74 | public UiWebSocket(ServiceDirectory directory, String userName) { |
74 | this.directory = directory; | 75 | this.directory = directory; |
75 | this.userName = userName; | 76 | this.userName = userName; |
76 | - this.topoSession = new UiTopoSession(this); | 77 | + this.topoSession = |
78 | + new UiTopoSession(this, directory.get(UiSharedTopologyModel.class)); | ||
77 | } | 79 | } |
78 | 80 | ||
79 | @Override | 81 | @Override | ... | ... |
... | @@ -18,6 +18,8 @@ package org.onosproject.ui.impl.topo; | ... | @@ -18,6 +18,8 @@ package org.onosproject.ui.impl.topo; |
18 | 18 | ||
19 | import org.onosproject.ui.UiTopoLayoutService; | 19 | import org.onosproject.ui.UiTopoLayoutService; |
20 | import org.onosproject.ui.impl.UiWebSocket; | 20 | import org.onosproject.ui.impl.UiWebSocket; |
21 | +import org.onosproject.ui.impl.topo.model.UiModelEvent; | ||
22 | +import org.onosproject.ui.impl.topo.model.UiModelListener; | ||
21 | import org.onosproject.ui.impl.topo.model.UiSharedTopologyModel; | 23 | import org.onosproject.ui.impl.topo.model.UiSharedTopologyModel; |
22 | import org.onosproject.ui.model.topo.UiTopoLayout; | 24 | import org.onosproject.ui.model.topo.UiTopoLayout; |
23 | import org.slf4j.Logger; | 25 | import org.slf4j.Logger; |
... | @@ -26,14 +28,14 @@ import org.slf4j.LoggerFactory; | ... | @@ -26,14 +28,14 @@ import org.slf4j.LoggerFactory; |
26 | /** | 28 | /** |
27 | * Coordinates with the {@link UiTopoLayoutService} to access | 29 | * Coordinates with the {@link UiTopoLayoutService} to access |
28 | * {@link UiTopoLayout}s, and with the {@link UiSharedTopologyModel} which | 30 | * {@link UiTopoLayout}s, and with the {@link UiSharedTopologyModel} which |
29 | - * maintains a local model of the network entities, | 31 | + * maintains a local model of the network entities, tailored specifically |
30 | - * tailored specifically for displaying on the UI. | 32 | + * for displaying on the UI. |
31 | * <p> | 33 | * <p> |
32 | * Note that an instance of this class will be created for each | 34 | * Note that an instance of this class will be created for each |
33 | * {@link UiWebSocket} connection, and will contain | 35 | * {@link UiWebSocket} connection, and will contain |
34 | * the state of how the topology is laid out for the logged-in user. | 36 | * the state of how the topology is laid out for the logged-in user. |
35 | */ | 37 | */ |
36 | -public class UiTopoSession { | 38 | +public class UiTopoSession implements UiModelListener { |
37 | private final Logger log = LoggerFactory.getLogger(getClass()); | 39 | private final Logger log = LoggerFactory.getLogger(getClass()); |
38 | 40 | ||
39 | private final UiWebSocket webSocket; | 41 | private final UiWebSocket webSocket; |
... | @@ -50,11 +52,12 @@ public class UiTopoSession { | ... | @@ -50,11 +52,12 @@ public class UiTopoSession { |
50 | * Creates a new topology session for the specified web socket connection. | 52 | * Creates a new topology session for the specified web socket connection. |
51 | * | 53 | * |
52 | * @param webSocket web socket | 54 | * @param webSocket web socket |
55 | + * @param model share topology model | ||
53 | */ | 56 | */ |
54 | - public UiTopoSession(UiWebSocket webSocket) { | 57 | + public UiTopoSession(UiWebSocket webSocket, UiSharedTopologyModel model) { |
55 | this.webSocket = webSocket; | 58 | this.webSocket = webSocket; |
56 | this.username = webSocket.userName(); | 59 | this.username = webSocket.userName(); |
57 | - this.sharedModel = UiSharedTopologyModel.instance(); | 60 | + this.sharedModel = model; |
58 | } | 61 | } |
59 | 62 | ||
60 | /** | 63 | /** |
... | @@ -87,4 +90,10 @@ public class UiTopoSession { | ... | @@ -87,4 +90,10 @@ public class UiTopoSession { |
87 | public String toString() { | 90 | public String toString() { |
88 | return String.format("{UiTopoSession for user <%s>}", username); | 91 | return String.format("{UiTopoSession for user <%s>}", username); |
89 | } | 92 | } |
93 | + | ||
94 | + @Override | ||
95 | + public void event(UiModelEvent event) { | ||
96 | + log.info("Event received: {}", event); | ||
97 | + // TODO: handle model events from the cache... | ||
98 | + } | ||
90 | } | 99 | } | ... | ... |
1 | +/* | ||
2 | + * Copyright 2016 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 | +package org.onosproject.ui.impl.topo.model; | ||
18 | + | ||
19 | +import org.onosproject.event.EventDispatcher; | ||
20 | +import org.onosproject.net.Device; | ||
21 | +import org.onosproject.ui.model.topo.UiDevice; | ||
22 | + | ||
23 | +/** | ||
24 | + * UI Topology Model cache. | ||
25 | + */ | ||
26 | +class ModelCache { | ||
27 | + | ||
28 | + private final EventDispatcher dispatcher; | ||
29 | + | ||
30 | + ModelCache(EventDispatcher eventDispatcher) { | ||
31 | + this.dispatcher = eventDispatcher; | ||
32 | + } | ||
33 | + | ||
34 | + /** | ||
35 | + * Clear our model. | ||
36 | + */ | ||
37 | + void clear() { | ||
38 | + // TODO: clear our internal state | ||
39 | + } | ||
40 | + | ||
41 | + /** | ||
42 | + * Create our internal model of the global topology. | ||
43 | + */ | ||
44 | + void load() { | ||
45 | +// loadClusterMembers(); | ||
46 | +// loadRegions(); | ||
47 | +// loadDevices(); | ||
48 | +// loadHosts(); | ||
49 | +// loadLinks(); | ||
50 | + } | ||
51 | + | ||
52 | + | ||
53 | + // add or update device | ||
54 | + void addOrUpdateDevice(Device device) { | ||
55 | + // fetch UiDevice | ||
56 | + UiDevice uiDevice = new UiDevice(); | ||
57 | + | ||
58 | + dispatcher.post( | ||
59 | + new UiModelEvent(UiModelEvent.Type.DEVICE_ADDED, uiDevice) | ||
60 | + ); | ||
61 | + | ||
62 | + } | ||
63 | + | ||
64 | + void removeDevice(Device device) { | ||
65 | + UiDevice uiDevice = new UiDevice(); | ||
66 | + | ||
67 | + dispatcher.post( | ||
68 | + new UiModelEvent(UiModelEvent.Type.DEVICE_REMOVED, uiDevice) | ||
69 | + ); | ||
70 | + | ||
71 | + } | ||
72 | + | ||
73 | + // TODO remaining model objects | ||
74 | + | ||
75 | +} |
1 | +/* | ||
2 | + * Copyright 2016 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 | +package org.onosproject.ui.impl.topo.model; | ||
18 | + | ||
19 | +import org.onosproject.event.AbstractEvent; | ||
20 | +import org.onosproject.ui.model.topo.UiElement; | ||
21 | + | ||
22 | +/** | ||
23 | + * UI Topology model events. | ||
24 | + */ | ||
25 | +public class UiModelEvent extends AbstractEvent<UiModelEvent.Type, UiElement> { | ||
26 | + | ||
27 | + protected UiModelEvent(Type type, UiElement subject) { | ||
28 | + super(type, subject); | ||
29 | + } | ||
30 | + | ||
31 | + enum Type { | ||
32 | + DEVICE_ADDED, | ||
33 | + DEVICE_REMOVED, | ||
34 | + // TODO... | ||
35 | + } | ||
36 | +} |
1 | +/* | ||
2 | + * Copyright 2016 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 | +package org.onosproject.ui.impl.topo.model; | ||
18 | + | ||
19 | +import org.onosproject.event.EventListener; | ||
20 | + | ||
21 | +/** | ||
22 | + * Can receive {@link UiModelEvent}s. | ||
23 | + */ | ||
24 | +public interface UiModelListener extends EventListener<UiModelEvent> { | ||
25 | +} |
... | @@ -16,16 +16,22 @@ | ... | @@ -16,16 +16,22 @@ |
16 | 16 | ||
17 | package org.onosproject.ui.impl.topo.model; | 17 | package org.onosproject.ui.impl.topo.model; |
18 | 18 | ||
19 | -import org.onlab.osgi.DefaultServiceDirectory; | 19 | +import org.apache.felix.scr.annotations.Activate; |
20 | -import org.onlab.osgi.ServiceDirectory; | 20 | +import org.apache.felix.scr.annotations.Component; |
21 | +import org.apache.felix.scr.annotations.Deactivate; | ||
22 | +import org.apache.felix.scr.annotations.Reference; | ||
23 | +import org.apache.felix.scr.annotations.ReferenceCardinality; | ||
24 | +import org.apache.felix.scr.annotations.Service; | ||
21 | import org.onosproject.cluster.ClusterEvent; | 25 | import org.onosproject.cluster.ClusterEvent; |
22 | import org.onosproject.cluster.ClusterEventListener; | 26 | import org.onosproject.cluster.ClusterEventListener; |
23 | import org.onosproject.cluster.ClusterService; | 27 | import org.onosproject.cluster.ClusterService; |
28 | +import org.onosproject.event.AbstractListenerManager; | ||
24 | import org.onosproject.incubator.net.PortStatisticsService; | 29 | import org.onosproject.incubator.net.PortStatisticsService; |
25 | import org.onosproject.incubator.net.tunnel.TunnelService; | 30 | import org.onosproject.incubator.net.tunnel.TunnelService; |
26 | import org.onosproject.mastership.MastershipEvent; | 31 | import org.onosproject.mastership.MastershipEvent; |
27 | import org.onosproject.mastership.MastershipListener; | 32 | import org.onosproject.mastership.MastershipListener; |
28 | import org.onosproject.mastership.MastershipService; | 33 | import org.onosproject.mastership.MastershipService; |
34 | +import org.onosproject.net.Device; | ||
29 | import org.onosproject.net.device.DeviceEvent; | 35 | import org.onosproject.net.device.DeviceEvent; |
30 | import org.onosproject.net.device.DeviceListener; | 36 | import org.onosproject.net.device.DeviceListener; |
31 | import org.onosproject.net.device.DeviceService; | 37 | import org.onosproject.net.device.DeviceService; |
... | @@ -50,30 +56,104 @@ import org.onosproject.ui.impl.topo.UiTopoSession; | ... | @@ -50,30 +56,104 @@ import org.onosproject.ui.impl.topo.UiTopoSession; |
50 | import org.slf4j.Logger; | 56 | import org.slf4j.Logger; |
51 | import org.slf4j.LoggerFactory; | 57 | import org.slf4j.LoggerFactory; |
52 | 58 | ||
53 | -import java.util.HashSet; | ||
54 | -import java.util.Set; | ||
55 | - | ||
56 | /** | 59 | /** |
57 | - * A lazily-initialized Singleton that creates and maintains the UI-model | 60 | + * Service that creates and maintains the UI-model of the network topology. |
58 | - * of the network topology. | ||
59 | */ | 61 | */ |
60 | -public final class UiSharedTopologyModel { | 62 | +@Component(immediate = true) |
63 | +@Service(value = UiSharedTopologyModel.class) | ||
64 | +public final class UiSharedTopologyModel | ||
65 | + extends AbstractListenerManager<UiModelEvent, UiModelListener> { | ||
61 | 66 | ||
62 | private static final Logger log = | 67 | private static final Logger log = |
63 | LoggerFactory.getLogger(UiSharedTopologyModel.class); | 68 | LoggerFactory.getLogger(UiSharedTopologyModel.class); |
64 | 69 | ||
65 | - private final ModelEventListener modelEventListener; | 70 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
71 | + private ClusterService clusterService; | ||
72 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
73 | + private MastershipService mastershipService; | ||
74 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
75 | + private RegionService regionService; | ||
76 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
77 | + private DeviceService deviceService; | ||
78 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
79 | + private LinkService linkService; | ||
80 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
81 | + private HostService hostService; | ||
82 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
83 | + private IntentService intentService; | ||
84 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
85 | + private FlowRuleService flowService; | ||
86 | + | ||
87 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
88 | + private StatisticService flowStatsService; | ||
89 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
90 | + private PortStatisticsService portStatsService; | ||
91 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
92 | + private TopologyService topologyService; | ||
93 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
94 | + private TunnelService tunnelService; | ||
95 | + | ||
96 | + private final ClusterEventListener clusterListener = | ||
97 | + new InternalClusterListener(); | ||
98 | + private final MastershipListener mastershipListener = | ||
99 | + new InternalMastershipListener(); | ||
100 | + private final RegionListener regionListener = | ||
101 | + new InternalRegionListener(); | ||
102 | + private final DeviceListener deviceListener = | ||
103 | + new InternalDeviceListener(); | ||
104 | + private final LinkListener linkListener = | ||
105 | + new InternalLinkListener(); | ||
106 | + private final HostListener hostListener = | ||
107 | + new InternalHostListener(); | ||
108 | + private final IntentListener intentListener = | ||
109 | + new InternalIntentListener(); | ||
110 | + private final FlowRuleListener flowRuleListener = | ||
111 | + new InternalFlowRuleListener(); | ||
112 | + | ||
113 | + | ||
114 | + private ModelCache cache; | ||
115 | + | ||
116 | + | ||
117 | + @Activate | ||
118 | + protected void activate() { | ||
119 | + cache = new ModelCache(eventDispatcher); | ||
120 | + | ||
121 | + eventDispatcher.addSink(UiModelEvent.class, listenerRegistry); | ||
122 | + | ||
123 | + clusterService.addListener(clusterListener); | ||
124 | + mastershipService.addListener(mastershipListener); | ||
125 | + regionService.addListener(regionListener); | ||
126 | + deviceService.addListener(deviceListener); | ||
127 | + linkService.addListener(linkListener); | ||
128 | + hostService.addListener(hostListener); | ||
129 | + intentService.addListener(intentListener); | ||
130 | + flowService.addListener(flowRuleListener); | ||
131 | + | ||
132 | + cache.load(); | ||
133 | + | ||
134 | + log.info("Started"); | ||
135 | + } | ||
136 | + | ||
137 | + @Deactivate | ||
138 | + protected void deactivate() { | ||
139 | + eventDispatcher.removeSink(UiModelEvent.class); | ||
66 | 140 | ||
67 | - private final Set<UiTopoSession> sessions = new HashSet<>(); | 141 | + clusterService.removeListener(clusterListener); |
142 | + mastershipService.removeListener(mastershipListener); | ||
143 | + regionService.removeListener(regionListener); | ||
144 | + deviceService.removeListener(deviceListener); | ||
145 | + linkService.removeListener(linkListener); | ||
146 | + hostService.removeListener(hostListener); | ||
147 | + intentService.removeListener(intentListener); | ||
148 | + flowService.removeListener(flowRuleListener); | ||
68 | 149 | ||
69 | - private UiSharedTopologyModel() { | 150 | + cache.clear(); |
70 | - modelEventListener = new ModelEventListener().init(); | 151 | + cache = null; |
71 | 152 | ||
72 | - // TODO: build and maintain the state of the model | 153 | + log.info("Stopped"); |
73 | - // (1) query model for current state | ||
74 | - // (2) update state as model events arrive | ||
75 | } | 154 | } |
76 | 155 | ||
156 | + | ||
77 | /** | 157 | /** |
78 | * Registers a UI topology session with the topology model. | 158 | * Registers a UI topology session with the topology model. |
79 | * | 159 | * |
... | @@ -81,7 +161,7 @@ public final class UiSharedTopologyModel { | ... | @@ -81,7 +161,7 @@ public final class UiSharedTopologyModel { |
81 | */ | 161 | */ |
82 | public void register(UiTopoSession session) { | 162 | public void register(UiTopoSession session) { |
83 | log.info("Registering topology session {}", session); | 163 | log.info("Registering topology session {}", session); |
84 | - sessions.add(session); | 164 | + addListener(session); |
85 | } | 165 | } |
86 | 166 | ||
87 | /** | 167 | /** |
... | @@ -91,138 +171,82 @@ public final class UiSharedTopologyModel { | ... | @@ -91,138 +171,82 @@ public final class UiSharedTopologyModel { |
91 | */ | 171 | */ |
92 | public void unregister(UiTopoSession session) { | 172 | public void unregister(UiTopoSession session) { |
93 | log.info("Unregistering topology session {}", session); | 173 | log.info("Unregistering topology session {}", session); |
94 | - sessions.remove(session); | 174 | + removeListener(session); |
95 | } | 175 | } |
96 | 176 | ||
97 | 177 | ||
98 | - // TODO: notify registered sessions when changes happen to the model | 178 | + private class InternalClusterListener implements ClusterEventListener { |
99 | - | 179 | + @Override |
100 | - | 180 | + public void event(ClusterEvent event) { |
101 | - // ---------- | 181 | + // TODO: handle cluster event |
102 | - | ||
103 | - // inner class to encapsulate the model listeners | ||
104 | - private final class ModelEventListener { | ||
105 | - | ||
106 | - // TODO: Review - is this good enough? couldn't otherwise see how to inject | ||
107 | - private final ServiceDirectory directory = new DefaultServiceDirectory(); | ||
108 | - | ||
109 | - private ClusterService clusterService; | ||
110 | - private MastershipService mastershipService; | ||
111 | - private RegionService regionService; | ||
112 | - private DeviceService deviceService; | ||
113 | - private LinkService linkService; | ||
114 | - private HostService hostService; | ||
115 | - private IntentService intentService; | ||
116 | - private FlowRuleService flowService; | ||
117 | - | ||
118 | - private StatisticService flowStatsService; | ||
119 | - private PortStatisticsService portStatsService; | ||
120 | - private TopologyService topologyService; | ||
121 | - private TunnelService tunnelService; | ||
122 | - | ||
123 | - private ModelEventListener init() { | ||
124 | - clusterService = directory.get(ClusterService.class); | ||
125 | - mastershipService = directory.get(MastershipService.class); | ||
126 | - regionService = directory.get(RegionService.class); | ||
127 | - deviceService = directory.get(DeviceService.class); | ||
128 | - linkService = directory.get(LinkService.class); | ||
129 | - hostService = directory.get(HostService.class); | ||
130 | - intentService = directory.get(IntentService.class); | ||
131 | - flowService = directory.get(FlowRuleService.class); | ||
132 | - | ||
133 | - // passive services (?) to whom we are not listening... | ||
134 | - flowStatsService = directory.get(StatisticService.class); | ||
135 | - portStatsService = directory.get(PortStatisticsService.class); | ||
136 | - topologyService = directory.get(TopologyService.class); | ||
137 | - tunnelService = directory.get(TunnelService.class); | ||
138 | - | ||
139 | - return this; | ||
140 | } | 182 | } |
183 | + } | ||
141 | 184 | ||
142 | - private class InternalClusterListener implements ClusterEventListener { | 185 | + private class InternalMastershipListener implements MastershipListener { |
143 | - @Override | 186 | + @Override |
144 | - public void event(ClusterEvent event) { | 187 | + public void event(MastershipEvent event) { |
145 | - // TODO: handle cluster event | 188 | + // TODO: handle mastership event |
146 | - // (1) emit cluster member event | ||
147 | - } | ||
148 | } | 189 | } |
190 | + } | ||
149 | 191 | ||
150 | - private class InternalMastershipListener implements MastershipListener { | 192 | + private class InternalRegionListener implements RegionListener { |
151 | - @Override | 193 | + @Override |
152 | - public void event(MastershipEvent event) { | 194 | + public void event(RegionEvent event) { |
153 | - // TODO: handle mastership event | 195 | + // TODO: handle region event |
154 | - // (1) emit cluster member update for all members | ||
155 | - // (2) emit update device event for he whose mastership changed | ||
156 | - } | ||
157 | } | 196 | } |
197 | + } | ||
158 | 198 | ||
159 | - private class InternalRegionListener implements RegionListener { | 199 | + private class InternalDeviceListener implements DeviceListener { |
160 | - @Override | 200 | + @Override |
161 | - public void event(RegionEvent event) { | 201 | + public void event(DeviceEvent event) { |
162 | - // TODO: handle region event | ||
163 | - // (1) emit region event | ||
164 | - } | ||
165 | - } | ||
166 | 202 | ||
167 | - private class InternalDeviceListener implements DeviceListener { | 203 | + Device device = event.subject(); |
168 | - @Override | ||
169 | - public void event(DeviceEvent event) { | ||
170 | - // TODO: handle device event | ||
171 | - // (1) emit device event | ||
172 | - } | ||
173 | - } | ||
174 | 204 | ||
175 | - private class InternalLinkListener implements LinkListener { | 205 | + switch (event.type()) { |
176 | - @Override | ||
177 | - public void event(LinkEvent event) { | ||
178 | - // TODO: handle link event | ||
179 | - // (1) consolidate infrastructure links -> UiLink (?) | ||
180 | - // (2) emit link event | ||
181 | - } | ||
182 | - } | ||
183 | 206 | ||
184 | - private class InternalHostListener implements HostListener { | 207 | + case DEVICE_ADDED: |
185 | - @Override | 208 | + case DEVICE_UPDATED: |
186 | - public void event(HostEvent event) { | 209 | + case DEVICE_AVAILABILITY_CHANGED: |
187 | - // TODO: handle host event | 210 | + case DEVICE_SUSPENDED: |
188 | - // (1) emit host event | 211 | + cache.addOrUpdateDevice(device); |
189 | - } | 212 | + break; |
190 | - } | 213 | + |
214 | + case DEVICE_REMOVED: | ||
215 | + cache.removeDevice(device); | ||
216 | + break; | ||
191 | 217 | ||
192 | - private class InternalIntentListener implements IntentListener { | 218 | + default: |
193 | - @Override | 219 | + break; |
194 | - public void event(IntentEvent event) { | ||
195 | - // TODO: handle intent event | ||
196 | - // (1) update cache of intent counts? | ||
197 | } | 220 | } |
198 | } | 221 | } |
222 | + } | ||
199 | 223 | ||
200 | - private class InternalFlowRuleListener implements FlowRuleListener { | 224 | + private class InternalLinkListener implements LinkListener { |
201 | - @Override | 225 | + @Override |
202 | - public void event(FlowRuleEvent event) { | 226 | + public void event(LinkEvent event) { |
203 | - // TODO: handle flowrule event | 227 | + // TODO: handle link event |
204 | - // (1) update cache of flow counts? | ||
205 | - } | ||
206 | } | 228 | } |
207 | } | 229 | } |
208 | 230 | ||
209 | - // ---------- | 231 | + private class InternalHostListener implements HostListener { |
232 | + @Override | ||
233 | + public void event(HostEvent event) { | ||
234 | + // TODO: handle host event | ||
235 | + } | ||
236 | + } | ||
210 | 237 | ||
211 | - /** | 238 | + private class InternalIntentListener implements IntentListener { |
212 | - * Bill Pugh Singleton pattern. INSTANCE won't be instantiated until the | 239 | + @Override |
213 | - * LazyHolder class is loaded via a call to the instance() method below. | 240 | + public void event(IntentEvent event) { |
214 | - */ | 241 | + // TODO: handle intent event |
215 | - private static class LazyHolder { | 242 | + } |
216 | - private static final UiSharedTopologyModel INSTANCE = | ||
217 | - new UiSharedTopologyModel(); | ||
218 | } | 243 | } |
219 | 244 | ||
220 | - /** | 245 | + private class InternalFlowRuleListener implements FlowRuleListener { |
221 | - * Returns a reference to the Singleton UI network topology model. | 246 | + @Override |
222 | - * | 247 | + public void event(FlowRuleEvent event) { |
223 | - * @return the singleton topology model | 248 | + // TODO: handle flowrule event |
224 | - */ | 249 | + } |
225 | - public static UiSharedTopologyModel instance() { | ||
226 | - return LazyHolder.INSTANCE; | ||
227 | } | 250 | } |
251 | + | ||
228 | } | 252 | } | ... | ... |
-
Please register or login to post a comment