Converted Inventory Manager to use Transaction Chaining 64/10064/1
authorTony Tkacik <ttkacik@cisco.com>
Tue, 19 Aug 2014 13:18:53 +0000 (15:18 +0200)
committerTony Tkacik <ttkacik@cisco.com>
Tue, 19 Aug 2014 13:30:18 +0000 (15:30 +0200)
Change-Id: Ife022b95daf4bf20b4e0fa243b2d55d898b85722
Signed-off-by: Tony Tkacik <ttkacik@cisco.com>
opendaylight/md-sal/inventory-manager/src/main/java/org/opendaylight/controller/md/inventory/manager/FlowCapableInventoryProvider.java

index 29ac12393ac54aa33d2de6b01af01c1213db1c4c..1e77a5554f179ee61da82e826d9cbf36269a94f5 100644 (file)
@@ -13,15 +13,19 @@ import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
 import java.util.concurrent.BlockingQueue;
 import java.util.concurrent.LinkedBlockingDeque;
+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.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-class FlowCapableInventoryProvider implements AutoCloseable, Runnable {
+class FlowCapableInventoryProvider implements AutoCloseable, Runnable, TransactionChainListener {
     private static final Logger LOG = LoggerFactory.getLogger(FlowCapableInventoryProvider.class);
     private static final int QUEUE_DEPTH = 500;
     private static final int MAX_BATCH = 100;
@@ -30,6 +34,7 @@ class FlowCapableInventoryProvider implements AutoCloseable, Runnable {
     private final NotificationProviderService notificationService;
 
     private final DataBroker dataBroker;
+    private BindingTransactionChain txChain;
     private ListenerRegistration<?> listenerRegistration;
     private Thread thread;
 
@@ -42,6 +47,7 @@ class FlowCapableInventoryProvider implements AutoCloseable, Runnable {
         final NodeChangeCommiter changeCommiter = new NodeChangeCommiter(FlowCapableInventoryProvider.this);
         this.listenerRegistration = this.notificationService.registerNotificationListener(changeCommiter);
 
+        this.txChain =  dataBroker.createTransactionChain(this);
         thread = new Thread(this);
         thread.setDaemon(true);
         thread.setName("FlowCapableInventoryProvider");
@@ -75,6 +81,10 @@ class FlowCapableInventoryProvider implements AutoCloseable, Runnable {
             thread.join();
             thread = null;
         }
+        if(txChain != null) {
+            txChain.close();
+            txChain = null;
+        }
 
 
     }
@@ -85,7 +95,7 @@ class FlowCapableInventoryProvider implements AutoCloseable, Runnable {
             for (; ; ) {
                 InventoryOperation op = queue.take();
 
-                final ReadWriteTransaction tx = dataBroker.newReadWriteTransaction();
+                final ReadWriteTransaction tx = txChain.newReadWriteTransaction();
                 LOG.debug("New operations available, starting transaction {}", tx.getIdentifier());
 
                 int ops = 0;
@@ -105,12 +115,12 @@ class FlowCapableInventoryProvider implements AutoCloseable, Runnable {
                 final CheckedFuture<Void, TransactionCommitFailedException> result = tx.submit();
                 Futures.addCallback(result, new FutureCallback<Void>() {
                     @Override
-                    public void onSuccess(Void aVoid) {
+                    public void onSuccess(final Void aVoid) {
                         //NOOP
                     }
 
                     @Override
-                    public void onFailure(Throwable throwable) {
+                    public void onFailure(final Throwable throwable) {
                         LOG.error("Transaction {} failed.", tx.getIdentifier(), throwable);
                     }
                 });
@@ -124,4 +134,16 @@ class FlowCapableInventoryProvider implements AutoCloseable, Runnable {
             queue.poll();
         }
     }
+
+    @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);
+
+    }
+
+    @Override
+    public void onTransactionChainSuccessful(final TransactionChain<?, ?> chain) {
+        // NOOP
+    }
 }