Move ShardManagerSnapshot to new package
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / LocalTransactionFactoryImpl.java
index 149b9370ecba75bd264e2f50c8d5cdfd89a4b39a..700d96f4fd7d79e2e9b513215c93e317cfe27dc0 100644 (file)
@@ -9,6 +9,8 @@ package org.opendaylight.controller.cluster.datastore;
 
 import akka.actor.ActorSelection;
 import com.google.common.base.Preconditions;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
 import org.opendaylight.controller.cluster.datastore.identifiers.TransactionIdentifier;
 import org.opendaylight.controller.cluster.datastore.utils.ActorContext;
 import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadTransaction;
@@ -20,8 +22,6 @@ import org.opendaylight.controller.sal.core.spi.data.SnapshotBackedWriteTransact
 import org.opendaylight.controller.sal.core.spi.data.SnapshotBackedWriteTransaction.TransactionReadyPrototype;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 /**
  * {@link LocalTransactionFactory} for instantiating backing transactions which are
@@ -31,7 +31,6 @@ import org.slf4j.LoggerFactory;
 final class LocalTransactionFactoryImpl extends TransactionReadyPrototype<TransactionIdentifier>
         implements LocalTransactionFactory {
 
-    private static final Logger LOG = LoggerFactory.getLogger(LocalTransactionFactoryImpl.class);
     private final ActorSelection leader;
     private final DataTree dataTree;
     private final ActorContext actorContext;
@@ -69,18 +68,25 @@ final class LocalTransactionFactoryImpl extends TransactionReadyPrototype<Transa
     @Override
     protected DOMStoreThreePhaseCommitCohort transactionReady(final SnapshotBackedWriteTransaction<TransactionIdentifier> tx,
             final DataTreeModification tree) {
-        return new LocalThreePhaseCommitCohort(actorContext, leader, tx, tree) {
-            @Override
-            protected void transactionAborted(final SnapshotBackedWriteTransaction<TransactionIdentifier> transaction) {
-                // No-op
-                LOG.debug("Transaction {} aborted", transaction);
-            }
+        return new LocalThreePhaseCommitCohort(actorContext, leader, tx, tree);
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public LocalThreePhaseCommitCohort onTransactionReady(@Nonnull DOMStoreWriteTransaction tx,
+            @Nullable Exception operationError) {
+        if(operationError != null) {
+            return new LocalThreePhaseCommitCohort(actorContext, leader,
+                    (SnapshotBackedWriteTransaction<TransactionIdentifier>)tx, operationError);
+        }
 
-            @Override
-            protected void transactionCommitted(final SnapshotBackedWriteTransaction<TransactionIdentifier> transaction) {
-                // No-op
-                LOG.debug("Transaction {} committed", transaction);
-            }
-        };
+        try {
+            return (LocalThreePhaseCommitCohort) tx.ready();
+        } catch (Exception e) {
+            // Unfortunately we need to cast to SnapshotBackedWriteTransaction here as it's required by
+            // LocalThreePhaseCommitCohort.
+            return new LocalThreePhaseCommitCohort(actorContext, leader,
+                    (SnapshotBackedWriteTransaction<TransactionIdentifier>)tx, e);
+        }
     }
 }