Make LocalThreePhaseCommitCohort::operationError final 64/31464/2
authorTom Pantelis <tpanteli@brocade.com>
Tue, 15 Dec 2015 18:45:27 +0000 (13:45 -0500)
committerTony Tkacik <ttkacik@cisco.com>
Mon, 4 Jan 2016 13:58:13 +0000 (13:58 +0000)
This is a follow-up to https://git.opendaylight.org/gerrit/#/c/31448/ to
make LocalThreePhaseCommitCohort::operationError final and remove the
setter. The callers were refactored to use the
LocalThreePhaseCommitCohort ctor that passes the operationError.

Change-Id: I68f69be08e7f74524e92f224172ebf1ca9469017
Signed-off-by: Tom Pantelis <tpanteli@brocade.com>
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/LocalThreePhaseCommitCohort.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/LocalTransactionChain.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/LocalTransactionContext.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/LocalTransactionFactoryImpl.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/LocalTransactionReadySupport.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/LocalTransactionContextTest.java

index 442e2f3b4dd77c88cfb3b57e868f5f5ed0a4d4fc..5323adb03a23867b462614149697d6edec778d84 100644 (file)
@@ -12,7 +12,6 @@ import akka.dispatch.Futures;
 import akka.dispatch.OnComplete;
 import com.google.common.base.Preconditions;
 import com.google.common.util.concurrent.ListenableFuture;
-import javax.annotation.Nonnull;
 import org.opendaylight.controller.cluster.datastore.identifiers.TransactionIdentifier;
 import org.opendaylight.controller.cluster.datastore.messages.CommitTransactionReply;
 import org.opendaylight.controller.cluster.datastore.messages.ReadyLocalTransaction;
@@ -38,7 +37,7 @@ class LocalThreePhaseCommitCohort implements DOMStoreThreePhaseCommitCohort {
     private final DataTreeModification modification;
     private final ActorContext actorContext;
     private final ActorSelection leader;
-    private Exception operationError;
+    private final Exception operationError;
 
     protected LocalThreePhaseCommitCohort(final ActorContext actorContext, final ActorSelection leader,
             final SnapshotBackedWriteTransaction<TransactionIdentifier> transaction, final DataTreeModification modification) {
@@ -46,6 +45,7 @@ class LocalThreePhaseCommitCohort implements DOMStoreThreePhaseCommitCohort {
         this.leader = Preconditions.checkNotNull(leader);
         this.transaction = Preconditions.checkNotNull(transaction);
         this.modification = Preconditions.checkNotNull(modification);
+        this.operationError = null;
     }
 
     protected LocalThreePhaseCommitCohort(final ActorContext actorContext, final ActorSelection leader,
@@ -67,14 +67,6 @@ class LocalThreePhaseCommitCohort implements DOMStoreThreePhaseCommitCohort {
         return actorContext.executeOperationAsync(leader, message, actorContext.getTransactionCommitOperationTimeout());
     }
 
-    void setOperationError(@Nonnull Exception operationError) {
-        if (this.operationError != null) {
-            LOG.info("Cohort {} already had operation error", this, this.operationError);
-        }
-
-        this.operationError = Preconditions.checkNotNull(operationError);
-    }
-
     Future<ActorSelection> initiateCoordinatedCommit() {
         final Future<Object> messageFuture = initiateCommit(false);
         final Future<ActorSelection> ret = TransactionReadyReplyMapper.transform(messageFuture, actorContext,
index 56466f78408fe24602564f9c62e14a8f5e31add5..b42c52d99341a716ae337510cea158cac1fd6de4 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.sal.core.spi.data.AbstractSnapshotBackedTransactionChain;
 import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadTransaction;
@@ -78,7 +80,13 @@ final class LocalTransactionChain extends AbstractSnapshotBackedTransactionChain
 
     @SuppressWarnings("unchecked")
     @Override
-    public LocalThreePhaseCommitCohort onTransactionReady(DOMStoreWriteTransaction tx) {
+    public LocalThreePhaseCommitCohort onTransactionReady(@Nonnull DOMStoreWriteTransaction tx,
+            @Nullable Exception operationError) {
+        if(operationError != null) {
+            return new LocalChainThreePhaseCommitCohort((SnapshotBackedWriteTransaction<TransactionIdentifier>)tx,
+                    operationError);
+        }
+
         try {
             return (LocalThreePhaseCommitCohort) tx.ready();
         } catch (Exception e) {
index 9398171b202bd2f05a5d9028946ebe26d44ce175..75cdd1b597c0bc29bf8ee8df4745b8a97902d147 100644 (file)
@@ -112,11 +112,7 @@ abstract class LocalTransactionContext extends AbstractTransactionContext {
 
     private LocalThreePhaseCommitCohort ready() {
         logModificationCount();
-        LocalThreePhaseCommitCohort cohort = readySupport.onTransactionReady(getWriteDelegate());
-        if (operationError != null) {
-            cohort.setOperationError(operationError);
-        }
-        return cohort;
+        return readySupport.onTransactionReady(getWriteDelegate(), operationError);
     }
 
     @Override
index 2f4474b5d7350071b90244e2297f3917d7fbe180..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;
@@ -71,7 +73,13 @@ final class LocalTransactionFactoryImpl extends TransactionReadyPrototype<Transa
 
     @SuppressWarnings("unchecked")
     @Override
-    public LocalThreePhaseCommitCohort onTransactionReady(DOMStoreWriteTransaction tx) {
+    public LocalThreePhaseCommitCohort onTransactionReady(@Nonnull DOMStoreWriteTransaction tx,
+            @Nullable Exception operationError) {
+        if(operationError != null) {
+            return new LocalThreePhaseCommitCohort(actorContext, leader,
+                    (SnapshotBackedWriteTransaction<TransactionIdentifier>)tx, operationError);
+        }
+
         try {
             return (LocalThreePhaseCommitCohort) tx.ready();
         } catch (Exception e) {
index e03f3d2433dc0a817e23e17e1da674ccc6ee5f0d..2e0dbb9fd1bbc813d15a8ede4174e60c1b8911a8 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.controller.cluster.datastore;
 
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
 import org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction;
 
 /**
@@ -15,5 +17,6 @@ import org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction;
  * @author Thomas Pantelis
  */
 interface LocalTransactionReadySupport {
-    LocalThreePhaseCommitCohort onTransactionReady(DOMStoreWriteTransaction tx);
+    LocalThreePhaseCommitCohort onTransactionReady(@Nonnull DOMStoreWriteTransaction tx,
+            @Nullable Exception operationError);
 }
index 08c4813523064441219977a2a388a1ff0ae3c2c2..838a169dbe1af622ce6ccdb61e9eecc90d5f7031 100644 (file)
@@ -106,12 +106,12 @@ public class LocalTransactionContextTest {
     public void testReady() {
         final LocalThreePhaseCommitCohort mockCohort = mock(LocalThreePhaseCommitCohort.class);
         doReturn(akka.dispatch.Futures.successful(null)).when(mockCohort).initiateCoordinatedCommit();
-        doReturn(mockCohort).when(mockReadySupport).onTransactionReady(readWriteTransaction);
+        doReturn(mockCohort).when(mockReadySupport).onTransactionReady(readWriteTransaction, null);
 
         Future<ActorSelection> future = localTransactionContext.readyTransaction();
         assertTrue(future.isCompleted());
 
-        verify(mockReadySupport).onTransactionReady(readWriteTransaction);
+        verify(mockReadySupport).onTransactionReady(readWriteTransaction, null);
     }
 
     @Test
@@ -161,10 +161,8 @@ public class LocalTransactionContextTest {
     private void doReadyWithExpectedError(RuntimeException expError) {
         LocalThreePhaseCommitCohort mockCohort = mock(LocalThreePhaseCommitCohort.class);
         doReturn(akka.dispatch.Futures.successful(null)).when(mockCohort).initiateCoordinatedCommit();
-        doReturn(mockCohort).when(mockReadySupport).onTransactionReady(readWriteTransaction);
+        doReturn(mockCohort).when(mockReadySupport).onTransactionReady(readWriteTransaction, expError);
 
         localTransactionContext.readyTransaction();
-
-        verify(mockCohort).setOperationError(expError);
     }
 }