-final class ShardDataTreeCohort implements DOMStoreThreePhaseCommitCohort {
- private static final Logger LOG = LoggerFactory.getLogger(ShardDataTreeCohort.class);
- private static final ListenableFuture<Boolean> TRUE_FUTURE = Futures.immediateFuture(Boolean.TRUE);
- private static final ListenableFuture<Void> VOID_FUTURE = Futures.immediateFuture(null);
- private final DataTreeModification transaction;
- private final ShardDataTree dataTree;
- private DataTreeCandidateTip candidate;
-
- ShardDataTreeCohort(final ShardDataTree dataTree, final DataTreeModification transaction) {
- this.dataTree = Preconditions.checkNotNull(dataTree);
- this.transaction = Preconditions.checkNotNull(transaction);
- }
-
- @Override
- public ListenableFuture<Boolean> canCommit() {
- try {
- dataTree.getDataTree().validate(transaction);
- LOG.debug("Transaction {} validated", transaction);
- return TRUE_FUTURE;
- } catch (Exception e) {
- return Futures.immediateFailedFuture(e);
- }
- }
-
- @Override
- public ListenableFuture<Void> preCommit() {
- try {
- candidate = dataTree.getDataTree().prepare(transaction);
- /*
- * FIXME: this is the place where we should be interacting with persistence, specifically by invoking
- * persist on the candidate (which gives us a Future).
- */
- LOG.debug("Transaction {} prepared candidate {}", transaction, candidate);
- return VOID_FUTURE;
- } catch (Exception e) {
- LOG.debug("Transaction {} failed to prepare", transaction, e);
- return Futures.immediateFailedFuture(e);
- }
- }
-
- @Override
- public ListenableFuture<Void> abort() {
- // No-op, really
- return VOID_FUTURE;