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.Config;
14 import org.opendaylight.controller.sal.core.api.Broker;
15 import org.opendaylight.controller.sal.core.api.RpcProvisionRegistry;
16 import org.osgi.framework.BundleContext;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
20 public class RemoteRpcProviderFactory {
21 private static final Logger LOG = LoggerFactory.getLogger(RemoteRpcProviderFactory.class);
23 public static RemoteRpcProvider createInstance(
24 final Broker broker, final BundleContext bundleContext, final RemoteRpcProviderConfig config){
26 RemoteRpcProvider rpcProvider =
27 new RemoteRpcProvider(createActorSystem(bundleContext, config), (RpcProvisionRegistry) broker);
29 broker.registerProvider(rpcProvider);
33 private static ActorSystem createActorSystem(BundleContext bundleContext, RemoteRpcProviderConfig config){
35 // Create an OSGi bundle classloader for actor system
36 BundleDelegatingClassLoader classLoader =
37 new BundleDelegatingClassLoader(bundleContext.getBundle(),
38 Thread.currentThread().getContextClassLoader());
40 Config actorSystemConfig = config.get();
41 if(LOG.isDebugEnabled()) {
42 LOG.debug("Actor system configuration\n{}", actorSystemConfig.root().render());
44 if (config.isMetricCaptureEnabled()) {
45 LOG.info("Instrumentation is enabled in actor system {}. Metrics can be viewed in JMX console.",
46 config.getActorSystemName());
49 return ActorSystem.create(config.getActorSystemName(), actorSystemConfig, classLoader);