From 085336d1304acd817f020f38632addc4a2c5ced3 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Thu, 30 Jul 2020 23:46:00 +0200 Subject: [PATCH] Add binding adapter components for notification services Rather than operating on service registry directly, create binding adapters as dedicated components. This allows proper provides/requires validation for downstream component users. JIRA: MDSAL-585 Change-Id: I8a3ec440d9e74cfaecdc310812da32b4b8b28241 Signed-off-by: Robert Varga (cherry picked from commit 0e769de7475abae5dd06fc2c93d69d0906c66bee) --- .../adapter/osgi/DynamicBindingAdapter.java | 12 ++-- .../osgi/OSGiNotificationPublishService.java | 56 +++++++++++++++++++ .../adapter/osgi/OSGiNotificationService.java | 44 +++++++++++++++ 3 files changed, 108 insertions(+), 4 deletions(-) create mode 100644 binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/osgi/OSGiNotificationPublishService.java create mode 100644 binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/osgi/OSGiNotificationService.java diff --git a/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/osgi/DynamicBindingAdapter.java b/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/osgi/DynamicBindingAdapter.java index 193e7b70c5..dace2cd5c5 100644 --- a/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/osgi/DynamicBindingAdapter.java +++ b/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/osgi/DynamicBindingAdapter.java @@ -60,6 +60,10 @@ public final class DynamicBindingAdapter { ComponentFactory actionProviderServiceFactory = null; @Reference(target = "(component.factory=" + OSGiMountPointService.FACTORY_NAME + ")") ComponentFactory mountPointServiceFactory = null; + @Reference(target = "(component.factory=" + OSGiNotificationService.FACTORY_NAME + ")") + ComponentFactory notificationServiceFactory = null; + @Reference(target = "(component.factory=" + OSGiNotificationPublishService.FACTORY_NAME + ")") + ComponentFactory notificationPublishServiceFactory = null; @Reference(target = "(component.factory=" + OSGiRpcConsumerRegistry.FACTORY_NAME + ")") ComponentFactory rpcConsumerRegistryFactory = null; @Reference(target = "(component.factory=" + OSGiRpcProviderService.FACTORY_NAME + ")") @@ -72,10 +76,10 @@ public final class DynamicBindingAdapter { new AdaptingTracker<>(ctx, DOMDataTreeService.class, DataTreeService.class, factory::createDataTreeService), new AdaptingComponentTracker<>(ctx, DOMMountPointService.class, MountPointService.class, factory::createMountPointService, mountPointServiceFactory), - new AdaptingTracker<>(ctx, DOMNotificationService.class, NotificationService.class, - factory::createNotificationService), - new AdaptingTracker<>(ctx, DOMNotificationPublishService.class, NotificationPublishService.class, - factory::createNotificationPublishService), + new AdaptingComponentTracker<>(ctx, DOMNotificationService.class, NotificationService.class, + factory::createNotificationService, notificationServiceFactory), + new AdaptingComponentTracker<>(ctx, DOMNotificationPublishService.class, NotificationPublishService.class, + factory::createNotificationPublishService, notificationPublishServiceFactory), new AdaptingComponentTracker<>(ctx, DOMRpcService.class, RpcConsumerRegistry.class, factory::createRpcConsumerRegistry, rpcConsumerRegistryFactory), new AdaptingComponentTracker<>(ctx, DOMRpcProviderService.class, RpcProviderService.class, diff --git a/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/osgi/OSGiNotificationPublishService.java b/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/osgi/OSGiNotificationPublishService.java new file mode 100644 index 0000000000..23fcf25213 --- /dev/null +++ b/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/osgi/OSGiNotificationPublishService.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.mdsal.binding.dom.adapter.osgi; + +import com.google.common.annotations.Beta; +import com.google.common.util.concurrent.ListenableFuture; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import org.opendaylight.mdsal.binding.api.NotificationPublishService; +import org.opendaylight.yangtools.yang.binding.Notification; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Deactivate; + +@Beta +@Component(factory = OSGiNotificationPublishService.FACTORY_NAME) +public final class OSGiNotificationPublishService extends AbstractAdaptedService + implements NotificationPublishService { + // OSGi DS Component Factory name + static final String FACTORY_NAME = "org.opendaylight.mdsal.binding.dom.adapter.osgi.OSGiNotificationPublishService"; + + public OSGiNotificationPublishService() { + super(NotificationPublishService.class); + } + + @Override + public void putNotification(final Notification notification) throws InterruptedException { + delegate().putNotification(notification); + } + + @Override + public ListenableFuture offerNotification(final Notification notification) { + return delegate().offerNotification(notification); + } + + @Override + public ListenableFuture offerNotification(final Notification notification, final int timeout, + final TimeUnit unit) throws InterruptedException { + return delegate().offerNotification(notification, timeout, unit); + } + + @Activate + void activate(final Map properties) { + start(properties); + } + + @Deactivate + void deactivate() { + stop(); + } +} diff --git a/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/osgi/OSGiNotificationService.java b/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/osgi/OSGiNotificationService.java new file mode 100644 index 0000000000..1a429f73b9 --- /dev/null +++ b/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/osgi/OSGiNotificationService.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.mdsal.binding.dom.adapter.osgi; + +import com.google.common.annotations.Beta; +import java.util.Map; +import org.opendaylight.mdsal.binding.api.NotificationService; +import org.opendaylight.yangtools.concepts.ListenerRegistration; +import org.opendaylight.yangtools.yang.binding.NotificationListener; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Deactivate; + +@Beta +@Component(factory = OSGiNotificationService.FACTORY_NAME) +public final class OSGiNotificationService extends AbstractAdaptedService + implements NotificationService { + // OSGi DS Component Factory name + static final String FACTORY_NAME = "org.opendaylight.mdsal.binding.dom.adapter.osgi.OSGiNotificationService"; + + public OSGiNotificationService() { + super(NotificationService.class); + } + + @Override + public ListenerRegistration registerNotificationListener(final T listener) { + return delegate().registerNotificationListener(listener); + } + + @Activate + void activate(final Map properties) { + start(properties); + } + + @Deactivate + void deactivate() { + stop(); + } +} -- 2.36.6