2 * Copyright (c) 2018 Pantheon Technologies, s.r.o. and others. All rights reserved.
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
8 package org.opendaylight.mdsal.binding.dom.adapter.osgi;
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.DataTreeService;
17 import org.opendaylight.mdsal.binding.api.MountPointService;
18 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
19 import org.opendaylight.mdsal.binding.api.NotificationService;
20 import org.opendaylight.mdsal.binding.api.RpcConsumerRegistry;
21 import org.opendaylight.mdsal.binding.api.RpcProviderService;
22 import org.opendaylight.mdsal.binding.dom.adapter.spi.AdapterFactory;
23 import org.opendaylight.mdsal.dom.api.DOMActionProviderService;
24 import org.opendaylight.mdsal.dom.api.DOMActionService;
25 import org.opendaylight.mdsal.dom.api.DOMDataBroker;
26 import org.opendaylight.mdsal.dom.api.DOMDataTreeService;
27 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
28 import org.opendaylight.mdsal.dom.api.DOMNotificationPublishService;
29 import org.opendaylight.mdsal.dom.api.DOMNotificationService;
30 import org.opendaylight.mdsal.dom.api.DOMRpcProviderService;
31 import org.opendaylight.mdsal.dom.api.DOMRpcService;
32 import org.opendaylight.mdsal.dom.api.DOMService;
33 import org.osgi.framework.BundleContext;
34 import org.osgi.service.component.ComponentFactory;
35 import org.osgi.service.component.annotations.Activate;
36 import org.osgi.service.component.annotations.Component;
37 import org.osgi.service.component.annotations.Deactivate;
38 import org.osgi.service.component.annotations.Reference;
39 import org.osgi.util.tracker.ServiceTracker;
40 import org.slf4j.Logger;
41 import org.slf4j.LoggerFactory;
44 * A component which watches the OSGi Service Registry for known {@link DOMService}s and publishes corresponding
45 * {@link BindingService}s backed by them.
47 * @author Robert Varga
49 @Component(immediate = true)
50 public final class DynamicBindingAdapter {
51 private static final Logger LOG = LoggerFactory.getLogger(DynamicBindingAdapter.class);
53 private List<AbstractAdaptingTracker<?, ?, ?>> trackers = ImmutableList.of();
56 AdapterFactory factory = null;
57 @Reference(target = "(component.factory=" + OSGiActionService.FACTORY_NAME + ")")
58 ComponentFactory actionServiceFactory = null;
59 @Reference(target = "(component.factory=" + OSGiActionProviderService.FACTORY_NAME + ")")
60 ComponentFactory actionProviderServiceFactory = null;
61 @Reference(target = "(component.factory=" + OSGiMountPointService.FACTORY_NAME + ")")
62 ComponentFactory mountPointServiceFactory = null;
63 @Reference(target = "(component.factory=" + OSGiNotificationService.FACTORY_NAME + ")")
64 ComponentFactory notificationServiceFactory = null;
65 @Reference(target = "(component.factory=" + OSGiNotificationPublishService.FACTORY_NAME + ")")
66 ComponentFactory notificationPublishServiceFactory = null;
67 @Reference(target = "(component.factory=" + OSGiRpcConsumerRegistry.FACTORY_NAME + ")")
68 ComponentFactory rpcConsumerRegistryFactory = null;
69 @Reference(target = "(component.factory=" + OSGiRpcProviderService.FACTORY_NAME + ")")
70 ComponentFactory rpcProviderServiceFactory = null;
73 void activate(final BundleContext ctx) {
74 trackers = ImmutableList.of(
75 new AdaptingTracker<>(ctx, DOMDataBroker.class, DataBroker.class, factory::createDataBroker),
76 new AdaptingTracker<>(ctx, DOMDataTreeService.class, DataTreeService.class, factory::createDataTreeService),
77 new AdaptingComponentTracker<>(ctx, DOMMountPointService.class, MountPointService.class,
78 factory::createMountPointService, mountPointServiceFactory),
79 new AdaptingComponentTracker<>(ctx, DOMNotificationService.class, NotificationService.class,
80 factory::createNotificationService, notificationServiceFactory),
81 new AdaptingComponentTracker<>(ctx, DOMNotificationPublishService.class, NotificationPublishService.class,
82 factory::createNotificationPublishService, notificationPublishServiceFactory),
83 new AdaptingComponentTracker<>(ctx, DOMRpcService.class, RpcConsumerRegistry.class,
84 factory::createRpcConsumerRegistry, rpcConsumerRegistryFactory),
85 new AdaptingComponentTracker<>(ctx, DOMRpcProviderService.class, RpcProviderService.class,
86 factory::createRpcProviderService, rpcProviderServiceFactory),
87 new AdaptingComponentTracker<>(ctx, DOMActionService.class, ActionService.class,
88 factory::createActionService, actionServiceFactory),
89 new AdaptingComponentTracker<>(ctx, DOMActionProviderService.class, ActionProviderService.class,
90 factory::createActionProviderService, actionProviderServiceFactory));
92 LOG.debug("Starting {} DOMService trackers", trackers.size());
93 trackers.forEach(ServiceTracker::open);
94 LOG.info("{} DOMService trackers started", trackers.size());
99 LOG.debug("Stopping {} DOMService trackers", trackers.size());
100 if (!trackers.isEmpty()) {
101 trackers.forEach(AbstractAdaptingTracker::close);
102 LOG.info("{} DOMService trackers stopped", trackers.size());
104 trackers = ImmutableList.of();