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 | 47e7b80 | 2015-08-18 08:54:30 -0700 | [diff] [blame] | 26 | import org.onosproject.net.link.LinkListener; |
| 27 | import org.onosproject.net.link.LinkService; |
| 28 | import org.onosproject.net.newresource.ResourceAdminService; |
| 29 | |
| 30 | import java.util.concurrent.ExecutorService; |
| 31 | import java.util.concurrent.Executors; |
| 32 | |
| 33 | import static org.onlab.util.Tools.groupedThreads; |
| 34 | |
| 35 | /** |
| 36 | * A class registering resources when they are detected. |
| 37 | */ |
| 38 | @Component(immediate = true, enabled = false) |
| 39 | @Beta |
| 40 | public final class ResourceRegistrar { |
| 41 | |
| 42 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 43 | protected ResourceAdminService adminService; |
| 44 | |
| 45 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Sho SHIMIZU | d97a950 | 2015-08-18 10:02:30 -0700 | [diff] [blame^] | 46 | protected DeviceService deviceService; |
| 47 | |
| 48 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Sho SHIMIZU | 47e7b80 | 2015-08-18 08:54:30 -0700 | [diff] [blame] | 49 | protected LinkService linkService; |
| 50 | |
Sho SHIMIZU | d97a950 | 2015-08-18 10:02:30 -0700 | [diff] [blame^] | 51 | private DeviceListener deviceListener; |
Sho SHIMIZU | 47e7b80 | 2015-08-18 08:54:30 -0700 | [diff] [blame] | 52 | private LinkListener linkListener; |
| 53 | private final ExecutorService executor = |
| 54 | Executors.newSingleThreadExecutor(groupedThreads("onos/resource", "registrar")); |
| 55 | |
| 56 | @Activate |
| 57 | public void activate() { |
Sho SHIMIZU | d97a950 | 2015-08-18 10:02:30 -0700 | [diff] [blame^] | 58 | deviceListener = new ResourceDeviceListener(adminService, executor); |
| 59 | deviceService.addListener(deviceListener); |
Sho SHIMIZU | 47e7b80 | 2015-08-18 08:54:30 -0700 | [diff] [blame] | 60 | linkListener = new ResourceLinkListener(adminService, executor); |
| 61 | linkService.addListener(linkListener); |
| 62 | } |
| 63 | |
| 64 | @Deactivate |
| 65 | public void deactivate() { |
Sho SHIMIZU | d97a950 | 2015-08-18 10:02:30 -0700 | [diff] [blame^] | 66 | deviceService.removeListener(deviceListener); |
Sho SHIMIZU | 47e7b80 | 2015-08-18 08:54:30 -0700 | [diff] [blame] | 67 | linkService.removeListener(linkListener); |
| 68 | } |
| 69 | } |