X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2FThreePhaseCommitCohortProxy.java;h=915b13dd8bc234a6cbf898658b8e6479333b36c2;hb=24c8edfec01c5a61bf40a930aec018502cd37275;hp=d12dc2b55a17f0ebaf1a3999778b109efbd60a0f;hpb=c3140359f8fc9759a309cb2d0476df5609952894;p=controller.git 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 d12dc2b55a..915b13dd8b 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,8 +31,6 @@ import org.slf4j.LoggerFactory; import java.util.Collections; import java.util.List; import java.util.concurrent.Callable; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; /** * ThreePhaseCommitCohortProxy represents a set of remote cohort proxies @@ -43,64 +43,65 @@ public class ThreePhaseCommitCohortProxy implements private final ActorContext actorContext; private final List cohortPaths; - //FIXME : Use a thread pool here - private final ExecutorService executorService = Executors.newSingleThreadExecutor(); + private final ListeningExecutorService executor; + private final String transactionId; - public ThreePhaseCommitCohortProxy(ActorContext actorContext, List cohortPaths) { + public ThreePhaseCommitCohortProxy(ActorContext actorContext, + List cohortPaths, + String transactionId, + ListeningExecutorService executor) { + this.actorContext = actorContext; this.cohortPaths = cohortPaths; + this.transactionId = transactionId; + this.executor = executor; } @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; + 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().toSerializable(), + ActorContext.ASK_DURATION); + + if (response.getClass().equals(CanCommitTransactionReply.SERIALIZABLE_CLASS)) { + CanCommitTransactionReply reply = + CanCommitTransactionReply.fromSerializable(response); + if (!reply.getCanCommit()) { + return false; + } } + } catch(RuntimeException e){ + 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); - - executorService.submit(future); - - return future; + return executor.submit(call); } @Override public ListenableFuture preCommit() { - return voidOperation(new PreCommitTransaction(), PreCommitTransactionReply.class); + return voidOperation(new PreCommitTransaction().toSerializable(), PreCommitTransactionReply.SERIALIZABLE_CLASS); } @Override public ListenableFuture abort() { - return voidOperation(new AbortTransaction(), AbortTransactionReply.class); + return voidOperation(new AbortTransaction().toSerializable(), AbortTransactionReply.SERIALIZABLE_CLASS); } @Override public ListenableFuture commit() { - return voidOperation(new CommitTransaction(), CommitTransactionReply.class); + return voidOperation(new CommitTransaction().toSerializable(), CommitTransactionReply.SERIALIZABLE_CLASS); } private ListenableFuture voidOperation(final Object message, final Class expectedResponseClass){ @@ -133,13 +134,7 @@ public class ThreePhaseCommitCohortProxy implements } }; - ListenableFutureTask - future = ListenableFutureTask.create(call); - - executorService.submit(future); - - return future; - + return executor.submit(call); } public List getCohortPaths() {