Adding remoterpc connector to distribution and Updating actor system creation 99/9599/3
authorHarman Singh <harmasin@cisco.com>
Sat, 2 Aug 2014 01:35:58 +0000 (18:35 -0700)
committerEd Warnicke <eaw@cisco.com>
Tue, 5 Aug 2014 02:35:10 +0000 (02:35 +0000)
Actor system will be created with in bundle class loader now. This change has been made to avoid any conflict with other actor systems.
We faced one class cast exception earlier and this fixes that

Change-Id: Iad55e60ee950fdcff8698270445f0da31bc39c5e
Signed-off-by: Harman Singh <harmasin@cisco.com>
opendaylight/commons/opendaylight/pom.xml
opendaylight/distribution/opendaylight/pom.xml
opendaylight/md-sal/sal-remoterpc-connector/pom.xml
opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/config/yang/config/remote_rpc_connector/RemoteRPCBrokerModule.java
opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/config/yang/config/remote_rpc_connector/RemoteRPCBrokerModuleFactory.java
opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/ActorSystemFactory.java
opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/RemoteRpcProviderFactory.java
opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/utils/XmlDocumentUtils.java

index a7bbbe772d8514c150ec2a92de4acd3cdbca00d9..ff8735a518cff77569d1300cf451ea9f345ce12c 100644 (file)
         <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>
index e4468b6f2735f4c7189ccf236fc48b5d8384e0e6..f8796e0ae4468093bde4cb91a88174335bc3a434 100644 (file)
           <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>
index ce3bfe9a4c81a65decaf51625c7505c07cafc05e..a2bee8ffee7295c8c086365fafa1651235f4efdc 100644 (file)
       <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>
index 9824889b8023d4e31e20d835731c59ef7047c314..2be8ba47b99f9881304f58eeee3dede71497821c 100644 (file)
@@ -2,8 +2,10 @@ package org.opendaylight.controller.config.yang.config.remote_rpc_connector;
 
 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);
   }
@@ -20,6 +22,10 @@ public class RemoteRPCBrokerModule extends org.opendaylight.controller.config.ya
   @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;
   }
 }
index 330845b14fc28bedbc9268467a2fa5075addc5a4..f97338d32971c277de5f258c15c94102f94120a6 100644 (file)
 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;
+  }
 }
index 4a6124a3bc37fbf2a46079dd82df6f1d3ba80283..bd49b6239c443ccd04f70da3dabd964da00c504f 100644 (file)
@@ -9,25 +9,39 @@
 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");
     }
+  }
 }
index 4c40ca177756877f121f0c5187b747241342655c..fc75f7747a0d25361c96f96e77aac30538bb05a5 100644 (file)
@@ -11,9 +11,12 @@ package org.opendaylight.controller.remote.rpc;
 
 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);
index 49ba84307109e650b07e25420506e73bbae57842..b4cca1ab485c3e99373dfd731166c6615e3903d3 100644 (file)
@@ -185,7 +185,8 @@ public class XmlDocumentUtils {
       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);
     }