Add binding adapter components for notification services 92/91792/1
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 30 Jul 2020 21:46:00 +0000 (23:46 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 31 Jul 2020 08:52:25 +0000 (10:52 +0200)
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 <robert.varga@pantheon.tech>
(cherry picked from commit 0e769de7475abae5dd06fc2c93d69d0906c66bee)

binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/osgi/DynamicBindingAdapter.java
binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/osgi/OSGiNotificationPublishService.java [new file with mode: 0644]
binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/osgi/OSGiNotificationService.java [new file with mode: 0644]

index 193e7b70c54f480fc5cb0e01f60af8a547ed0374..dace2cd5c52c89083739b232bfc465d59b4be143 100644 (file)
@@ -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 (file)
index 0000000..23fcf25
--- /dev/null
@@ -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<NotificationPublishService>
+        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<? extends Object> offerNotification(final Notification notification) {
+        return delegate().offerNotification(notification);
+    }
+
+    @Override
+    public ListenableFuture<? extends Object> offerNotification(final Notification notification, final int timeout,
+            final TimeUnit unit) throws InterruptedException {
+        return delegate().offerNotification(notification, timeout, unit);
+    }
+
+    @Activate
+    void activate(final Map<String, ?> 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 (file)
index 0000000..1a429f7
--- /dev/null
@@ -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<NotificationService>
+        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 <T extends NotificationListener> ListenerRegistration<T> registerNotificationListener(final T listener) {
+        return delegate().registerNotificationListener(listener);
+    }
+
+    @Activate
+    void activate(final Map<String, ?> properties) {
+        start(properties);
+    }
+
+    @Deactivate
+    void deactivate() {
+        stop();
+    }
+}