Add MappingCheckedFuture
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / LocalThreePhaseCommitCohort.java
index 23207f01ceeea9bb9890b47a848c0bb2c2a2ba83..2087da07596cb90f20637bfe1d14f3dc414efd2f 100644 (file)
@@ -12,6 +12,8 @@ import akka.dispatch.Futures;
 import akka.dispatch.OnComplete;
 import com.google.common.base.Preconditions;
 import com.google.common.util.concurrent.ListenableFuture;
+import java.util.Optional;
+import java.util.SortedSet;
 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
 import org.opendaylight.controller.cluster.datastore.messages.CommitTransactionReply;
 import org.opendaylight.controller.cluster.datastore.messages.ReadyLocalTransaction;
@@ -59,25 +61,26 @@ class LocalThreePhaseCommitCohort implements DOMStoreThreePhaseCommitCohort {
         this.modification = null;
     }
 
-    private Future<Object> initiateCommit(final boolean immediate) {
+    private Future<Object> initiateCommit(final boolean immediate,
+            final Optional<SortedSet<String>> participatingShardNames) {
         if (operationError != null) {
             return Futures.failed(operationError);
         }
 
         final ReadyLocalTransaction message = new ReadyLocalTransaction(transaction.getIdentifier(),
-                modification, immediate);
+                modification, immediate, participatingShardNames);
         return actorContext.executeOperationAsync(leader, message, actorContext.getTransactionCommitOperationTimeout());
     }
 
-    Future<ActorSelection> initiateCoordinatedCommit() {
-        final Future<Object> messageFuture = initiateCommit(false);
+    Future<ActorSelection> initiateCoordinatedCommit(Optional<SortedSet<String>> participatingShardNames) {
+        final Future<Object> messageFuture = initiateCommit(false, participatingShardNames);
         final Future<ActorSelection> ret = TransactionReadyReplyMapper.transform(messageFuture, actorContext,
                 transaction.getIdentifier());
         ret.onComplete(new OnComplete<ActorSelection>() {
             @Override
-            public void onComplete(final Throwable failure, final ActorSelection success) throws Throwable {
+            public void onComplete(final Throwable failure, final ActorSelection success) {
                 if (failure != null) {
-                    LOG.info("Failed to prepare transaction {} on backend", transaction.getIdentifier(), failure);
+                    LOG.warn("Failed to prepare transaction {} on backend", transaction.getIdentifier(), failure);
                     transactionAborted(transaction);
                     return;
                 }
@@ -90,12 +93,12 @@ class LocalThreePhaseCommitCohort implements DOMStoreThreePhaseCommitCohort {
     }
 
     Future<Object> initiateDirectCommit() {
-        final Future<Object> messageFuture = initiateCommit(true);
+        final Future<Object> messageFuture = initiateCommit(true, Optional.empty());
         messageFuture.onComplete(new OnComplete<Object>() {
             @Override
-            public void onComplete(final Throwable failure, final Object message) throws Throwable {
+            public void onComplete(final Throwable failure, final Object message) {
                 if (failure != null) {
-                    LOG.error("Failed to prepare transaction {} on backend", transaction.getIdentifier(), failure);
+                    LOG.warn("Failed to prepare transaction {} on backend", transaction.getIdentifier(), failure);
                     transactionAborted(transaction);
                 } else if (CommitTransactionReply.isSerializedType(message)) {
                     LOG.debug("Transaction {} committed successfully", transaction.getIdentifier());