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%2FThreePhaseCommitCohortProxy.java;h=5b447943ea7fd798e5572e55483ff8b4fcf7e331;hp=279ecba40977e1293a9fbad090cd1a0dfddff2a4;hb=971b179000ef1cc56699de35061cf6f97d4cf36f;hpb=79202e1fd05d2606b35e163f608fad9cce84b5d4 diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ThreePhaseCommitCohortProxy.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ThreePhaseCommitCohortProxy.java index 279ecba409..5b447943ea 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ThreePhaseCommitCohortProxy.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ThreePhaseCommitCohortProxy.java @@ -10,8 +10,10 @@ package org.opendaylight.controller.cluster.datastore; import akka.actor.ActorPath; import akka.actor.ActorSelection; + import com.google.common.util.concurrent.ListenableFuture; -import com.google.common.util.concurrent.ListenableFutureTask; +import com.google.common.util.concurrent.ListeningExecutorService; + import org.opendaylight.controller.cluster.datastore.exceptions.TimeoutException; import org.opendaylight.controller.cluster.datastore.messages.AbortTransaction; import org.opendaylight.controller.cluster.datastore.messages.AbortTransactionReply; @@ -29,7 +31,6 @@ import org.slf4j.LoggerFactory; import java.util.Collections; import java.util.List; import java.util.concurrent.Callable; -import java.util.concurrent.ExecutorService; /** * ThreePhaseCommitCohortProxy represents a set of remote cohort proxies @@ -42,14 +43,14 @@ public class ThreePhaseCommitCohortProxy implements private final ActorContext actorContext; private final List cohortPaths; - private final ExecutorService executor; + private final ListeningExecutorService executor; private final String transactionId; public ThreePhaseCommitCohortProxy(ActorContext actorContext, List cohortPaths, String transactionId, - ExecutorService executor) { + ListeningExecutorService executor) { this.actorContext = actorContext; this.cohortPaths = cohortPaths; @@ -58,54 +59,58 @@ public class ThreePhaseCommitCohortProxy implements } @Override public ListenableFuture canCommit() { - Callable call = new Callable() { - - @Override public Boolean call() throws Exception { - for(ActorPath actorPath : cohortPaths){ - ActorSelection cohort = actorContext.actorSelection(actorPath); - - try { - Object response = - actorContext.executeRemoteOperation(cohort, - new CanCommitTransaction(), - ActorContext.ASK_DURATION); - - if (response instanceof CanCommitTransactionReply) { - CanCommitTransactionReply reply = - (CanCommitTransactionReply) response; - if (!reply.getCanCommit()) { - return false; + LOG.debug("txn {} canCommit", transactionId); + Callable call = new Callable() { + + @Override + public Boolean call() throws Exception { + for(ActorPath actorPath : cohortPaths){ + + Object message = new CanCommitTransaction().toSerializable(); + LOG.debug("txn {} Sending {} to {}", transactionId, message, actorPath); + + ActorSelection cohort = actorContext.actorSelection(actorPath); + + try { + Object response = + actorContext.executeRemoteOperation(cohort, + message, + ActorContext.ASK_DURATION); + + if (response.getClass().equals(CanCommitTransactionReply.SERIALIZABLE_CLASS)) { + CanCommitTransactionReply reply = + CanCommitTransactionReply.fromSerializable(response); + if (!reply.getCanCommit()) { + return false; + } } + } catch(RuntimeException e){ + // FIXME : Need to properly handle this + LOG.error("Unexpected Exception", e); + return false; } - } catch(RuntimeException e){ - LOG.error("Unexpected Exception", e); - return false; } - - } - return true; + return true; } }; - ListenableFutureTask - future = ListenableFutureTask.create(call); - - executor.submit(future); - - return future; + return executor.submit(call); } @Override public ListenableFuture preCommit() { - return voidOperation(new PreCommitTransaction(), PreCommitTransactionReply.class); + LOG.debug("txn {} preCommit", transactionId); + return voidOperation(new PreCommitTransaction().toSerializable(), PreCommitTransactionReply.SERIALIZABLE_CLASS); } @Override public ListenableFuture abort() { - return voidOperation(new AbortTransaction(), AbortTransactionReply.class); + LOG.debug("txn {} abort", transactionId); + return voidOperation(new AbortTransaction().toSerializable(), AbortTransactionReply.SERIALIZABLE_CLASS); } @Override public ListenableFuture commit() { - return voidOperation(new CommitTransaction(), CommitTransactionReply.class); + LOG.debug("txn {} commit", transactionId); + return voidOperation(new CommitTransaction().toSerializable(), CommitTransactionReply.SERIALIZABLE_CLASS); } private ListenableFuture voidOperation(final Object message, final Class expectedResponseClass){ @@ -115,6 +120,8 @@ public class ThreePhaseCommitCohortProxy implements for(ActorPath actorPath : cohortPaths){ ActorSelection cohort = actorContext.actorSelection(actorPath); + LOG.debug("txn {} Sending {} to {}", transactionId, message, actorPath); + try { Object response = actorContext.executeRemoteOperation(cohort, @@ -138,13 +145,7 @@ public class ThreePhaseCommitCohortProxy implements } }; - ListenableFutureTask - future = ListenableFutureTask.create(call); - - executor.submit(future); - - return future; - + return executor.submit(call); } public List getCohortPaths() {