Converted UiSharedTopologyModel to be a @Service.
Change-Id: Idc8df1b9c0a52db01ac545567dacc0e1c770f84a
Showing
13 changed files
with
184 additions
and
13 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 | +} |
This diff is collapsed. Click to expand it.
-
Please register or login to post a comment