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 org.opendaylight.controller.remote.rpc.utils.AkkaConfigurationReader;
14 import org.osgi.framework.BundleContext;
17 public class ActorSystemFactory {
19 public static final String ACTOR_SYSTEM_NAME = "opendaylight-cluster-rpc";
20 public static final String CONFIGURATION_NAME = "odl-cluster-rpc";
22 private static volatile ActorSystem actorSystem = null;
24 public static final ActorSystem getInstance(){
29 * This method should be called only once during initialization
31 * @param bundleContext
33 public static final void createInstance(final BundleContext bundleContext, AkkaConfigurationReader akkaConfigurationReader) {
34 if(actorSystem == null) {
35 // Create an OSGi bundle classloader for actor system
36 BundleDelegatingClassLoader classLoader = new BundleDelegatingClassLoader(bundleContext.getBundle(),
37 Thread.currentThread().getContextClassLoader());
38 synchronized (ActorSystemFactory.class) {
40 if (actorSystem == null) {
41 ActorSystem system = ActorSystem.create(ACTOR_SYSTEM_NAME,
42 akkaConfigurationReader.read().getConfig(CONFIGURATION_NAME), classLoader);
47 throw new IllegalStateException("Actor system should be created only once. Use getInstance method to access existing actor system");