<artifactId>akka-testkit_${scala.version}</artifactId>
<version>${akka.version}</version>
</dependency>
+ <dependency>
+ <groupId>com.typesafe.akka</groupId>
+ <artifactId>akka-osgi_${scala.version}</artifactId>
+ <version>${akka.version}</version>
+ </dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>${mdsal.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>sal-remoterpc-connector</artifactId>
+ <version>${mdsal.version}</version>
+ </dependency>
+
+
<!-- SAL Extension bundles -->
<dependency>
<groupId>org.opendaylight.controller</groupId>
<groupId>org.opendaylight.controller</groupId>
<artifactId>sal-restconf-broker</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>sal-remoterpc-connector</artifactId>
+ </dependency>
+
<dependency>
<groupId>org.opendaylight.controller</groupId>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-testkit_${scala.version}</artifactId>
</dependency>
-
+ <dependency>
+ <groupId>com.typesafe.akka</groupId>
+ <artifactId>akka-osgi_${scala.version}</artifactId>
+ </dependency>
<!-- SAL Dependencies -->
<dependency>
import org.opendaylight.controller.remote.rpc.RemoteRpcProviderFactory;
import org.opendaylight.controller.sal.core.api.Broker;
+import org.osgi.framework.BundleContext;
public class RemoteRPCBrokerModule extends org.opendaylight.controller.config.yang.config.remote_rpc_connector.AbstractRemoteRPCBrokerModule {
+ private BundleContext bundleContext;
public RemoteRPCBrokerModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
super(identifier, dependencyResolver);
}
@Override
public java.lang.AutoCloseable createInstance() {
Broker broker = getDomBrokerDependency();
- return RemoteRpcProviderFactory.createInstance(broker);
+ return RemoteRpcProviderFactory.createInstance(broker, bundleContext);
+ }
+
+ public void setBundleContext(BundleContext bundleContext) {
+ this.bundleContext = bundleContext;
}
}
package org.opendaylight.controller.config.yang.config.remote_rpc_connector;
+import org.opendaylight.controller.config.api.DependencyResolver;
+import org.opendaylight.controller.config.api.DynamicMBeanWithInstance;
+import org.opendaylight.controller.config.spi.Module;
+import org.osgi.framework.BundleContext;
+
public class RemoteRPCBrokerModuleFactory extends org.opendaylight.controller.config.yang.config.remote_rpc_connector.AbstractRemoteRPCBrokerModuleFactory {
+ @Override
+ public Module createModule(String instanceName, DependencyResolver dependencyResolver, BundleContext bundleContext) {
+ RemoteRPCBrokerModule module = (RemoteRPCBrokerModule)super.createModule(instanceName,dependencyResolver,bundleContext);
+ module.setBundleContext(bundleContext);
+ return module;
+ }
+ @Override
+ public Module createModule(String instanceName, DependencyResolver dependencyResolver,
+ DynamicMBeanWithInstance old, BundleContext bundleContext) throws Exception {
+ RemoteRPCBrokerModule module = (RemoteRPCBrokerModule)super.createModule(instanceName, dependencyResolver,
+ old, bundleContext);
+ module.setBundleContext(bundleContext);
+ return module;
+ }
}
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<Void, ActorSystem>(){
+ 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;
+ }
+
+ /**
+ * This method should be called only once during initialization
+ *
+ * @param bundleContext
+ */
+ public static final void createInstance(final BundleContext bundleContext) {
- public static final ActorSystem getInstance(){
- return actorSystem;
+ 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-rpc",
+ ConfigFactory.load().getConfig("odl-cluster"), classLoader);
+ actorSystem = system;
+ }
+ }
+ } else {
+ throw new IllegalStateException("Actor system should be created only once. Use getInstance method to access existing actor system");
}
+ }
}
import org.opendaylight.controller.sal.core.api.Broker;
import org.opendaylight.controller.sal.core.api.RpcProvisionRegistry;
+import org.osgi.framework.BundleContext;
public class RemoteRpcProviderFactory {
- public static RemoteRpcProvider createInstance(final Broker broker){
+ public static RemoteRpcProvider createInstance(final Broker broker, final BundleContext bundleContext){
+
+ ActorSystemFactory.createInstance(bundleContext);
RemoteRpcProvider rpcProvider =
new RemoteRpcProvider(ActorSystemFactory.getInstance(), (RpcProvisionRegistry) broker);
broker.registerProvider(rpcProvider);
value = codec.deserialize(text);
}
- if (schema.getType() instanceof InstanceIdentifierType) {
+ final TypeDefinition<?> baseType = XmlUtils.resolveBaseTypeFrom(schema.getType());
+ if (baseType instanceof InstanceIdentifierType) {
logger.debug("toSimpleNodeWithType: base type of node is instance identifier, deserializing element", xmlElement);
value = InstanceIdentifierForXmlCodec.deserialize(xmlElement,schemaCtx);
}