Factor out ActorSystemProvider from blueprint 76/91276/6
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 12 Jul 2020 08:23:57 +0000 (10:23 +0200)
committerRobert Varga <nite@hq.sk>
Sun, 12 Jul 2020 12:14:57 +0000 (12:14 +0000)
ActorSystemProvider is quite simple, make it completely independent
of blueprint.

Change-Id: I45233cad19ec8580d45d387efe627ab0935ce2eb
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/md-sal/sal-distributed-datastore/pom.xml
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/akka/osgi/impl/OSGiActorSystemProvider.java [new file with mode: 0644]
opendaylight/md-sal/sal-distributed-datastore/src/main/resources/OSGI-INF/blueprint/clustered-datastore.xml

index a6f73ad..9c14d75 100644 (file)
       <groupId>org.osgi</groupId>
       <artifactId>org.osgi.core</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.osgi</groupId>
+      <artifactId>osgi.cmpn</artifactId>
+    </dependency>
 
     <!-- Akka -->
     <dependency>
     <dependency>
       <groupId>com.typesafe.akka</groupId>
       <artifactId>akka-osgi_2.13</artifactId>
+      <exclusions>
+        <exclusion>
+          <groupId>org.osgi</groupId>
+          <artifactId>org.osgi.compendium</artifactId>
+        </exclusion>
+      </exclusions>
     </dependency>
     <dependency>
       <groupId>com.typesafe.akka</groupId>
diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/akka/osgi/impl/OSGiActorSystemProvider.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/akka/osgi/impl/OSGiActorSystemProvider.java
new file mode 100644 (file)
index 0000000..05af18d
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * 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.cluster.akka.osgi.impl;
+
+import akka.actor.ActorSystem;
+import com.typesafe.config.Config;
+import java.util.concurrent.TimeoutException;
+import org.opendaylight.controller.cluster.ActorSystemProvider;
+import org.opendaylight.controller.cluster.ActorSystemProviderListener;
+import org.opendaylight.controller.cluster.akka.impl.ActorSystemProviderImpl;
+import org.opendaylight.controller.cluster.akka.impl.AkkaConfigFactory;
+import org.opendaylight.controller.cluster.common.actor.AkkaConfigurationReader;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.osgi.framework.BundleContext;
+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;
+import scala.concurrent.Await;
+import scala.concurrent.duration.Duration;
+
+@Component(immediate = true)
+public final class OSGiActorSystemProvider implements ActorSystemProvider {
+    private static final Logger LOG = LoggerFactory.getLogger(OSGiActorSystemProvider.class);
+
+    @Reference
+    AkkaConfigurationReader reader = null;
+
+    private ActorSystemProviderImpl delegate;
+
+    @Override
+    public ActorSystem getActorSystem() {
+        return delegate.getActorSystem();
+    }
+
+    @Override
+    public ListenerRegistration<ActorSystemProviderListener> registerActorSystemProviderListener(
+            final ActorSystemProviderListener listener) {
+        return delegate.registerActorSystemProviderListener(listener);
+    }
+
+    @Activate
+    void activate(final BundleContext bundleContext) {
+        LOG.info("Actor System provider starting");
+        final Config akkaConfig = AkkaConfigFactory.createAkkaConfig(reader);
+        delegate = new ActorSystemProviderImpl(BundleClassLoaderFactory.createClassLoader(bundleContext),
+            QuarantinedMonitorActorPropsFactory.createProps(bundleContext, akkaConfig), akkaConfig);
+        LOG.info("Actor System provider started");
+    }
+
+    @Deactivate
+    void deactivate() throws TimeoutException, InterruptedException {
+        LOG.info("Actor System provider stopping");
+        Await.result(delegate.asyncClose(), Duration.Inf());
+        delegate = null;
+        LOG.info("Actor System provider stopped");
+    }
+}
+
index d6fadcb..ef7bc2e 100644 (file)
     <argument ref="bindingSerializer"/>
   </bean>
 
-  <!-- ActorSystemProvider -->
-
-  <bean id="bundleClassLoader" class="org.opendaylight.controller.cluster.akka.osgi.impl.BundleClassLoaderFactory"
-          factory-method="createClassLoader">
-    <argument ref="blueprintBundleContext" />
-  </bean>
-
-  <reference id="akkaReader" interface="org.opendaylight.controller.cluster.common.actor.AkkaConfigurationReader"/>
-
-  <bean id="akkaConfig" class="org.opendaylight.controller.cluster.akka.impl.AkkaConfigFactory"
-          factory-method="createAkkaConfig">
-    <argument ref="akkaReader" />
-  </bean>
-
-  <bean id="actorSystemProps" class="org.opendaylight.controller.cluster.akka.osgi.impl.QuarantinedMonitorActorPropsFactory"
-        factory-method="createProps">
-    <argument ref="blueprintBundleContext" />
-    <argument ref="akkaConfig"/>
-  </bean>
-
-  <bean id="actorSystemProvider" class="org.opendaylight.controller.cluster.akka.impl.ActorSystemProviderImpl"
-          destroy-method="close">
-    <argument ref="bundleClassLoader" />
-    <argument ref="actorSystemProps"/>
-    <argument ref="akkaConfig"/>
-  </bean>
-
-  <service ref="actorSystemProvider" interface="org.opendaylight.controller.cluster.ActorSystemProvider"/>
-
   <!-- Datastore properties -->
+  <reference id="actorSystemProvider" interface="org.opendaylight.controller.cluster.ActorSystemProvider"/>
+
   <cm:cm-properties id="datastoreProps" persistent-id="org.opendaylight.controller.cluster.datastore"/>
 
   <!-- Distributed Config Datastore -->

©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.