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; |
| 24 | import org.onosproject.net.link.LinkListener; |
| 25 | import org.onosproject.net.link.LinkService; |
| 26 | import org.onosproject.net.newresource.ResourceAdminService; |
| 27 | |
| 28 | import java.util.concurrent.ExecutorService; |
| 29 | import java.util.concurrent.Executors; |
| 30 | |
| 31 | import static org.onlab.util.Tools.groupedThreads; |
| 32 | |
| 33 | /** |
| 34 | * A class registering resources when they are detected. |
| 35 | */ |
| 36 | @Component(immediate = true, enabled = false) |
| 37 | @Beta |
| 38 | public final class ResourceRegistrar { |
| 39 | |
| 40 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 41 | protected ResourceAdminService adminService; |
| 42 | |
| 43 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 44 | protected LinkService linkService; |
| 45 | |
| 46 | private LinkListener linkListener; |
| 47 | private final ExecutorService executor = |
| 48 | Executors.newSingleThreadExecutor(groupedThreads("onos/resource", "registrar")); |
| 49 | |
| 50 | @Activate |
| 51 | public void activate() { |
| 52 | linkListener = new ResourceLinkListener(adminService, executor); |
| 53 | linkService.addListener(linkListener); |
| 54 | } |
| 55 | |
| 56 | @Deactivate |
| 57 | public void deactivate() { |
| 58 | linkService.removeListener(linkListener); |
| 59 | } |
| 60 | } |