Avoid nullpointer exception on starting up the TopologyProvider and the InventorReadA... 99/5699/2
authorMoiz Raja <moraja@cisco.com>
Thu, 20 Mar 2014 19:58:16 +0000 (12:58 -0700)
committerMoiz Raja <moraja@cisco.com>
Thu, 27 Mar 2014 18:58:57 +0000 (11:58 -0700)
The TopologyProvider and InventoryAndReadAdapter are Felix services which get started when all it's
dependencies are resolved (that is their start method gets called). The MD-SAL DataProviderService is not
or cannot be injected into them and so when start is called and the dataProviderService is used it throws an NPE

To fix this I simply moved most of the startup code into a separate method which I then call from the ComponentActivator
instead of start

Change-Id: Ia6f0b6cebd38f4af7f03c9da8a5e26e05c13f664
Signed-off-by: Moiz Raja <moraja@cisco.com>
opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/ComponentActivator.xtend
opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/InventoryAndReadAdapter.xtend
opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/topology/TopologyProvider.xtend

index a59c2c1..00ce312 100644 (file)
@@ -251,9 +251,9 @@ package class SalCompatibilityProvider implements BindingAwareProvider {
         topology.dataService = session.getSALService(DataProviderService)
         tpProvider.dataService = session.getSALService(DataProviderService)
 
-        inventory.start();
+        inventory.startAdapter();
 
-        tpProvider.start();
+        tpProvider.startAdapter();
 
         subscribe.registerNotificationListener(dataPacket)
     }
index 0c211fd..f54defd 100644 (file)
@@ -122,12 +122,15 @@ class InventoryAndReadAdapter implements IPluginInReadService,
     private final Lock nodeToNodeConnectorsLock = new ReentrantLock();
 
 
-    def start(){
+    def startAdapter(){
         inventoryNotificationProvider.dataProviderService = dataProviderService;
         inventoryNotificationProvider.inventoryPublisher = inventoryPublisher;
         // inventoryNotificationProvider.start();
     }
 
+    def start(){
+    }
+
     def setInventoryPublisher(IPluginOutInventoryService listener){
         inventoryPublisher.add(listener);
     }
index 3df826e..4aef75d 100644 (file)
@@ -31,8 +31,15 @@ class TopologyProvider implements AutoCloseable{
     DataProviderService dataService;
     
     Registration<DataCommitHandler<InstanceIdentifier<? extends DataObject>,DataObject>> commitHandlerRegistration;
-    
+
     def void start() {
+
+    }
+    def void startAdapter() {
+        if(dataService == null){
+            LOG.error("dataService not set");
+            return;
+        }
         commitHandler = new TopologyCommitHandler(dataService)
         commitHandler.setTopologyPublisher(topologyPublisher)
         val InstanceIdentifier<? extends DataObject> path = InstanceIdentifier.builder(NetworkTopology)
@@ -49,7 +56,9 @@ class TopologyProvider implements AutoCloseable{
     
     def setTopologyPublisher(IPluginOutTopologyService topologyPublisher) {
         _topologyPublisher = topologyPublisher;
-        commitHandler.setTopologyPublisher(topologyPublisher);
+        if(commitHandler != null){
+            commitHandler.setTopologyPublisher(topologyPublisher);
+        }
     }
     
 }