import org.opendaylight.controller.cluster.datastore.messages.AbortTransaction;
import org.opendaylight.controller.cluster.datastore.messages.AbortTransactionReply;
import org.opendaylight.controller.cluster.datastore.messages.CanCommitTransaction;
import org.opendaylight.controller.cluster.datastore.messages.AbortTransaction;
import org.opendaylight.controller.cluster.datastore.messages.AbortTransactionReply;
import org.opendaylight.controller.cluster.datastore.messages.CanCommitTransaction;
private final ActorContext actorContext;
private final List<CohortInfo> cohorts;
private final SettableFuture<Void> cohortsResolvedFuture = SettableFuture.create();
private final ActorContext actorContext;
private final List<CohortInfo> cohorts;
private final SettableFuture<Void> cohortsResolvedFuture = SettableFuture.create();
- public ThreePhaseCommitCohortProxy(ActorContext actorContext, List<CohortInfo> cohorts, String transactionId) {
+ public ThreePhaseCommitCohortProxy(ActorContext actorContext, List<CohortInfo> cohorts,
+ TransactionIdentifier transactionId) {
info.getActorFuture().onComplete(new OnComplete<ActorSelection>() {
@Override
public void onComplete(Throwable failure, ActorSelection actor) {
info.getActorFuture().onComplete(new OnComplete<ActorSelection>() {
@Override
public void onComplete(Throwable failure, ActorSelection actor) {
LOG.debug("Tx {}: a cohort Future failed", transactionId, failure);
cohortsResolvedFuture.setException(failure);
LOG.debug("Tx {}: a cohort Future failed", transactionId, failure);
cohortsResolvedFuture.setException(failure);
LOG.debug("Tx {}: cohort actor {} resolved", transactionId, actor);
info.setResolvedActor(actor);
LOG.debug("Tx {}: cohort actor {} resolved", transactionId, actor);
info.setResolvedActor(actor);
LOG.debug("Tx {}: successfully resolved all cohort actors", transactionId);
cohortsResolvedFuture.set(null);
}
LOG.debug("Tx {}: successfully resolved all cohort actors", transactionId);
cohortsResolvedFuture.set(null);
}
LOG.debug("Tx {} finishCanCommit", transactionId);
// For empty transactions return immediately
LOG.debug("Tx {} finishCanCommit", transactionId);
// For empty transactions return immediately
LOG.debug("Tx {}: canCommit returning result true", transactionId);
returnFuture.set(Boolean.TRUE);
return;
LOG.debug("Tx {}: canCommit returning result true", transactionId);
returnFuture.set(Boolean.TRUE);
return;
sendCanCommitTransaction(iterator.next(), this);
} else {
LOG.debug("Tx {}: canCommit returning result: {}", transactionId, result);
sendCanCommitTransaction(iterator.next(), this);
} else {
LOG.debug("Tx {}: canCommit returning result: {}", transactionId, result);
private void sendCanCommitTransaction(CohortInfo toCohortInfo, OnComplete<Object> onComplete) {
CanCommitTransaction message = new CanCommitTransaction(transactionId, toCohortInfo.getActorVersion());
private void sendCanCommitTransaction(CohortInfo toCohortInfo, OnComplete<Object> onComplete) {
CanCommitTransaction message = new CanCommitTransaction(transactionId, toCohortInfo.getActorVersion());
- if(LOG.isDebugEnabled()) {
- LOG.debug("Tx {}: sending {} to {}", transactionId, message, toCohortInfo.getResolvedActor());
- }
+ LOG.debug("Tx {}: sending {} to {}", transactionId, message, toCohortInfo.getResolvedActor());
Future<Object> future = actorContext.executeOperationAsync(toCohortInfo.getResolvedActor(),
message.toSerializable(), actorContext.getTransactionCommitOperationTimeout());
Future<Object> future = actorContext.executeOperationAsync(toCohortInfo.getResolvedActor(),
message.toSerializable(), actorContext.getTransactionCommitOperationTimeout());
private Future<Iterable<Object>> invokeCohorts(MessageSupplier messageSupplier) {
List<Future<Object>> futureList = Lists.newArrayListWithCapacity(cohorts.size());
private Future<Iterable<Object>> invokeCohorts(MessageSupplier messageSupplier) {
List<Future<Object>> futureList = Lists.newArrayListWithCapacity(cohorts.size());
- if(LOG.isDebugEnabled()) {
- LOG.debug("Tx {}: Sending {} to cohort {}", transactionId, message , cohort);
- }
+ LOG.debug("Tx {}: Sending {} to cohort {}", transactionId, message , cohort);
futureList.add(actorContext.executeOperationAsync(cohort.getResolvedActor(), message,
actorContext.getTransactionCommitOperationTimeout()));
futureList.add(actorContext.executeOperationAsync(cohort.getResolvedActor(), message,
actorContext.getTransactionCommitOperationTimeout()));
// if not for some reason, we'll try to build it here.
ListenableFuture<Void> future = resolveCohorts();
// if not for some reason, we'll try to build it here.
ListenableFuture<Void> future = resolveCohorts();
finishVoidOperation(operationName, messageSupplier, expectedResponseClass, propagateException,
returnFuture, callback);
} else {
finishVoidOperation(operationName, messageSupplier, expectedResponseClass, propagateException,
returnFuture, callback);
} else {
public void onFailure(Throwable failure) {
LOG.debug("Tx {}: a {} cohort path Future failed: {}", transactionId, operationName, failure);
public void onFailure(Throwable failure) {
LOG.debug("Tx {}: a {} cohort path Future failed: {}", transactionId, operationName, failure);
@Override
public void onComplete(Throwable failure, Iterable<Object> responses) throws Throwable {
Throwable exceptionToPropagate = failure;
@Override
public void onComplete(Throwable failure, Iterable<Object> responses) throws Throwable {
Throwable exceptionToPropagate = failure;
- if(exceptionToPropagate == null) {
- for(Object response: responses) {
- if(!response.getClass().equals(expectedResponseClass)) {
+ if (exceptionToPropagate == null) {
+ for (Object response: responses) {
+ if (!response.getClass().equals(expectedResponseClass)) {
exceptionToPropagate = new IllegalArgumentException(
String.format("Unexpected response type %s", response.getClass()));
break;
exceptionToPropagate = new IllegalArgumentException(
String.format("Unexpected response type %s", response.getClass()));
break;
LOG.debug("Tx {}: a {} cohort Future failed", transactionId, operationName, exceptionToPropagate);
LOG.debug("Tx {}: a {} cohort Future failed", transactionId, operationName, exceptionToPropagate);
// We don't log the exception here to avoid redundant logging since we're
// propagating to the caller in MD-SAL core who will log it.
returnFuture.setException(exceptionToPropagate);
// We don't log the exception here to avoid redundant logging since we're
// propagating to the caller in MD-SAL core who will log it.
returnFuture.setException(exceptionToPropagate);
@Override
List<Future<ActorSelection>> getCohortFutures() {
List<Future<ActorSelection>> cohortFutures = new ArrayList<>(cohorts.size());
@Override
List<Future<ActorSelection>> getCohortFutures() {
List<Future<ActorSelection>> cohortFutures = new ArrayList<>(cohorts.size());