Correct ActionProviderService method definition
[mdsal.git] / binding / mdsal-binding-dom-adapter / src / main / java / org / opendaylight / mdsal / binding / dom / adapter / osgi / DynamicBindingAdapter.java
1 /*
2  * Copyright (c) 2018 Pantheon Technologies, s.r.o. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.mdsal.binding.dom.adapter.osgi;
9
10 import com.google.common.collect.ImmutableList;
11 import java.util.List;
12 import org.opendaylight.mdsal.binding.api.ActionProviderService;
13 import org.opendaylight.mdsal.binding.api.ActionService;
14 import org.opendaylight.mdsal.binding.api.BindingService;
15 import org.opendaylight.mdsal.binding.api.DataBroker;
16 import org.opendaylight.mdsal.binding.api.MountPointService;
17 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
18 import org.opendaylight.mdsal.binding.api.NotificationService;
19 import org.opendaylight.mdsal.binding.api.RpcConsumerRegistry;
20 import org.opendaylight.mdsal.binding.api.RpcProviderService;
21 import org.opendaylight.mdsal.binding.dom.adapter.spi.AdapterFactory;
22 import org.opendaylight.mdsal.dom.api.DOMActionProviderService;
23 import org.opendaylight.mdsal.dom.api.DOMActionService;
24 import org.opendaylight.mdsal.dom.api.DOMDataBroker;
25 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
26 import org.opendaylight.mdsal.dom.api.DOMNotificationPublishService;
27 import org.opendaylight.mdsal.dom.api.DOMNotificationService;
28 import org.opendaylight.mdsal.dom.api.DOMRpcProviderService;
29 import org.opendaylight.mdsal.dom.api.DOMRpcService;
30 import org.opendaylight.mdsal.dom.api.DOMService;
31 import org.osgi.framework.BundleContext;
32 import org.osgi.service.component.ComponentFactory;
33 import org.osgi.service.component.annotations.Activate;
34 import org.osgi.service.component.annotations.Component;
35 import org.osgi.service.component.annotations.Deactivate;
36 import org.osgi.service.component.annotations.Reference;
37 import org.osgi.util.tracker.ServiceTracker;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
40
41 /**
42  * A component which watches the OSGi Service Registry for known {@link DOMService}s and publishes corresponding
43  * {@link BindingService}s backed by them.
44  *
45  * @author Robert Varga
46  */
47 @Component(immediate = true)
48 public final class DynamicBindingAdapter {
49     private static final Logger LOG = LoggerFactory.getLogger(DynamicBindingAdapter.class);
50
51     private List<AdaptingTracker<?, ?>> trackers = ImmutableList.of();
52
53     @Reference
54     AdapterFactory factory = null;
55     @Reference(target = "(component.factory=" + OSGiActionService.FACTORY_NAME + ")")
56     ComponentFactory<OSGiActionService> actionServiceFactory = null;
57     @Reference(target = "(component.factory=" + OSGiActionProviderService.FACTORY_NAME + ")")
58     ComponentFactory<OSGiActionProviderService> actionProviderServiceFactory = null;
59     @Reference(target = "(component.factory=" + OSGiDataBroker.FACTORY_NAME + ")")
60     ComponentFactory<OSGiDataBroker> dataBrokerFactory = null;
61     @Reference(target = "(component.factory=" + OSGiMountPointService.FACTORY_NAME + ")")
62     ComponentFactory<OSGiMountPointService> mountPointServiceFactory = null;
63     @Reference(target = "(component.factory=" + OSGiNotificationService.FACTORY_NAME + ")")
64     ComponentFactory<OSGiNotificationService> notificationServiceFactory = null;
65     @Reference(target = "(component.factory=" + OSGiNotificationPublishService.FACTORY_NAME + ")")
66     ComponentFactory<OSGiNotificationPublishService> notificationPublishServiceFactory = null;
67     @Reference(target = "(component.factory=" + OSGiRpcConsumerRegistry.FACTORY_NAME + ")")
68     ComponentFactory<OSGiRpcConsumerRegistry> rpcConsumerRegistryFactory = null;
69     @Reference(target = "(component.factory=" + OSGiRpcProviderService.FACTORY_NAME + ")")
70     ComponentFactory<OSGiRpcProviderService> rpcProviderServiceFactory = null;
71
72     @Activate
73     void activate(final BundleContext ctx) {
74         trackers = ImmutableList.of(
75             new AdaptingTracker<>(ctx, DOMDataBroker.class, DataBroker.class, factory::createDataBroker,
76                     dataBrokerFactory),
77             new AdaptingTracker<>(ctx, DOMMountPointService.class, MountPointService.class,
78                     factory::createMountPointService, mountPointServiceFactory),
79             new AdaptingTracker<>(ctx, DOMNotificationService.class, NotificationService.class,
80                     factory::createNotificationService, notificationServiceFactory),
81             new AdaptingTracker<>(ctx, DOMNotificationPublishService.class, NotificationPublishService.class,
82                     factory::createNotificationPublishService, notificationPublishServiceFactory),
83             new AdaptingTracker<>(ctx, DOMRpcService.class, RpcConsumerRegistry.class,
84                     factory::createRpcConsumerRegistry, rpcConsumerRegistryFactory),
85             new AdaptingTracker<>(ctx, DOMRpcProviderService.class, RpcProviderService.class,
86                     factory::createRpcProviderService, rpcProviderServiceFactory),
87             new AdaptingTracker<>(ctx, DOMActionService.class, ActionService.class, factory::createActionService,
88                     actionServiceFactory),
89             new AdaptingTracker<>(ctx, DOMActionProviderService.class, ActionProviderService.class,
90                     factory::createActionProviderService, actionProviderServiceFactory));
91
92         LOG.debug("Starting {} DOMService trackers", trackers.size());
93         trackers.forEach(ServiceTracker::open);
94         LOG.info("{} DOMService trackers started", trackers.size());
95     }
96
97     @Deactivate
98     void deactivate() {
99         LOG.debug("Stopping {} DOMService trackers", trackers.size());
100         if (!trackers.isEmpty()) {
101             trackers.forEach(AdaptingTracker::close);
102             LOG.info("{} DOMService trackers stopped", trackers.size());
103         }
104         trackers = ImmutableList.of();
105     }
106 }