From eb38eebf5bcb5190246d7a022731ca2922c8ce18 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Sun, 12 Jul 2020 10:23:57 +0200 Subject: [PATCH] Factor out ActorSystemProvider from blueprint ActorSystemProvider is quite simple, make it completely independent of blueprint. Change-Id: I45233cad19ec8580d45d387efe627ab0935ce2eb Signed-off-by: Robert Varga --- .../md-sal/sal-distributed-datastore/pom.xml | 10 +++ .../osgi/impl/OSGiActorSystemProvider.java | 66 +++++++++++++++++++ .../blueprint/clustered-datastore.xml | 31 +-------- 3 files changed, 78 insertions(+), 29 deletions(-) create mode 100644 opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/akka/osgi/impl/OSGiActorSystemProvider.java diff --git a/opendaylight/md-sal/sal-distributed-datastore/pom.xml b/opendaylight/md-sal/sal-distributed-datastore/pom.xml index a6f73ada75..9c14d7536b 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/pom.xml +++ b/opendaylight/md-sal/sal-distributed-datastore/pom.xml @@ -23,6 +23,10 @@ org.osgi org.osgi.core + + org.osgi + osgi.cmpn + @@ -36,6 +40,12 @@ com.typesafe.akka akka-osgi_2.13 + + + org.osgi + org.osgi.compendium + + com.typesafe.akka 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 index 0000000000..05af18d32f --- /dev/null +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/akka/osgi/impl/OSGiActorSystemProvider.java @@ -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 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"); + } +} + diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/resources/OSGI-INF/blueprint/clustered-datastore.xml b/opendaylight/md-sal/sal-distributed-datastore/src/main/resources/OSGI-INF/blueprint/clustered-datastore.xml index d6fadcbb37..ef7bc2e54c 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/resources/OSGI-INF/blueprint/clustered-datastore.xml +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/resources/OSGI-INF/blueprint/clustered-datastore.xml @@ -18,36 +18,9 @@ - - - - - - - - - - - - - - - - - - - - - - - - - + + -- 2.36.6