2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.cluster.datastore;
11 import akka.actor.ActorSystem;
12 import akka.actor.Props;
13 import akka.osgi.BundleDelegatingClassLoader;
14 import com.google.common.base.Preconditions;
15 import com.typesafe.config.Config;
16 import com.typesafe.config.ConfigFactory;
17 import org.osgi.framework.BundleContext;
21 public class ActorSystemFactory {
23 public static final String AKKA_CONF_PATH = "./configuration/initial/akka.conf";
24 public static final String ACTOR_SYSTEM_NAME = "opendaylight-cluster-data";
25 public static final String CONFIGURATION_NAME = "odl-cluster-data";
27 private static volatile ActorSystem actorSystem = null;
29 public static final ActorSystem getInstance(){
34 * This method should be called only once during initialization
36 * @param bundleContext
38 public static final ActorSystem createInstance(final BundleContext bundleContext) {
39 if(actorSystem == null) {
40 // Create an OSGi bundle classloader for actor system
41 BundleDelegatingClassLoader classLoader = new BundleDelegatingClassLoader(bundleContext.getBundle(),
42 Thread.currentThread().getContextClassLoader());
43 synchronized (ActorSystemFactory.class) {
46 if (actorSystem == null) {
47 ActorSystem system = ActorSystem.create(ACTOR_SYSTEM_NAME,
48 ConfigFactory.load(readAkkaConfiguration()).getConfig(CONFIGURATION_NAME), classLoader);
49 system.actorOf(Props.create(TerminationMonitor.class), "termination-monitor");
59 private static final Config readAkkaConfiguration(){
60 File defaultConfigFile = new File(AKKA_CONF_PATH);
61 Preconditions.checkState(defaultConfigFile.exists(), "akka.conf is missing");
62 return ConfigFactory.parseFile(defaultConfigFile);