Use stateless transaction commands
[ovsdb.git] / southbound / southbound-impl / src / main / java / org / opendaylight / ovsdb / southbound / SouthboundProvider.java
index 0b388af8c5a70d2967ab3355149cd0ee95df9096..a331a2ab5d6c83661d9df46d35a148ad9e70b757 100644 (file)
@@ -22,7 +22,6 @@ import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
 import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
 import org.opendaylight.ovsdb.lib.OvsdbConnection;
-import org.opendaylight.ovsdb.lib.impl.OvsdbConnectionService;
 import org.opendaylight.ovsdb.southbound.transactions.md.TransactionInvoker;
 import org.opendaylight.ovsdb.southbound.transactions.md.TransactionInvokerImpl;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
@@ -57,9 +56,12 @@ public class SouthboundProvider implements BindingAwareProvider, AutoCloseable {
 
 
     public SouthboundProvider(
-            EntityOwnershipService entityOwnershipServiceDependency) {
+            EntityOwnershipService entityOwnershipServiceDependency,
+            OvsdbConnection ovsdbConnection) {
         this.entityOwnershipService = entityOwnershipServiceDependency;
         registration = null;
+        this.ovsdbConnection = ovsdbConnection;
+        LOG.info("SouthboundProvider ovsdbConnectionService: {}", ovsdbConnection);
     }
 
     @Override
@@ -67,7 +69,7 @@ public class SouthboundProvider implements BindingAwareProvider, AutoCloseable {
         LOG.info("SouthboundProvider Session Initiated");
         db = session.getSALService(DataBroker.class);
         this.txInvoker = new TransactionInvokerImpl(db);
-        cm = new OvsdbConnectionManager(db,txInvoker,entityOwnershipService);
+        cm = new OvsdbConnectionManager(db,txInvoker,entityOwnershipService, ovsdbConnection);
         ovsdbDataChangeListener = new OvsdbDataChangeListener(db,cm);
 
         //Register listener for entityOnwership changes
@@ -83,21 +85,19 @@ public class SouthboundProvider implements BindingAwareProvider, AutoCloseable {
             if (ownershipStateOpt.isPresent()) {
                 EntityOwnershipState ownershipState = ownershipStateOpt.get();
                 if (ownershipState.hasOwner() && !ownershipState.isOwner()) {
-                    if (ovsdbConnection == null) {
-                        ovsdbConnection = new OvsdbConnectionService();
-                        ovsdbConnection.registerConnectionListener(cm);
-                        ovsdbConnection.startOvsdbManager(SouthboundConstants.DEFAULT_OVSDB_PORT);
-                    }
+                    ovsdbConnection.registerConnectionListener(cm);
+                    ovsdbConnection.startOvsdbManager(SouthboundConstants.DEFAULT_OVSDB_PORT);
+                    LOG.info("*This* instance of OVSDB southbound provider is set as a SLAVE instance");
                 }
             }
         } catch (CandidateAlreadyRegisteredException e) {
             LOG.warn("OVSDB Southbound Provider instance entity {} was already "
-                    + "registered for {} ownership", instanceEntity, e);
+                    + "registered for ownership", instanceEntity, e);
         }
     }
 
     @Override
-    public void close() throws Exception {
+    public void close() {
         LOG.info("SouthboundProvider Closed");
         cm.close();
         ovsdbDataChangeListener.close();
@@ -139,7 +139,7 @@ public class SouthboundProvider implements BindingAwareProvider, AutoCloseable {
                 transaction.cancel();
             }
         } catch (Exception e) {
-            LOG.error("Error initializing ovsdb topology {}",e);
+            LOG.error("Error initializing ovsdb topology", e);
         }
     }
 
@@ -153,11 +153,8 @@ public class SouthboundProvider implements BindingAwareProvider, AutoCloseable {
         } else {
             LOG.info("*This* instance of OVSDB southbound provider is set as a SLAVE instance");
         }
-        if (ovsdbConnection == null) {
-            ovsdbConnection = new OvsdbConnectionService();
-            ovsdbConnection.registerConnectionListener(cm);
-            ovsdbConnection.startOvsdbManager(SouthboundConstants.DEFAULT_OVSDB_PORT);
-        }
+        ovsdbConnection.registerConnectionListener(cm);
+        ovsdbConnection.startOvsdbManager(SouthboundConstants.DEFAULT_OVSDB_PORT);
     }
 
     private class SouthboundPluginInstanceEntityOwnershipListener implements EntityOwnershipListener {