blob: c3863ca51b70e14ac0b552d58fe4fc215c639f9f [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.newresource.ResourceAdminService;
28
29import java.util.concurrent.ExecutorService;
30import java.util.concurrent.Executors;
31
32import static org.onlab.util.Tools.groupedThreads;
33
34/**
35 * A class registering resources when they are detected.
36 */
Sho SHIMIZUf1a62792015-11-04 08:15:29 -080037@Component(immediate = true)
Sho SHIMIZU47e7b802015-08-18 08:54:30 -070038@Beta
39public final class ResourceRegistrar {
40
41 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
42 protected ResourceAdminService adminService;
43
44 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Sho SHIMIZU4bdd2592015-08-25 15:33:32 -070045 protected DriverService driverService;
46
47 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Sho SHIMIZUd97a9502015-08-18 10:02:30 -070048 protected DeviceService deviceService;
49
Sho SHIMIZUd97a9502015-08-18 10:02:30 -070050 private DeviceListener deviceListener;
Sho SHIMIZU47e7b802015-08-18 08:54:30 -070051 private final ExecutorService executor =
52 Executors.newSingleThreadExecutor(groupedThreads("onos/resource", "registrar"));
53
54 @Activate
55 public void activate() {
HIGUCHI Yuta11d16092015-12-04 23:35:43 -080056 deviceListener = new ResourceDeviceListener(adminService, deviceService, driverService, executor);
Sho SHIMIZU69dc5842015-11-20 16:31:12 -080057 deviceService.addListener(deviceListener);
Sho SHIMIZU47e7b802015-08-18 08:54:30 -070058 }
59
60 @Deactivate
61 public void deactivate() {
Sho SHIMIZU69dc5842015-11-20 16:31:12 -080062 deviceService.removeListener(deviceListener);
HIGUCHI Yuta11d16092015-12-04 23:35:43 -080063 executor.shutdownNow();
Sho SHIMIZU47e7b802015-08-18 08:54:30 -070064 }
65}