Add binding adapter components for MountPointService 82/91782/2
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 30 Jul 2020 21:02:39 +0000 (23:02 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 30 Jul 2020 21:03:27 +0000 (23:03 +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-586
Change-Id: I8e27d8c0b73f69633d889476aeb7808a69d5825f
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
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/OSGiMountPointService.java [new file with mode: 0644]

index 82e631559a2ab6a1c4a82c58e47b6486a690a011..48fe1faef29e35e40466f190cb954b6ae0f1c1aa 100644 (file)
@@ -54,6 +54,8 @@ public final class DynamicBindingAdapter {
 
     @Reference
     AdapterFactory factory = null;
+    @Reference(target = "(component.factory=" + OSGiMountPointService.FACTORY_NAME + ")")
+    ComponentFactory mountPointServiceFactory = null;
     @Reference(target = "(component.factory=" + OSGiRpcConsumerRegistry.FACTORY_NAME + ")")
     ComponentFactory rpcConsumerRegistryFactory = null;
     @Reference(target = "(component.factory=" + OSGiRpcProviderService.FACTORY_NAME + ")")
@@ -64,8 +66,8 @@ public final class DynamicBindingAdapter {
         trackers = ImmutableList.of(
             new AdaptingTracker<>(ctx, DOMDataBroker.class, DataBroker.class, factory::createDataBroker),
             new AdaptingTracker<>(ctx, DOMDataTreeService.class, DataTreeService.class, factory::createDataTreeService),
-            new AdaptingTracker<>(ctx, DOMMountPointService.class, MountPointService.class,
-                    factory::createMountPointService),
+            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,
diff --git a/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/osgi/OSGiMountPointService.java b/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/osgi/OSGiMountPointService.java
new file mode 100644 (file)
index 0000000..77221f4
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * 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 java.util.Optional;
+import org.opendaylight.mdsal.binding.api.MountPoint;
+import org.opendaylight.mdsal.binding.api.MountPointService;
+import org.opendaylight.mdsal.binding.api.MountPointService.MountPointListener;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+
+@Beta
+@Component(factory = OSGiMountPointService.FACTORY_NAME)
+public final class OSGiMountPointService extends AbstractAdaptedService<MountPointService>
+        implements MountPointService {
+    // OSGi DS Component Factory name
+    static final String FACTORY_NAME = "org.opendaylight.mdsal.binding.dom.adapter.osgi.OSGiMountPointService";
+
+    public OSGiMountPointService() {
+        super(MountPointService.class);
+    }
+
+    @Override
+    public Optional<MountPoint> getMountPoint(final InstanceIdentifier<?> mountPoint) {
+        return delegate().getMountPoint(mountPoint);
+    }
+
+    @Override
+    public <T extends MountPointListener> ListenerRegistration<T> registerListener(final InstanceIdentifier<?> path,
+            final T listener) {
+        return delegate().registerListener(path, listener);
+    }
+
+    @Activate
+    void activate(final Map<String, ?> properties) {
+        start(properties);
+    }
+
+    @Deactivate
+    void deactivate() {
+        stop();
+    }
+}