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.remote.rpc;
11 import akka.actor.ActorSystem;
12 import akka.osgi.BundleDelegatingClassLoader;
13 import com.typesafe.config.ConfigFactory;
14 import org.osgi.framework.BundleContext;
17 public class ActorSystemFactory {
18 private static volatile ActorSystem actorSystem = null;
20 public static final ActorSystem getInstance(){
25 * This method should be called only once during initialization
27 * @param bundleContext
29 public static final void createInstance(final BundleContext bundleContext) {
30 if(actorSystem == null) {
31 // Create an OSGi bundle classloader for actor system
32 BundleDelegatingClassLoader classLoader = new BundleDelegatingClassLoader(bundleContext.getBundle(),
33 Thread.currentThread().getContextClassLoader());
34 synchronized (ActorSystemFactory.class) {
36 if (actorSystem == null) {
37 ActorSystem system = ActorSystem.create("opendaylight-cluster-rpc",
38 ConfigFactory.load().getConfig("odl-cluster-rpc"), classLoader);
43 throw new IllegalStateException("Actor system should be created only once. Use getInstance method to access existing actor system");