package org.opendaylight.mdsal.dom.store.inmemory;
+import com.google.common.annotations.Beta;
+import com.google.common.base.Preconditions;
import com.google.common.util.concurrent.ListenableFuture;
import java.util.Collection;
import java.util.concurrent.Callable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-class ShardCommitCoordinationTask implements Callable<Void> {
+/**
+ * Task that coordinates the Commit phase of the provided {@link DOMStoreThreePhaseCommitCohort}'s.
+ */
+@Beta
+public class ShardCommitCoordinationTask implements Callable<Void> {
private static final Logger LOG = LoggerFactory.getLogger(ShardCommitCoordinationTask.class);
private final DOMDataTreeIdentifier rootShardPrefix;
private final Collection<DOMStoreThreePhaseCommitCohort> cohorts;
+ private InmemoryDOMDataTreeShardWriteTransaction transaction;
- ShardCommitCoordinationTask(final DOMDataTreeIdentifier rootShardPrefix,
- final Collection<DOMStoreThreePhaseCommitCohort> cohorts) {
- this.rootShardPrefix = rootShardPrefix;
- this.cohorts = cohorts;
+ public ShardCommitCoordinationTask(final DOMDataTreeIdentifier rootShardPrefix,
+ final Collection<DOMStoreThreePhaseCommitCohort> cohorts,
+ final InmemoryDOMDataTreeShardWriteTransaction transaction) {
+ this.rootShardPrefix = Preconditions.checkNotNull(rootShardPrefix);
+ this.cohorts = Preconditions.checkNotNull(cohorts);
+ this.transaction = Preconditions.checkNotNull(transaction);
}
@Override
try {
LOG.debug("Shard {}, commit started", rootShardPrefix);
commitBlocking();
+ transaction.transactionCommited(transaction);
return null;
- } catch (TransactionCommitFailedException e) {
+ } catch (final TransactionCommitFailedException e) {
LOG.warn("Shard: {} Submit Error during phase Commit, starting Abort", rootShardPrefix, e);
//FIXME abort here
throw e;
private ListenableFuture<?>[] commitAll() {
final ListenableFuture<?>[] ops = new ListenableFuture<?>[cohorts.size()];
- int i = 0;
+ int index = 0;
for (final DOMStoreThreePhaseCommitCohort cohort : cohorts) {
- ops[i++] = cohort.commit();
+ ops[index++] = cohort.commit();
}
return ops;
}