From fd71304db951e0c7c732f98313f8fa32843f8df9 Mon Sep 17 00:00:00 2001 From: Moiz Raja Date: Thu, 20 Mar 2014 12:58:16 -0700 Subject: [PATCH] Avoid nullpointer exception on starting up the TopologyProvider and the InventorReadAdapter 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 --- .../sal/compatibility/ComponentActivator.xtend | 4 ++-- .../sal/compatibility/InventoryAndReadAdapter.xtend | 5 ++++- .../compatibility/topology/TopologyProvider.xtend | 13 +++++++++++-- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/ComponentActivator.xtend b/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/ComponentActivator.xtend index a59c2c1636..00ce312335 100644 --- a/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/ComponentActivator.xtend +++ b/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/ComponentActivator.xtend @@ -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) } diff --git a/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/InventoryAndReadAdapter.xtend b/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/InventoryAndReadAdapter.xtend index 0c211fd0aa..f54defdf14 100644 --- a/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/InventoryAndReadAdapter.xtend +++ b/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/InventoryAndReadAdapter.xtend @@ -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); } diff --git a/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/topology/TopologyProvider.xtend b/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/topology/TopologyProvider.xtend index 3df826e36e..4aef75d991 100644 --- a/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/topology/TopologyProvider.xtend +++ b/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/topology/TopologyProvider.xtend @@ -31,8 +31,15 @@ class TopologyProvider implements AutoCloseable{ DataProviderService dataService; Registration,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 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); + } } } -- 2.36.6