blob: 62948926279a1496a00afa998b5f104da6087f86 [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 SHIMIZU47e7b802015-08-18 08:54:30 -070026import org.onosproject.net.link.LinkListener;
27import org.onosproject.net.link.LinkService;
28import org.onosproject.net.newresource.ResourceAdminService;
29
30import java.util.concurrent.ExecutorService;
31import java.util.concurrent.Executors;
32
33import 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
40public final class ResourceRegistrar {
41
42 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
43 protected ResourceAdminService adminService;
44
45 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Sho SHIMIZUd97a9502015-08-18 10:02:30 -070046 protected DeviceService deviceService;
47
48 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Sho SHIMIZU47e7b802015-08-18 08:54:30 -070049 protected LinkService linkService;
50
Sho SHIMIZUd97a9502015-08-18 10:02:30 -070051 private DeviceListener deviceListener;
Sho SHIMIZU47e7b802015-08-18 08:54:30 -070052 private LinkListener linkListener;
53 private final ExecutorService executor =
54 Executors.newSingleThreadExecutor(groupedThreads("onos/resource", "registrar"));
55
56 @Activate
57 public void activate() {
Sho SHIMIZUd97a9502015-08-18 10:02:30 -070058 deviceListener = new ResourceDeviceListener(adminService, executor);
59 deviceService.addListener(deviceListener);
Sho SHIMIZU47e7b802015-08-18 08:54:30 -070060 linkListener = new ResourceLinkListener(adminService, executor);
61 linkService.addListener(linkListener);
62 }
63
64 @Deactivate
65 public void deactivate() {
Sho SHIMIZUd97a9502015-08-18 10:02:30 -070066 deviceService.removeListener(deviceListener);
Sho SHIMIZU47e7b802015-08-18 08:54:30 -070067 linkService.removeListener(linkListener);
68 }
69}