Sho SHIMIZU | 47e7b80 | 2015-08-18 08:54:30 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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.net.newresource.impl; |
| 17 | |
| 18 | import com.google.common.annotations.Beta; |
| 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.Reference; |
| 23 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
Sho SHIMIZU | d97a950 | 2015-08-18 10:02:30 -0700 | [diff] [blame] | 24 | import org.onosproject.net.device.DeviceListener; |
| 25 | import org.onosproject.net.device.DeviceService; |
Sho SHIMIZU | 4bdd259 | 2015-08-25 15:33:32 -0700 | [diff] [blame] | 26 | import org.onosproject.net.driver.DriverService; |
Sho SHIMIZU | 47e7b80 | 2015-08-18 08:54:30 -0700 | [diff] [blame] | 27 | import org.onosproject.net.link.LinkListener; |
| 28 | import org.onosproject.net.link.LinkService; |
| 29 | import org.onosproject.net.newresource.ResourceAdminService; |
| 30 | |
| 31 | import java.util.concurrent.ExecutorService; |
| 32 | import java.util.concurrent.Executors; |
| 33 | |
| 34 | import static org.onlab.util.Tools.groupedThreads; |
| 35 | |
| 36 | /** |
| 37 | * A class registering resources when they are detected. |
| 38 | */ |
Sho SHIMIZU | f1a6279 | 2015-11-04 08:15:29 -0800 | [diff] [blame] | 39 | @Component(immediate = true) |
Sho SHIMIZU | 47e7b80 | 2015-08-18 08:54:30 -0700 | [diff] [blame] | 40 | @Beta |
| 41 | public final class ResourceRegistrar { |
| 42 | |
| 43 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 44 | protected ResourceAdminService adminService; |
| 45 | |
| 46 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Sho SHIMIZU | 4bdd259 | 2015-08-25 15:33:32 -0700 | [diff] [blame] | 47 | protected DriverService driverService; |
| 48 | |
| 49 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Sho SHIMIZU | d97a950 | 2015-08-18 10:02:30 -0700 | [diff] [blame] | 50 | protected DeviceService deviceService; |
| 51 | |
| 52 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Sho SHIMIZU | 47e7b80 | 2015-08-18 08:54:30 -0700 | [diff] [blame] | 53 | protected LinkService linkService; |
| 54 | |
Sho SHIMIZU | d97a950 | 2015-08-18 10:02:30 -0700 | [diff] [blame] | 55 | private DeviceListener deviceListener; |
Sho SHIMIZU | 47e7b80 | 2015-08-18 08:54:30 -0700 | [diff] [blame] | 56 | private LinkListener linkListener; |
| 57 | private final ExecutorService executor = |
| 58 | Executors.newSingleThreadExecutor(groupedThreads("onos/resource", "registrar")); |
| 59 | |
| 60 | @Activate |
| 61 | public void activate() { |
Brian O'Connor | 63ff35a | 2015-11-20 12:39:28 -0800 | [diff] [blame] | 62 | // FIXME there is a loop causing high resource utilization on device registration |
| 63 | // deviceListener = new ResourceDeviceListener(adminService, executor); |
| 64 | // deviceService.addListener(deviceListener); |
| 65 | // linkListener = new ResourceLinkListener(adminService, driverService, executor); |
| 66 | // linkService.addListener(linkListener); |
Sho SHIMIZU | 47e7b80 | 2015-08-18 08:54:30 -0700 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | @Deactivate |
| 70 | public void deactivate() { |
Brian O'Connor | 63ff35a | 2015-11-20 12:39:28 -0800 | [diff] [blame] | 71 | // FIXME there is a loop causing high resource utilization on device registration |
| 72 | // deviceService.removeListener(deviceListener); |
| 73 | // linkService.removeListener(linkListener); |
Sho SHIMIZU | 47e7b80 | 2015-08-18 08:54:30 -0700 | [diff] [blame] | 74 | } |
| 75 | } |