Simon Hunt | ed804d5 | 2016-03-30 09:51:40 -0700 | [diff] [blame] | 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 | |
Simon Hunt | f679c4e | 2016-04-01 17:02:24 -0700 | [diff] [blame^] | 19 | import org.onosproject.ui.impl.topo.UiTopoSession; |
Simon Hunt | ed804d5 | 2016-03-30 09:51:40 -0700 | [diff] [blame] | 20 | import org.slf4j.Logger; |
| 21 | import org.slf4j.LoggerFactory; |
| 22 | |
| 23 | /** |
| 24 | * A lazily-initialized Singleton that creates and maintains the UI-model |
| 25 | * of the network topology. |
| 26 | */ |
| 27 | public final class UiSharedTopologyModel { |
| 28 | |
| 29 | private static final Logger log = |
| 30 | LoggerFactory.getLogger(UiSharedTopologyModel.class); |
| 31 | |
Simon Hunt | ed804d5 | 2016-03-30 09:51:40 -0700 | [diff] [blame] | 32 | |
| 33 | private UiSharedTopologyModel() { |
| 34 | // TODO: set up core model listeners and build the state of the model |
| 35 | } |
| 36 | |
Simon Hunt | f679c4e | 2016-04-01 17:02:24 -0700 | [diff] [blame^] | 37 | // TODO: Note to Thomas (or others).. |
| 38 | // Don't we have a common pattern for adding/removing listeners and |
| 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 |
Simon Hunt | ed804d5 | 2016-03-30 09:51:40 -0700 | [diff] [blame] | 50 | } |
| 51 | |
Simon Hunt | f679c4e | 2016-04-01 17:02:24 -0700 | [diff] [blame^] | 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 |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Bill Pugh Singleton pattern. INSTANCE won't be instantiated until the |
| 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(); |
Simon Hunt | ed804d5 | 2016-03-30 09:51:40 -0700 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Returns a reference to the Singleton UI network topology model. |
| 73 | * |
| 74 | * @return the singleton topology model |
| 75 | */ |
Simon Hunt | f679c4e | 2016-04-01 17:02:24 -0700 | [diff] [blame^] | 76 | public static UiSharedTopologyModel instance() { |
| 77 | return LazyHolder.INSTANCE; |
Simon Hunt | ed804d5 | 2016-03-30 09:51:40 -0700 | [diff] [blame] | 78 | } |
| 79 | } |