Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 3 | * |
Simon Hunt | ed804d5 | 2016-03-30 09:51:40 -0700 | [diff] [blame] | 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 |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 7 | * |
Simon Hunt | ed804d5 | 2016-03-30 09:51:40 -0700 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 9 | * |
Simon Hunt | ed804d5 | 2016-03-30 09:51:40 -0700 | [diff] [blame] | 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. |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
Simon Hunt | ed804d5 | 2016-03-30 09:51:40 -0700 | [diff] [blame] | 17 | package org.onosproject.ui.impl.topo.util; |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 18 | |
Simon Hunt | 1911fe4 | 2017-05-02 18:25:58 -0700 | [diff] [blame] | 19 | import org.onlab.osgi.ServiceDirectory; |
| 20 | import org.onosproject.cluster.ClusterService; |
Thomas Vachuska | 52f2cd1 | 2018-11-08 21:20:04 -0800 | [diff] [blame] | 21 | import org.onosproject.net.statistic.PortStatisticsService; |
Simon Hunt | 1911fe4 | 2017-05-02 18:25:58 -0700 | [diff] [blame] | 22 | import org.onosproject.mastership.MastershipAdminService; |
| 23 | import org.onosproject.mastership.MastershipService; |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 24 | import org.onosproject.net.device.DeviceService; |
Laszlo Papp | e1579fa | 2018-03-08 09:18:48 +0000 | [diff] [blame] | 25 | import org.onosproject.net.driver.DriverService; |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 26 | import org.onosproject.net.flow.FlowRuleService; |
| 27 | import org.onosproject.net.host.HostService; |
| 28 | import org.onosproject.net.intent.IntentService; |
| 29 | import org.onosproject.net.link.LinkService; |
| 30 | import org.onosproject.net.statistic.StatisticService; |
Simon Hunt | 1911fe4 | 2017-05-02 18:25:58 -0700 | [diff] [blame] | 31 | import org.onosproject.net.topology.TopologyService; |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 32 | |
| 33 | import static com.google.common.base.Preconditions.checkNotNull; |
| 34 | |
| 35 | /** |
Simon Hunt | 1911fe4 | 2017-05-02 18:25:58 -0700 | [diff] [blame] | 36 | * A bundle of services that the topology view(s) require to get the job done. |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 37 | */ |
| 38 | public class ServicesBundle { |
| 39 | |
Thomas Vachuska | 2b4de87 | 2021-03-30 16:31:34 -0700 | [diff] [blame] | 40 | private ServiceDirectory directory; |
| 41 | |
Simon Hunt | 1911fe4 | 2017-05-02 18:25:58 -0700 | [diff] [blame] | 42 | private ClusterService clusterService; |
| 43 | |
| 44 | private TopologyService topologyService; |
| 45 | private DeviceService deviceService; |
Laszlo Papp | e1579fa | 2018-03-08 09:18:48 +0000 | [diff] [blame] | 46 | private DriverService driverService; |
Simon Hunt | 1911fe4 | 2017-05-02 18:25:58 -0700 | [diff] [blame] | 47 | private HostService hostService; |
| 48 | private LinkService linkService; |
Simon Hunt | 1911fe4 | 2017-05-02 18:25:58 -0700 | [diff] [blame] | 49 | |
| 50 | private MastershipService mastershipService; |
| 51 | private MastershipAdminService mastershipAdminService; |
| 52 | private IntentService intentService; |
| 53 | private FlowRuleService flowService; |
| 54 | private StatisticService flowStatsService; |
| 55 | private PortStatisticsService portStatsService; |
| 56 | |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 57 | |
| 58 | /** |
Simon Hunt | 1911fe4 | 2017-05-02 18:25:58 -0700 | [diff] [blame] | 59 | * Creates the services bundle, from the given directly. |
Simon Hunt | 4fc8685 | 2015-08-20 17:57:52 -0700 | [diff] [blame] | 60 | * |
Simon Hunt | 1911fe4 | 2017-05-02 18:25:58 -0700 | [diff] [blame] | 61 | * @param directory service directory |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 62 | */ |
Simon Hunt | 1911fe4 | 2017-05-02 18:25:58 -0700 | [diff] [blame] | 63 | public ServicesBundle(ServiceDirectory directory) { |
| 64 | checkNotNull(directory, "Directory cannot be null"); |
Thomas Vachuska | 2b4de87 | 2021-03-30 16:31:34 -0700 | [diff] [blame] | 65 | this.directory = directory; |
Simon Hunt | 1911fe4 | 2017-05-02 18:25:58 -0700 | [diff] [blame] | 66 | |
| 67 | clusterService = directory.get(ClusterService.class); |
| 68 | |
| 69 | topologyService = directory.get(TopologyService.class); |
| 70 | deviceService = directory.get(DeviceService.class); |
Thomas Vachuska | 177ea1b | 2018-03-13 12:00:49 -0700 | [diff] [blame] | 71 | driverService = directory.get(DriverService.class); |
Simon Hunt | 1911fe4 | 2017-05-02 18:25:58 -0700 | [diff] [blame] | 72 | hostService = directory.get(HostService.class); |
| 73 | linkService = directory.get(LinkService.class); |
Simon Hunt | 1911fe4 | 2017-05-02 18:25:58 -0700 | [diff] [blame] | 74 | |
| 75 | mastershipService = directory.get(MastershipService.class); |
| 76 | mastershipAdminService = directory.get(MastershipAdminService.class); |
| 77 | intentService = directory.get(IntentService.class); |
| 78 | flowService = directory.get(FlowRuleService.class); |
| 79 | flowStatsService = directory.get(StatisticService.class); |
| 80 | portStatsService = directory.get(PortStatisticsService.class); |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 81 | } |
| 82 | |
Simon Hunt | 4fc8685 | 2015-08-20 17:57:52 -0700 | [diff] [blame] | 83 | /** |
Simon Hunt | 1911fe4 | 2017-05-02 18:25:58 -0700 | [diff] [blame] | 84 | * Returns a reference to the cluster service. |
Simon Hunt | 4fc8685 | 2015-08-20 17:57:52 -0700 | [diff] [blame] | 85 | * |
Simon Hunt | 1911fe4 | 2017-05-02 18:25:58 -0700 | [diff] [blame] | 86 | * @return cluster service reference |
Simon Hunt | 4fc8685 | 2015-08-20 17:57:52 -0700 | [diff] [blame] | 87 | */ |
Simon Hunt | 1911fe4 | 2017-05-02 18:25:58 -0700 | [diff] [blame] | 88 | public ClusterService cluster() { |
| 89 | return clusterService; |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Returns a reference to the topology service. |
| 94 | * |
| 95 | * @return topology service reference |
| 96 | */ |
| 97 | public TopologyService topology() { |
| 98 | return topologyService; |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 99 | } |
| 100 | |
Simon Hunt | 4fc8685 | 2015-08-20 17:57:52 -0700 | [diff] [blame] | 101 | /** |
| 102 | * Returns a reference to the device service. |
| 103 | * |
| 104 | * @return device service reference |
| 105 | */ |
Simon Hunt | 1911fe4 | 2017-05-02 18:25:58 -0700 | [diff] [blame] | 106 | public DeviceService device() { |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 107 | return deviceService; |
| 108 | } |
| 109 | |
Simon Hunt | 4fc8685 | 2015-08-20 17:57:52 -0700 | [diff] [blame] | 110 | /** |
Laszlo Papp | e1579fa | 2018-03-08 09:18:48 +0000 | [diff] [blame] | 111 | * Returns a reference to the driver service. |
| 112 | * |
| 113 | * @return driver service reference |
| 114 | */ |
| 115 | public DriverService driver() { |
| 116 | return driverService; |
| 117 | } |
| 118 | |
| 119 | /** |
Simon Hunt | 4fc8685 | 2015-08-20 17:57:52 -0700 | [diff] [blame] | 120 | * Returns a reference to the host service. |
| 121 | * |
| 122 | * @return host service reference |
| 123 | */ |
Simon Hunt | 1911fe4 | 2017-05-02 18:25:58 -0700 | [diff] [blame] | 124 | public HostService host() { |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 125 | return hostService; |
| 126 | } |
| 127 | |
Simon Hunt | 4fc8685 | 2015-08-20 17:57:52 -0700 | [diff] [blame] | 128 | /** |
| 129 | * Returns a reference to the link service. |
| 130 | * |
| 131 | * @return link service reference |
| 132 | */ |
Simon Hunt | 1911fe4 | 2017-05-02 18:25:58 -0700 | [diff] [blame] | 133 | public LinkService link() { |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 134 | return linkService; |
| 135 | } |
| 136 | |
Simon Hunt | 4fc8685 | 2015-08-20 17:57:52 -0700 | [diff] [blame] | 137 | /** |
Simon Hunt | 1911fe4 | 2017-05-02 18:25:58 -0700 | [diff] [blame] | 138 | * Returns a reference to the mastership service. |
| 139 | * |
| 140 | * @return mastership service reference |
| 141 | */ |
| 142 | public MastershipService mastership() { |
| 143 | return mastershipService; |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * Returns a reference to the mastership admin service. |
| 148 | * |
| 149 | * @return mastership admin service reference |
| 150 | */ |
| 151 | public MastershipAdminService mastershipAdmin() { |
| 152 | return mastershipAdminService; |
| 153 | } |
| 154 | |
| 155 | /** |
| 156 | * Returns a reference to the intent service. |
| 157 | * |
| 158 | * @return intent service reference |
| 159 | */ |
| 160 | public IntentService intent() { |
| 161 | return intentService; |
| 162 | } |
| 163 | |
| 164 | /** |
Simon Hunt | 4fc8685 | 2015-08-20 17:57:52 -0700 | [diff] [blame] | 165 | * Returns a reference to the flow rule service. |
| 166 | * |
| 167 | * @return flow service reference |
| 168 | */ |
Simon Hunt | 1911fe4 | 2017-05-02 18:25:58 -0700 | [diff] [blame] | 169 | public FlowRuleService flow() { |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 170 | return flowService; |
| 171 | } |
| 172 | |
Simon Hunt | 4fc8685 | 2015-08-20 17:57:52 -0700 | [diff] [blame] | 173 | /** |
| 174 | * Returns a reference to the flow statistics service. |
| 175 | * |
| 176 | * @return flow statistics service reference |
| 177 | */ |
Simon Hunt | 1911fe4 | 2017-05-02 18:25:58 -0700 | [diff] [blame] | 178 | public StatisticService flowStats() { |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 179 | return flowStatsService; |
| 180 | } |
| 181 | |
Simon Hunt | 4fc8685 | 2015-08-20 17:57:52 -0700 | [diff] [blame] | 182 | /** |
| 183 | * Returns a reference to the port statistics service. |
| 184 | * |
| 185 | * @return port statistics service reference |
| 186 | */ |
Simon Hunt | 1911fe4 | 2017-05-02 18:25:58 -0700 | [diff] [blame] | 187 | public PortStatisticsService portStats() { |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 188 | return portStatsService; |
| 189 | } |
Thomas Vachuska | 2b4de87 | 2021-03-30 16:31:34 -0700 | [diff] [blame] | 190 | |
| 191 | /** |
| 192 | * Returns the implementation of the specified service class. |
| 193 | * |
| 194 | * @param serviceClass service class |
| 195 | * @param <T> class of service |
| 196 | * @return implementation of the service class |
| 197 | */ |
| 198 | public <T> T get(Class<T> serviceClass) { |
| 199 | return directory.get(serviceClass); |
| 200 | } |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 201 | } |