2 * Copyright 2015 Open Networking Laboratory
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.onosproject.net.newresource.impl;
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.device.DeviceListener;
25 import org.onosproject.net.device.DeviceService;
26 import org.onosproject.net.driver.DriverService;
27 import org.onosproject.net.link.LinkListener;
28 import org.onosproject.net.link.LinkService;
29 import org.onosproject.net.newresource.ResourceAdminService;
31 import java.util.concurrent.ExecutorService;
32 import java.util.concurrent.Executors;
34 import static org.onlab.util.Tools.groupedThreads;
37 * A class registering resources when they are detected.
39 @Component(immediate = true)
41 public final class ResourceRegistrar {
43 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
44 protected ResourceAdminService adminService;
46 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
47 protected DriverService driverService;
49 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
50 protected DeviceService deviceService;
52 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
53 protected LinkService linkService;
55 private DeviceListener deviceListener;
56 private LinkListener linkListener;
57 private final ExecutorService executor =
58 Executors.newSingleThreadExecutor(groupedThreads("onos/resource", "registrar"));
61 public void activate() {
62 deviceListener = new ResourceDeviceListener(adminService, executor);
63 deviceService.addListener(deviceListener);
64 linkListener = new ResourceLinkListener(adminService, driverService, executor);
65 linkService.addListener(linkListener);
69 public void deactivate() {
70 deviceService.removeListener(deviceListener);
71 linkService.removeListener(linkListener);