import akka.actor.ActorSystem;
import akka.actor.Props;
-import akka.osgi.BundleDelegatingClassLoader;
import com.typesafe.config.Config;
-import com.typesafe.config.ConfigFactory;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
import java.util.concurrent.TimeUnit;
import org.opendaylight.controller.cluster.ActorSystemProvider;
import org.opendaylight.controller.cluster.ActorSystemProviderListener;
-import org.opendaylight.controller.cluster.common.actor.AkkaConfigurationReader;
-import org.opendaylight.controller.cluster.common.actor.FileAkkaConfigurationReader;
import org.opendaylight.controller.cluster.common.actor.QuarantinedMonitorActor;
import org.opendaylight.controller.cluster.datastore.TerminationMonitor;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
import org.opendaylight.yangtools.util.ListenerRegistry;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import scala.concurrent.Await;
public class ActorSystemProviderImpl implements ActorSystemProvider, AutoCloseable {
private static final String ACTOR_SYSTEM_NAME = "opendaylight-cluster-data";
- private static final String CONFIGURATION_NAME = "odl-cluster-data";
static final Logger LOG = LoggerFactory.getLogger(ActorSystemProviderImpl.class);
private final ActorSystem actorSystem;
private final ListenerRegistry<ActorSystemProviderListener> listeners = new ListenerRegistry<>();
- public ActorSystemProviderImpl(final BundleContext bundleContext) {
+ public ActorSystemProviderImpl(
+ final ClassLoader classLoader, final Props quarantinedMonitorActorProps, final Config akkaConfig) {
LOG.info("Creating new ActorSystem");
- final Bundle bundle = bundleContext.getBundle();
-
- final BundleDelegatingClassLoader classLoader = AccessController.doPrivileged(
- (PrivilegedAction<BundleDelegatingClassLoader>) () ->
- new BundleDelegatingClassLoader(bundle, Thread.currentThread().getContextClassLoader()));
-
- final AkkaConfigurationReader configurationReader = new FileAkkaConfigurationReader();
- final Config akkaConfig = ConfigFactory.load(configurationReader.read()).getConfig(CONFIGURATION_NAME);
-
actorSystem = ActorSystem.create(ACTOR_SYSTEM_NAME, akkaConfig, classLoader);
actorSystem.actorOf(Props.create(TerminationMonitor.class), TerminationMonitor.ADDRESS);
-
- actorSystem.actorOf(QuarantinedMonitorActor.props(() -> {
- // restart the entire karaf container
- LOG.warn("Restarting karaf container");
- System.setProperty("karaf.restart.jvm", "true");
- bundleContext.getBundle(0).stop();
- }), QuarantinedMonitorActor.ADDRESS);
+ actorSystem.actorOf(quarantinedMonitorActorProps, QuarantinedMonitorActor.ADDRESS);
}
@Override
try {
Await.result(actorSystem.terminate(), Duration.create(10, TimeUnit.SECONDS));
- } catch (Exception e) {
+ } catch (final Exception e) {
LOG.warn("Error awaiting actor termination", e);
}
}
--- /dev/null
+/*
+ * Copyright (c) 2017 Pantheon Technologies 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.config.yang.config.actor_system_provider.impl.factory;
+
+import com.typesafe.config.Config;
+import com.typesafe.config.ConfigFactory;
+import org.opendaylight.controller.cluster.common.actor.AkkaConfigurationReader;
+
+public class AkkaConfigFactory {
+
+ private static final String CONFIGURATION_NAME = "odl-cluster-data";
+
+ public static Config createAkkaConfig(final AkkaConfigurationReader reader) {
+ return ConfigFactory.load(reader.read()).getConfig(CONFIGURATION_NAME);
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 Pantheon Technologies 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.config.yang.config.actor_system_provider.impl.factory.osgi;
+
+import akka.osgi.BundleDelegatingClassLoader;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import org.osgi.framework.BundleContext;
+
+public class BundleClassLoaderFactory {
+
+ public static ClassLoader createClassLoader(final BundleContext bundleContext) {
+ return AccessController
+ .doPrivileged((PrivilegedAction<BundleDelegatingClassLoader>) () -> new BundleDelegatingClassLoader(
+ bundleContext.getBundle(), Thread.currentThread().getContextClassLoader()));
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 Pantheon Technologies 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.config.yang.config.actor_system_provider.impl.factory.osgi;
+
+import akka.actor.Props;
+import org.opendaylight.controller.cluster.common.actor.QuarantinedMonitorActor;
+import org.osgi.framework.BundleContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class QuarantinedMonitorActorPropsFactory {
+ private static final Logger LOG = LoggerFactory.getLogger(QuarantinedMonitorActorPropsFactory.class);
+
+ public static Props createProps(final BundleContext bundleContext) {
+ return QuarantinedMonitorActor.props(() -> {
+ // restart the entire karaf container
+ LOG.warn("Restarting karaf container");
+ System.setProperty("karaf.restart.jvm", "true");
+ bundleContext.getBundle().stop();
+ });
+ }
+}
<!-- ActorSystemProvider -->
+ <bean id="bundleClassLoader" class="org.opendaylight.controller.config.yang.config.actor_system_provider.impl.factory.osgi.BundleClassLoaderFactory"
+ factory-method="createClassLoader">
+ <argument ref="blueprintBundleContext" />
+ </bean>
+
+ <bean id="actorSystemProps" class="org.opendaylight.controller.config.yang.config.actor_system_provider.impl.factory.osgi.QuarantinedMonitorActorPropsFactory"
+ factory-method="createProps">
+ <argument ref="blueprintBundleContext" />
+ </bean>
+
+ <bean id="akkaReader" class="org.opendaylight.controller.cluster.common.actor.FileAkkaConfigurationReader"/>
+ <bean id="akkaConfig" class="org.opendaylight.controller.config.yang.config.actor_system_provider.impl.factory.AkkaConfigFactory"
+ factory-method="createAkkaConfig">
+ <argument ref="akkaReader" />
+ </bean>
+
<bean id="actorSystemProvider" class="org.opendaylight.controller.config.yang.config.actor_system_provider.impl.ActorSystemProviderImpl"
destroy-method="close">
- <argument ref="blueprintBundleContext"/>
+ <argument ref="bundleClassLoader" />
+ <argument ref="actorSystemProps"/>
+ <argument ref="akkaConfig"/>
</bean>
<service ref="actorSystemProvider" interface="org.opendaylight.controller.cluster.ActorSystemProvider"/>