Fix transaction manager closing.
[openflowplugin.git] / applications / topology-manager / src / main / java / org / opendaylight / openflowplugin / applications / topology / manager / TopologyManagerUtil.java
index 96dd36e582958688b83e6d2acb4373beb5caab13..b3dfcb278f095650676477d77422630814772c18 100644 (file)
@@ -10,9 +10,9 @@ package org.opendaylight.openflowplugin.applications.topology.manager;
 import com.google.common.base.Optional;
 import java.util.Collections;
 import java.util.List;
-import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
+import org.opendaylight.openflowplugin.common.txchain.TransactionChainManager;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
@@ -21,54 +21,54 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class TopologyManagerUtil {
+class TopologyManagerUtil {
 
     private static final Logger LOG = LoggerFactory.getLogger(TopologyManagerUtil.class);
 
     private TopologyManagerUtil() {}
 
-    static void removeAffectedLinks(final NodeId id, final ReadWriteTransaction transaction, InstanceIdentifier<Topology> topology) {
+    static void removeAffectedLinks(final NodeId id, final TransactionChainManager manager, InstanceIdentifier<Topology> topology) {
         Optional<Topology> topologyOptional = Optional.absent();
         try {
-            topologyOptional = transaction.read(LogicalDatastoreType.OPERATIONAL, topology).checkedGet();
+            topologyOptional = manager.readFromTransaction(LogicalDatastoreType.OPERATIONAL, topology).checkedGet();
         } catch (ReadFailedException e) {
             LOG.warn("Error reading topology data for topology {}: {}", topology, e.getMessage());
             LOG.debug("Error reading topology data for topology.. ", e);
         }
         if (topologyOptional.isPresent()) {
-            removeAffectedLinks(id, topologyOptional, transaction, topology);
+            removeAffectedLinks(id, topologyOptional, manager, topology);
         }
     }
 
-    static void removeAffectedLinks(final NodeId id, Optional<Topology> topologyOptional, ReadWriteTransaction transaction, final InstanceIdentifier<Topology> topology) {
+    private static void removeAffectedLinks(final NodeId id, Optional<Topology> topologyOptional, TransactionChainManager manager, final InstanceIdentifier<Topology> topology) {
         if (!topologyOptional.isPresent()) {
             return;
         }
 
         List<Link> linkList = topologyOptional.get().getLink() != null ?
-                topologyOptional.get().getLink() : Collections.<Link> emptyList();
+                topologyOptional.get().getLink() : Collections.emptyList();
         for (Link link : linkList) {
             if (id.equals(link.getSource().getSourceNode()) ||
                     id.equals(link.getDestination().getDestNode())) {
-                transaction.delete(LogicalDatastoreType.OPERATIONAL, linkPath(link, topology));
+                manager.addDeleteOperationTotTxChain(LogicalDatastoreType.OPERATIONAL, linkPath(link, topology));
             }
         }
     }
 
-    static void removeAffectedLinks(final TpId id, final ReadWriteTransaction transaction, final InstanceIdentifier<Topology> topology) {
+    static void removeAffectedLinks(final TpId id, final TransactionChainManager manager, final InstanceIdentifier<Topology> topology) {
         Optional<Topology> topologyOptional = Optional.absent();
         try {
-            topologyOptional = transaction.read(LogicalDatastoreType.OPERATIONAL, topology).checkedGet();
+            topologyOptional = manager.readFromTransaction(LogicalDatastoreType.OPERATIONAL, topology).checkedGet();
         } catch (ReadFailedException e) {
             LOG.warn("Error reading topology data for topology {}: {}", topology, e.getMessage());
             LOG.debug("Error reading topology data for topology..", e);
         }
         if (topologyOptional.isPresent()) {
-            removeAffectedLinks(id, topologyOptional, transaction, topology);
+            removeAffectedLinks(id, topologyOptional, manager, topology);
         }
     }
 
-    static void removeAffectedLinks(final TpId id, Optional<Topology> topologyOptional, ReadWriteTransaction transaction, final InstanceIdentifier<Topology> topology) {
+    private static void removeAffectedLinks(final TpId id, Optional<Topology> topologyOptional, TransactionChainManager manager, final InstanceIdentifier<Topology> topology) {
         if (!topologyOptional.isPresent()) {
             return;
         }
@@ -78,7 +78,7 @@ public class TopologyManagerUtil {
         for (Link link : linkList) {
             if (id.equals(link.getSource().getSourceTp()) ||
                     id.equals(link.getDestination().getDestTp())) {
-                transaction.delete(LogicalDatastoreType.OPERATIONAL, linkPath(link, topology));
+                manager.addDeleteOperationTotTxChain(LogicalDatastoreType.OPERATIONAL, linkPath(link, topology));
             }
         }
     }