Merge "Bug 1686 - Rework TopologyManager to use transaction chaining in order to...
authorTony Tkacik <ttkacik@cisco.com>
Fri, 5 Sep 2014 07:10:27 +0000 (07:10 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Fri, 5 Sep 2014 07:10:27 +0000 (07:10 +0000)
opendaylight/md-sal/inventory-manager/src/main/java/org/opendaylight/controller/md/inventory/manager/FlowCapableInventoryProvider.java
opendaylight/md-sal/topology-manager/src/main/java/org/opendaylight/md/controller/topology/manager/OperationProcessor.java

index 1e77a5554f179ee61da82e826d9cbf36269a94f5..3db929b99d9c68065cec7875412901090570530d 100644 (file)
@@ -47,7 +47,7 @@ class FlowCapableInventoryProvider implements AutoCloseable, Runnable, Transacti
         final NodeChangeCommiter changeCommiter = new NodeChangeCommiter(FlowCapableInventoryProvider.this);
         this.listenerRegistration = this.notificationService.registerNotificationListener(changeCommiter);
 
-        this.txChain =  dataBroker.createTransactionChain(this);
+        this.txChain = dataBroker.createTransactionChain(this);
         thread = new Thread(this);
         thread.setDaemon(true);
         thread.setName("FlowCapableInventoryProvider");
@@ -81,7 +81,7 @@ class FlowCapableInventoryProvider implements AutoCloseable, Runnable, Transacti
             thread.join();
             thread = null;
         }
-        if(txChain != null) {
+        if (txChain != null) {
             txChain.close();
             txChain = null;
         }
@@ -137,8 +137,8 @@ class FlowCapableInventoryProvider implements AutoCloseable, Runnable, Transacti
 
     @Override
     public void onTransactionChainFailed(final TransactionChain<?, ?> chain, final AsyncTransaction<?, ?> transaction,
-            final Throwable cause) {
-        LOG.error("Failed to export Flow Capable Inventory, Transaction {} failed.",transaction.getIdentifier(),cause);
+                                         final Throwable cause) {
+        LOG.error("Failed to export Flow Capable Inventory, Transaction {} failed.", transaction.getIdentifier(), cause);
 
     }
 
index 3800413eb1b9964d00207f526177862eb69c5885..1cf648eb975c521d6c81e22b927e8f276f888e99 100644 (file)
@@ -13,21 +13,27 @@ import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
 import java.util.concurrent.BlockingQueue;
 import java.util.concurrent.LinkedBlockingQueue;
+import org.opendaylight.controller.md.sal.binding.api.BindingTransactionChain;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.TransactionChain;
+import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-final class OperationProcessor implements Runnable {
+final class OperationProcessor implements AutoCloseable, Runnable, TransactionChainListener {
     private static final Logger LOG = LoggerFactory.getLogger(OperationProcessor.class);
     private static final int MAX_TRANSACTION_OPERATIONS = 100;
     private static final int OPERATION_QUEUE_DEPTH = 500;
 
     private final BlockingQueue<TopologyOperation> queue = new LinkedBlockingQueue<>(OPERATION_QUEUE_DEPTH);
     private final DataBroker dataBroker;
+    private final BindingTransactionChain transactionChain;
 
     OperationProcessor(final DataBroker dataBroker) {
         this.dataBroker = Preconditions.checkNotNull(dataBroker);
+        transactionChain = this.dataBroker.createTransactionChain(this);
     }
 
     void enqueueOperation(final TopologyOperation task) {
@@ -45,7 +51,8 @@ final class OperationProcessor implements Runnable {
                 TopologyOperation op = queue.take();
 
                 LOG.debug("New operations available, starting transaction");
-                final ReadWriteTransaction tx = dataBroker.newReadWriteTransaction();
+                final ReadWriteTransaction tx = transactionChain.newReadWriteTransaction();
+
 
                 int ops = 0;
                 do {
@@ -83,4 +90,22 @@ final class OperationProcessor implements Runnable {
             queue.poll();
         }
     }
+
+    @Override
+    public void onTransactionChainFailed(TransactionChain<?, ?> chain, AsyncTransaction<?, ?> transaction, Throwable cause) {
+        LOG.error("Failed to export Topology manager operations, Transaction {} failed.", transaction.getIdentifier(), cause);
+    }
+
+    @Override
+    public void onTransactionChainSuccessful(TransactionChain<?, ?> chain) {
+        //NOOP
+    }
+
+    @Override
+    public void close() throws Exception {
+        if (transactionChain != null) {
+            transactionChain.close();
+        }
+
+    }
 }