X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-remoterpc-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fremote%2Frpc%2FActorSystemFactory.java;h=f1ca3ccd505e1b1732ad906f75f3662368fdc4a2;hb=3831771765fd07c3ec0f224c8a0c01ce6ae94186;hp=4a6124a3bc37fbf2a46079dd82df6f1d3ba80283;hpb=6d73d16b194435ea1ea783a37d1b51fc1f558a1f;p=controller.git diff --git a/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/ActorSystemFactory.java b/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/ActorSystemFactory.java index 4a6124a3bc..f1ca3ccd50 100644 --- a/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/ActorSystemFactory.java +++ b/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/ActorSystemFactory.java @@ -9,25 +9,38 @@ package org.opendaylight.controller.remote.rpc; import akka.actor.ActorSystem; -import akka.actor.Props; -import com.google.common.base.Function; +import akka.osgi.BundleDelegatingClassLoader; import com.typesafe.config.ConfigFactory; +import org.osgi.framework.BundleContext; -import javax.annotation.Nullable; public class ActorSystemFactory { - private static final ActorSystem actorSystem = (new Function(){ + private static volatile ActorSystem actorSystem = null; - @Nullable @Override public ActorSystem apply(@Nullable Void aVoid) { - ActorSystem system = - ActorSystem.create("opendaylight-rpc", ConfigFactory - .load().getConfig("odl-cluster")); - system.actorOf(Props.create(TerminationMonitor.class), "termination-monitor"); - return system; - } - }).apply(null); + public static final ActorSystem getInstance(){ + return actorSystem; + } - public static final ActorSystem getInstance(){ - return actorSystem; + /** + * This method should be called only once during initialization + * + * @param bundleContext + */ + public static final void createInstance(final BundleContext bundleContext) { + if(actorSystem == null) { + // Create an OSGi bundle classloader for actor system + BundleDelegatingClassLoader classLoader = new BundleDelegatingClassLoader(bundleContext.getBundle(), + Thread.currentThread().getContextClassLoader()); + synchronized (ActorSystemFactory.class) { + // Double check + if (actorSystem == null) { + ActorSystem system = ActorSystem.create("opendaylight-cluster-rpc", + ConfigFactory.load().getConfig("odl-cluster-rpc"), classLoader); + actorSystem = system; + } + } + } else { + throw new IllegalStateException("Actor system should be created only once. Use getInstance method to access existing actor system"); } + } }