Switch DOMNotificationRouter to OSGi DS 75/89075/4
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 16 Apr 2020 14:08:59 +0000 (16:08 +0200)
committerRobert Varga <nite@hq.sk>
Thu, 16 Apr 2020 21:20:39 +0000 (21:20 +0000)
DOMNotificationRouter is easily converted to declarative services,
this performs the migration.

JIRA: MDSAL-521
Change-Id: I54990b7ccbe45a717c46742216487b90dc4855fd
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
dom/mdsal-dom-broker/src/main/java/org/opendaylight/mdsal/dom/broker/OSGiDOMNotificationRouter.java [new file with mode: 0644]
dom/mdsal-dom-broker/src/main/resources/org/opendaylight/blueprint/dom-broker.xml [deleted file]

diff --git a/dom/mdsal-dom-broker/src/main/java/org/opendaylight/mdsal/dom/broker/OSGiDOMNotificationRouter.java b/dom/mdsal-dom-broker/src/main/java/org/opendaylight/mdsal/dom/broker/OSGiDOMNotificationRouter.java
new file mode 100644 (file)
index 0000000..87ebcdb
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ * 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.dom.broker;
+
+import com.google.common.util.concurrent.ListenableFuture;
+import java.util.Collection;
+import java.util.concurrent.TimeUnit;
+import org.opendaylight.mdsal.dom.api.DOMNotification;
+import org.opendaylight.mdsal.dom.api.DOMNotificationListener;
+import org.opendaylight.mdsal.dom.api.DOMNotificationPublishService;
+import org.opendaylight.mdsal.dom.api.DOMNotificationService;
+import org.opendaylight.mdsal.dom.spi.DOMNotificationSubscriptionListener;
+import org.opendaylight.mdsal.dom.spi.DOMNotificationSubscriptionListenerRegistry;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.metatype.annotations.AttributeDefinition;
+import org.osgi.service.metatype.annotations.Designate;
+import org.osgi.service.metatype.annotations.ObjectClassDefinition;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Component(immediate = true, configurationPid = "org.opendaylight.mdsal.dom.notification", service = {
+        DOMNotificationService.class, DOMNotificationPublishService.class,
+        DOMNotificationSubscriptionListenerRegistry.class
+})
+@Designate(ocd = OSGiDOMNotificationRouter.Config.class)
+public final class OSGiDOMNotificationRouter implements DOMNotificationService, DOMNotificationPublishService,
+        DOMNotificationSubscriptionListenerRegistry {
+    @ObjectClassDefinition()
+    public @interface Config {
+        @AttributeDefinition(name = "notification-queue-depth")
+        int queueDepth() default 65536;
+        @AttributeDefinition(name = "notification-queue-spin")
+        long spinTime() default 0;
+        @AttributeDefinition(name = "notification-queue-park")
+        long parkTime() default 0;
+    }
+
+    private static final Logger LOG = LoggerFactory.getLogger(OSGiDOMNotificationRouter.class);
+
+    private DOMNotificationRouter router;
+
+    @Activate
+    void activate(final Config config) {
+        router = DOMNotificationRouter.create(config.queueDepth(), config.spinTime(), config.parkTime(),
+            TimeUnit.MILLISECONDS);
+        LOG.info("DOM Notification Router started");
+    }
+
+    @Deactivate
+    void deactivate() {
+        router.close();
+        router = null;
+        LOG.info("DOM Notification Router stopped");
+    }
+
+    @Override
+    public <L extends DOMNotificationSubscriptionListener> ListenerRegistration<L> registerSubscriptionListener(
+            final L listener) {
+        return router.registerSubscriptionListener(listener);
+    }
+
+    @Override
+    public ListenableFuture<? extends Object> putNotification(final DOMNotification notification)
+            throws InterruptedException {
+        return router.putNotification(notification);
+    }
+
+    @Override
+    public ListenableFuture<? extends Object> offerNotification(final DOMNotification notification) {
+        return router.offerNotification(notification);
+    }
+
+    @Override
+    public ListenableFuture<? extends Object> offerNotification(final DOMNotification notification,
+            final long timeout, final TimeUnit unit) throws InterruptedException {
+        return router.offerNotification(notification, timeout, unit);
+    }
+
+    @Override
+    public <T extends DOMNotificationListener> ListenerRegistration<T> registerNotificationListener(final T listener,
+            final Collection<SchemaPath> types) {
+        return router.registerNotificationListener(listener, types);
+    }
+
+    @Override
+    public <T extends DOMNotificationListener> ListenerRegistration<T> registerNotificationListener(final T listener,
+            final SchemaPath... types) {
+        return router.registerNotificationListener(listener, types);
+    }
+}
diff --git a/dom/mdsal-dom-broker/src/main/resources/org/opendaylight/blueprint/dom-broker.xml b/dom/mdsal-dom-broker/src/main/resources/org/opendaylight/blueprint/dom-broker.xml
deleted file mode 100644 (file)
index 735d18e..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
-           xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
-           xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
-    odl:restart-dependents-on-updates="false">
-
-  <cm:property-placeholder persistent-id="org.opendaylight.mdsal.dom.notification" update-strategy="none">
-    <cm:default-properties>
-      <cm:property name="notification-queue-depth" value="65536"/>
-      <cm:property name="notification-queue-spin" value="0"/>
-      <cm:property name="notification-queue-park" value="0"/>
-    </cm:default-properties>
-  </cm:property-placeholder>
-
-  <!-- DOM Notification Service -->
-
-  <bean id="domNotificationRouter" class="org.opendaylight.mdsal.dom.broker.DOMNotificationRouter"
-          factory-method="create">
-    <argument value="${notification-queue-depth}"/>
-    <argument value="${notification-queue-spin}"/>
-    <argument value="${notification-queue-park}"/>
-    <argument value="MILLISECONDS"/>
-  </bean>
-
-  <service ref="domNotificationRouter" odl:type="default">
-    <interfaces>
-      <value>org.opendaylight.mdsal.dom.api.DOMNotificationService</value>
-      <value>org.opendaylight.mdsal.dom.api.DOMNotificationPublishService</value>
-      <value>org.opendaylight.mdsal.dom.spi.DOMNotificationSubscriptionListenerRegistry</value>
-    </interfaces>
-  </service>
-</blueprint>