X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2FLocalTransactionChain.java;h=de98dce5620ba84434cf3d7e679a29fde9d05bca;hp=39d0133d02f5f71eab1d509079f7fd0c688ba903;hb=95c296a7c1e8e186a88a0a0dc82e080b2185db33;hpb=d3a97264ecf47e8c60ea11a7caebce41b580e91d diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/LocalTransactionChain.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/LocalTransactionChain.java index 39d0133d02..de98dce562 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/LocalTransactionChain.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/LocalTransactionChain.java @@ -9,7 +9,9 @@ package org.opendaylight.controller.cluster.datastore; import akka.actor.ActorSelection; import com.google.common.base.Preconditions; -import org.opendaylight.controller.cluster.datastore.identifiers.TransactionIdentifier; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; import org.opendaylight.controller.sal.core.spi.data.AbstractSnapshotBackedTransactionChain; import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadTransaction; import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction; @@ -57,18 +59,10 @@ final class LocalTransactionChain extends AbstractSnapshotBackedTransactionChain } @Override - protected DOMStoreThreePhaseCommitCohort createCohort(final SnapshotBackedWriteTransaction transaction, final DataTreeModification modification) { - return new LocalThreePhaseCommitCohort(parent.getActorContext(), leader, transaction, modification) { - @Override - protected void transactionAborted(final SnapshotBackedWriteTransaction transaction) { - onTransactionFailed(transaction, ABORTED); - } - - @Override - protected void transactionCommitted(final SnapshotBackedWriteTransaction transaction) { - onTransactionCommited(transaction); - } - }; + protected DOMStoreThreePhaseCommitCohort createCohort( + final SnapshotBackedWriteTransaction transaction, + final DataTreeModification modification) { + return new LocalChainThreePhaseCommitCohort(transaction, modification); } @Override @@ -85,4 +79,46 @@ final class LocalTransactionChain extends AbstractSnapshotBackedTransactionChain public DOMStoreWriteTransaction newWriteOnlyTransaction(TransactionIdentifier identifier) { return super.newWriteOnlyTransaction(identifier); } + + @SuppressWarnings({"unchecked", "checkstyle:IllegalCatch"}) + @Override + public LocalThreePhaseCommitCohort onTransactionReady(@Nonnull DOMStoreWriteTransaction tx, + @Nullable Exception operationError) { + Preconditions.checkArgument(tx instanceof SnapshotBackedWriteTransaction); + if (operationError != null) { + return new LocalChainThreePhaseCommitCohort((SnapshotBackedWriteTransaction)tx, + operationError); + } + + try { + return (LocalThreePhaseCommitCohort) tx.ready(); + } catch (Exception e) { + // Unfortunately we need to cast to SnapshotBackedWriteTransaction here as it's required by + // LocalThreePhaseCommitCohort and the base class. + return new LocalChainThreePhaseCommitCohort((SnapshotBackedWriteTransaction)tx, e); + } + } + + private class LocalChainThreePhaseCommitCohort extends LocalThreePhaseCommitCohort { + + protected LocalChainThreePhaseCommitCohort(SnapshotBackedWriteTransaction transaction, + DataTreeModification modification) { + super(parent.getActorContext(), leader, transaction, modification); + } + + protected LocalChainThreePhaseCommitCohort(SnapshotBackedWriteTransaction transaction, + Exception operationError) { + super(parent.getActorContext(), leader, transaction, operationError); + } + + @Override + protected void transactionAborted(SnapshotBackedWriteTransaction transaction) { + onTransactionFailed(transaction, ABORTED); + } + + @Override + protected void transactionCommitted(SnapshotBackedWriteTransaction transaction) { + onTransactionCommited(transaction); + } + } }