blob: 143f8c2b9dacf1db9f9e33c1e651ce9644e663d0 [file] [log] [blame]
Sho SHIMIZU47e7b802015-08-18 08:54:30 -07001/*
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 */
16package org.onosproject.net.newresource.impl;
17
18import com.google.common.annotations.Beta;
19import org.apache.felix.scr.annotations.Activate;
20import org.apache.felix.scr.annotations.Component;
21import org.apache.felix.scr.annotations.Deactivate;
22import org.apache.felix.scr.annotations.Reference;
23import org.apache.felix.scr.annotations.ReferenceCardinality;
Sho SHIMIZUd97a9502015-08-18 10:02:30 -070024import org.onosproject.net.device.DeviceListener;
25import org.onosproject.net.device.DeviceService;
Sho SHIMIZU4bdd2592015-08-25 15:33:32 -070026import org.onosproject.net.driver.DriverService;
Sho SHIMIZU47e7b802015-08-18 08:54:30 -070027import org.onosproject.net.link.LinkListener;
28import org.onosproject.net.link.LinkService;
29import org.onosproject.net.newresource.ResourceAdminService;
30
31import java.util.concurrent.ExecutorService;
32import java.util.concurrent.Executors;
33
34import static org.onlab.util.Tools.groupedThreads;
35
36/**
37 * A class registering resources when they are detected.
38 */
Sho SHIMIZUf1a62792015-11-04 08:15:29 -080039@Component(immediate = true)
Sho SHIMIZU47e7b802015-08-18 08:54:30 -070040@Beta
41public final class ResourceRegistrar {
42
43 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
44 protected ResourceAdminService adminService;
45
46 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Sho SHIMIZU4bdd2592015-08-25 15:33:32 -070047 protected DriverService driverService;
48
49 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Sho SHIMIZUd97a9502015-08-18 10:02:30 -070050 protected DeviceService deviceService;
51
52 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Sho SHIMIZU47e7b802015-08-18 08:54:30 -070053 protected LinkService linkService;
54
Sho SHIMIZUd97a9502015-08-18 10:02:30 -070055 private DeviceListener deviceListener;
Sho SHIMIZU47e7b802015-08-18 08:54:30 -070056 private LinkListener linkListener;
57 private final ExecutorService executor =
58 Executors.newSingleThreadExecutor(groupedThreads("onos/resource", "registrar"));
59
60 @Activate
61 public void activate() {
Sho SHIMIZU69dc5842015-11-20 16:31:12 -080062 deviceListener = new ResourceDeviceListener(adminService, executor);
63 deviceService.addListener(deviceListener);
64 linkListener = new ResourceLinkListener(adminService, driverService, executor);
65 linkService.addListener(linkListener);
Sho SHIMIZU47e7b802015-08-18 08:54:30 -070066 }
67
68 @Deactivate
69 public void deactivate() {
Sho SHIMIZU69dc5842015-11-20 16:31:12 -080070 deviceService.removeListener(deviceListener);
71 linkService.removeListener(linkListener);
Sho SHIMIZU47e7b802015-08-18 08:54:30 -070072 }
73}