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.newresource.ResourceAdminService; |
| 28 | |
| 29 | import java.util.concurrent.ExecutorService; |
| 30 | import java.util.concurrent.Executors; |
| 31 | |
| 32 | import static org.onlab.util.Tools.groupedThreads; |
| 33 | |
| 34 | /** |
| 35 | * A class registering resources when they are detected. |
| 36 | */ |
Sho SHIMIZU | f1a6279 | 2015-11-04 08:15:29 -0800 | [diff] [blame] | 37 | @Component(immediate = true) |
Sho SHIMIZU | 47e7b80 | 2015-08-18 08:54:30 -0700 | [diff] [blame] | 38 | @Beta |
| 39 | public final class ResourceRegistrar { |
| 40 | |
| 41 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 42 | protected ResourceAdminService adminService; |
| 43 | |
| 44 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Sho SHIMIZU | 4bdd259 | 2015-08-25 15:33:32 -0700 | [diff] [blame] | 45 | protected DriverService driverService; |
| 46 | |
| 47 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Sho SHIMIZU | d97a950 | 2015-08-18 10:02:30 -0700 | [diff] [blame] | 48 | protected DeviceService deviceService; |
| 49 | |
Sho SHIMIZU | d97a950 | 2015-08-18 10:02:30 -0700 | [diff] [blame] | 50 | private DeviceListener deviceListener; |
Sho SHIMIZU | 47e7b80 | 2015-08-18 08:54:30 -0700 | [diff] [blame] | 51 | private final ExecutorService executor = |
| 52 | Executors.newSingleThreadExecutor(groupedThreads("onos/resource", "registrar")); |
| 53 | |
| 54 | @Activate |
| 55 | public void activate() { |
HIGUCHI Yuta | 11d1609 | 2015-12-04 23:35:43 -0800 | [diff] [blame] | 56 | deviceListener = new ResourceDeviceListener(adminService, deviceService, driverService, executor); |
Sho SHIMIZU | 69dc584 | 2015-11-20 16:31:12 -0800 | [diff] [blame] | 57 | deviceService.addListener(deviceListener); |
Sho SHIMIZU | 47e7b80 | 2015-08-18 08:54:30 -0700 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | @Deactivate |
| 61 | public void deactivate() { |
Sho SHIMIZU | 69dc584 | 2015-11-20 16:31:12 -0800 | [diff] [blame] | 62 | deviceService.removeListener(deviceListener); |
HIGUCHI Yuta | 11d1609 | 2015-12-04 23:35:43 -0800 | [diff] [blame] | 63 | executor.shutdownNow(); |
Sho SHIMIZU | 47e7b80 | 2015-08-18 08:54:30 -0700 | [diff] [blame] | 64 | } |
| 65 | } |