Convert messagebus-impl to OSGi DS 74/91774/14
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 30 Jul 2020 15:28:37 +0000 (17:28 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 21 Sep 2020 18:20:07 +0000 (20:20 +0200)
messagebus-impl is an extremely simple component, convert it to
Declarative Services.

JIRA: CONTROLLER-1882
Change-Id: I5131530f3ba907525a7a29775136cd5123f56f18
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/md-sal/messagebus-impl/pom.xml
opendaylight/md-sal/messagebus-impl/src/main/java/org/opendaylight/controller/messagebus/app/impl/OSGiEventSourceRegistry.java [new file with mode: 0644]
opendaylight/md-sal/messagebus-impl/src/main/resources/OSGI-INF/blueprint/messagebus.xml [deleted file]

index 9111061..649a1c0 100644 (file)
@@ -38,5 +38,9 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
             <groupId>org.opendaylight.controller</groupId>
             <artifactId>messagebus-spi</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>osgi.cmpn</artifactId>
+        </dependency>
     </dependencies>
 </project>
diff --git a/opendaylight/md-sal/messagebus-impl/src/main/java/org/opendaylight/controller/messagebus/app/impl/OSGiEventSourceRegistry.java b/opendaylight/md-sal/messagebus-impl/src/main/java/org/opendaylight/controller/messagebus/app/impl/OSGiEventSourceRegistry.java
new file mode 100644 (file)
index 0000000..29389ab
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * 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.controller.messagebus.app.impl;
+
+import com.google.common.annotations.Beta;
+import org.opendaylight.controller.messagebus.spi.EventSource;
+import org.opendaylight.controller.messagebus.spi.EventSourceRegistration;
+import org.opendaylight.controller.messagebus.spi.EventSourceRegistry;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.binding.api.RpcConsumerRegistry;
+import org.opendaylight.mdsal.binding.api.RpcProviderService;
+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.component.annotations.Reference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Beta
+@Component(immediate = true)
+public final class OSGiEventSourceRegistry implements EventSourceRegistry {
+    private static final Logger LOG = LoggerFactory.getLogger(OSGiEventSourceRegistry.class);
+
+    @Reference
+    DataBroker dataBroker;
+    @Reference
+    RpcConsumerRegistry rpcConsumerRegistry;
+    @Reference
+    RpcProviderService rpcProviderService;
+
+    private EventSourceTopology delegate;
+
+    @Override
+    public <T extends EventSource> EventSourceRegistration<T> registerEventSource(final T eventSource) {
+        return delegate.registerEventSource(eventSource);
+    }
+
+    @Override
+    public void close() {
+        // Intentiational no-op
+    }
+
+    @Activate
+    void activate() {
+        delegate = new EventSourceTopology(dataBroker, rpcProviderService, rpcConsumerRegistry);
+        LOG.info("Event Source Registry started");
+    }
+
+    @Deactivate
+    void deactivate() {
+        LOG.info("Event Source Registry stopping");
+        delegate.close();
+        LOG.info("Event Source Registry stopped");
+    }
+}
diff --git a/opendaylight/md-sal/messagebus-impl/src/main/resources/OSGI-INF/blueprint/messagebus.xml b/opendaylight/md-sal/messagebus-impl/src/main/resources/OSGI-INF/blueprint/messagebus.xml
deleted file mode 100644 (file)
index 24a2013..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- Copyright (c) 2017 Inocybe Technologies Inc. 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
--->
-<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
-           xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
-           odl:use-default-for-reference-types="true">
-
-  <reference id="dataBroker" interface="org.opendaylight.mdsal.binding.api.DataBroker"/>
-  <reference id="consumerRegistry" interface="org.opendaylight.mdsal.binding.api.RpcConsumerRegistry"/>
-  <reference id="providerRegistry" interface="org.opendaylight.mdsal.binding.api.RpcProviderService"/>
-
-  <bean id="eventSourceTopology" class="org.opendaylight.controller.messagebus.app.impl.EventSourceTopology"
-          destroy-method="close">
-    <argument ref="dataBroker"/>
-    <argument ref="providerRegistry"/>
-    <argument ref="consumerRegistry"/>
-  </bean>
-
-  <service ref="eventSourceTopology"
-          interface="org.opendaylight.controller.messagebus.spi.EventSourceRegistry"/>
-</blueprint>

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.