You've been checkstyled!
Change-Id: I0425764b2f3b07bc224a387ab7d544c6b360c691
Showing
5 changed files
with
204 additions
and
19 deletions
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 | +package org.onosproject.ui; | ||
17 | + | ||
18 | +import org.onosproject.ui.model.topo.UiTopoLayout; | ||
19 | + | ||
20 | +import java.util.List; | ||
21 | + | ||
22 | +/** | ||
23 | + * Service for managing {@link UiTopoLayout} instances. | ||
24 | + */ | ||
25 | +public interface UiTopoLayoutService { | ||
26 | + | ||
27 | + /** | ||
28 | + * Returns the list of available layouts. | ||
29 | + * | ||
30 | + * @return available layouts | ||
31 | + */ | ||
32 | + List<UiTopoLayout> getLayouts(); | ||
33 | + | ||
34 | + /** | ||
35 | + * Adds a layout to the system. | ||
36 | + * | ||
37 | + * @param layout the layout to add | ||
38 | + * @return an indication of success | ||
39 | + */ | ||
40 | + boolean addLayout(UiTopoLayout layout); | ||
41 | + | ||
42 | + /** | ||
43 | + * Removes a layout from the system. | ||
44 | + * | ||
45 | + * @param layout the layout to remove | ||
46 | + * @return an indication of success | ||
47 | + */ | ||
48 | + boolean removeLayout(UiTopoLayout layout); | ||
49 | + | ||
50 | +} |
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 | +import org.onosproject.net.region.Region; | ||
20 | + | ||
21 | +/** | ||
22 | + * Represents a specific "subset" of the UI model of the network topology | ||
23 | + * that a user might wish to view. Backed by a {@link Region}. | ||
24 | + */ | ||
25 | +public class UiTopoLayout { | ||
26 | + | ||
27 | + private Region backingRegion; | ||
28 | + | ||
29 | +} |
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; | ||
18 | + | ||
19 | +import org.apache.felix.scr.annotations.Activate; | ||
20 | +import org.apache.felix.scr.annotations.Component; | ||
21 | +import org.apache.felix.scr.annotations.Deactivate; | ||
22 | +import org.apache.felix.scr.annotations.Service; | ||
23 | +import org.onosproject.ui.UiTopoLayoutService; | ||
24 | +import org.onosproject.ui.model.topo.UiTopoLayout; | ||
25 | +import org.slf4j.Logger; | ||
26 | +import org.slf4j.LoggerFactory; | ||
27 | + | ||
28 | +import java.util.List; | ||
29 | + | ||
30 | +/** | ||
31 | + * Manages the user interface topology layouts. | ||
32 | + * Note that these layouts are persisted and distributed across the cluster. | ||
33 | + */ | ||
34 | +@Component(immediate = true) | ||
35 | +@Service | ||
36 | +public class UiTopoLayoutManager implements UiTopoLayoutService { | ||
37 | + | ||
38 | +// private static final ClassLoader CL = | ||
39 | +// UiTopoLayoutManager.class.getClassLoader(); | ||
40 | + | ||
41 | + private final Logger log = LoggerFactory.getLogger(getClass()); | ||
42 | + | ||
43 | + @Activate | ||
44 | + public void activate() { | ||
45 | + // TODO: implement starting stuff | ||
46 | + log.info("Started"); | ||
47 | + } | ||
48 | + | ||
49 | + @Deactivate | ||
50 | + public void deactivate() { | ||
51 | + // TODO: implement stopping stuff | ||
52 | + log.info("Stopped"); | ||
53 | + } | ||
54 | + | ||
55 | + | ||
56 | + @Override | ||
57 | + public List<UiTopoLayout> getLayouts() { | ||
58 | + // TODO: implement | ||
59 | + return null; | ||
60 | + } | ||
61 | + | ||
62 | + @Override | ||
63 | + public boolean addLayout(UiTopoLayout layout) { | ||
64 | + // TODO: implement | ||
65 | + return false; | ||
66 | + } | ||
67 | + | ||
68 | + @Override | ||
69 | + public boolean removeLayout(UiTopoLayout layout) { | ||
70 | + // TODO: implement | ||
71 | + return false; | ||
72 | + } | ||
73 | +} |
... | @@ -14,31 +14,43 @@ | ... | @@ -14,31 +14,43 @@ |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | 16 | ||
17 | -package org.onosproject.ui.impl.topo.model; | 17 | +package org.onosproject.ui.impl.topo; |
18 | 18 | ||
19 | +import org.onosproject.ui.UiTopoLayoutService; | ||
20 | +import org.onosproject.ui.impl.UiWebSocket; | ||
21 | +import org.onosproject.ui.impl.topo.model.UiSharedTopologyModel; | ||
22 | +import org.onosproject.ui.model.topo.UiTopoLayout; | ||
19 | import org.slf4j.Logger; | 23 | import org.slf4j.Logger; |
20 | import org.slf4j.LoggerFactory; | 24 | import org.slf4j.LoggerFactory; |
21 | 25 | ||
22 | /** | 26 | /** |
23 | - * Base class for modeling the Topology View layout. | 27 | + * Coordinates with the {@link UiTopoLayoutService} to access |
28 | + * {@link UiTopoLayout}s, and with the {@link UiSharedTopologyModel} which | ||
29 | + * maintains a local model of the network entities, | ||
30 | + * tailored specifically for displaying on the UI. | ||
24 | * <p> | 31 | * <p> |
25 | * Note that an instance of this class will be created for each | 32 | * Note that an instance of this class will be created for each |
26 | - * {@link org.onosproject.ui.impl.UiWebSocket} connection, and will contain | 33 | + * {@link UiWebSocket} connection, and will contain |
27 | * the state of how the topology is laid out for the logged-in user. | 34 | * the state of how the topology is laid out for the logged-in user. |
28 | */ | 35 | */ |
29 | -public class UiTopoLayout { | 36 | +public class UiTopoSession { |
30 | private final Logger log = LoggerFactory.getLogger(getClass()); | 37 | private final Logger log = LoggerFactory.getLogger(getClass()); |
31 | 38 | ||
32 | private final String username; | 39 | private final String username; |
40 | + private final UiWebSocket webSocket; | ||
33 | private final UiSharedTopologyModel sharedModel; | 41 | private final UiSharedTopologyModel sharedModel; |
34 | 42 | ||
35 | private boolean registered = false; | 43 | private boolean registered = false; |
36 | 44 | ||
45 | + private UiTopoLayoutService service; | ||
46 | + private UiTopoLayout layout; | ||
47 | + | ||
37 | /** | 48 | /** |
38 | * Creates a new topology layout. | 49 | * Creates a new topology layout. |
39 | */ | 50 | */ |
40 | - public UiTopoLayout(String username) { | 51 | + public UiTopoSession(String username, UiWebSocket webSocket) { |
41 | this.username = username; | 52 | this.username = username; |
53 | + this.webSocket = webSocket; | ||
42 | this.sharedModel = UiSharedTopologyModel.instance(); | 54 | this.sharedModel = UiSharedTopologyModel.instance(); |
43 | } | 55 | } |
44 | 56 | ||
... | @@ -60,6 +72,7 @@ public class UiTopoLayout { | ... | @@ -60,6 +72,7 @@ public class UiTopoLayout { |
60 | public void destroy() { | 72 | public void destroy() { |
61 | if (!registered) { | 73 | if (!registered) { |
62 | sharedModel.unregister(this); | 74 | sharedModel.unregister(this); |
75 | + registered = false; | ||
63 | } else { | 76 | } else { |
64 | log.warn("already unregistered"); | 77 | log.warn("already unregistered"); |
65 | } | 78 | } |
... | @@ -67,6 +80,6 @@ public class UiTopoLayout { | ... | @@ -67,6 +80,6 @@ public class UiTopoLayout { |
67 | 80 | ||
68 | @Override | 81 | @Override |
69 | public String toString() { | 82 | public String toString() { |
70 | - return String.format("{UiTopoLayout for user <%s>}", username); | 83 | + return String.format("{UiTopoSession for user <%s>}", username); |
71 | } | 84 | } |
72 | } | 85 | } | ... | ... |
... | @@ -16,6 +16,7 @@ | ... | @@ -16,6 +16,7 @@ |
16 | 16 | ||
17 | package org.onosproject.ui.impl.topo.model; | 17 | package org.onosproject.ui.impl.topo.model; |
18 | 18 | ||
19 | +import org.onosproject.ui.impl.topo.UiTopoSession; | ||
19 | import org.slf4j.Logger; | 20 | import org.slf4j.Logger; |
20 | import org.slf4j.LoggerFactory; | 21 | import org.slf4j.LoggerFactory; |
21 | 22 | ||
... | @@ -28,20 +29,43 @@ public final class UiSharedTopologyModel { | ... | @@ -28,20 +29,43 @@ public final class UiSharedTopologyModel { |
28 | private static final Logger log = | 29 | private static final Logger log = |
29 | LoggerFactory.getLogger(UiSharedTopologyModel.class); | 30 | LoggerFactory.getLogger(UiSharedTopologyModel.class); |
30 | 31 | ||
31 | - private static UiSharedTopologyModel singleton = null; | ||
32 | 32 | ||
33 | private UiSharedTopologyModel() { | 33 | private UiSharedTopologyModel() { |
34 | // TODO: set up core model listeners and build the state of the model | 34 | // TODO: set up core model listeners and build the state of the model |
35 | } | 35 | } |
36 | 36 | ||
37 | - public void register(UiTopoLayout layout) { | 37 | + // TODO: Note to Thomas (or others).. |
38 | - log.info("Registering topology layout {}", layout); | 38 | + // Don't we have a common pattern for adding/removing listeners and |
39 | - // TODO: register the view | 39 | + // invoking them when things happen? |
40 | + | ||
41 | + | ||
42 | + /** | ||
43 | + * Registers a UI topology session with the topology model. | ||
44 | + * | ||
45 | + * @param session the session to register | ||
46 | + */ | ||
47 | + public void register(UiTopoSession session) { | ||
48 | + log.info("Registering topology session {}", session); | ||
49 | + // TODO: register the session | ||
50 | + } | ||
51 | + | ||
52 | + /** | ||
53 | + * Unregisters a UI topology session from the topology model. | ||
54 | + * | ||
55 | + * @param session the session to unregister | ||
56 | + */ | ||
57 | + public void unregister(UiTopoSession session) { | ||
58 | + log.info("Unregistering topology session {}", session); | ||
59 | + // TODO: unregister the session | ||
40 | } | 60 | } |
41 | 61 | ||
42 | - public void unregister(UiTopoLayout layout) { | 62 | + /** |
43 | - log.info("Unregistering topology layout {}", layout); | 63 | + * Bill Pugh Singleton pattern. INSTANCE won't be instantiated until the |
44 | - // TODO: unregister the view | 64 | + * LazyHolder class is loaded via a call to the instance() method below. |
65 | + */ | ||
66 | + private static class LazyHolder { | ||
67 | + private static final UiSharedTopologyModel INSTANCE = | ||
68 | + new UiSharedTopologyModel(); | ||
45 | } | 69 | } |
46 | 70 | ||
47 | /** | 71 | /** |
... | @@ -49,11 +73,7 @@ public final class UiSharedTopologyModel { | ... | @@ -49,11 +73,7 @@ public final class UiSharedTopologyModel { |
49 | * | 73 | * |
50 | * @return the singleton topology model | 74 | * @return the singleton topology model |
51 | */ | 75 | */ |
52 | - public static synchronized UiSharedTopologyModel instance() { | 76 | + public static UiSharedTopologyModel instance() { |
53 | - if (singleton == null) { | 77 | + return LazyHolder.INSTANCE; |
54 | - log.info("Instantiating Singleton."); | ||
55 | - singleton = new UiSharedTopologyModel(); | ||
56 | - } | ||
57 | - return singleton; | ||
58 | } | 78 | } |
59 | } | 79 | } | ... | ... |
-
Please register or login to post a comment