+ protected synchronized void onTransactionFailed(final SnapshotBackedWriteTransaction transaction,
+ final Throwable t) {
+ chainFailed = true;
+
+ }
+
+ public synchronized void onTransactionCommited(final SnapshotBackedWriteTransaction transaction) {
+ // If commited transaction is latestOutstandingTx we clear
+ // latestOutstandingTx
+ // field in order to base new transactions on Datastore Data Tree
+ // directly.
+ if (transaction.equals(latestOutstandingTx)) {
+ latestOutstandingTx = null;
+ }
+ }
+
+ }
+
+ private static class ChainedTransactionCommitImpl implements DOMStoreThreePhaseCommitCohort {
+
+ private final SnapshotBackedWriteTransaction transaction;
+ private final DOMStoreThreePhaseCommitCohort delegate;
+
+ private final DOMStoreTransactionChainImpl txChain;
+
+ protected ChainedTransactionCommitImpl(final SnapshotBackedWriteTransaction transaction,
+ final DOMStoreThreePhaseCommitCohort delegate, final DOMStoreTransactionChainImpl txChain) {
+ super();
+ this.transaction = transaction;
+ this.delegate = delegate;
+ this.txChain = txChain;
+ }
+
+ @Override
+ public ListenableFuture<Boolean> canCommit() {
+ return delegate.canCommit();
+ }
+
+ @Override
+ public ListenableFuture<Void> preCommit() {
+ return delegate.preCommit();
+ }
+
+ @Override
+ public ListenableFuture<Void> abort() {
+ return delegate.abort();
+ }
+
+ @Override
+ public ListenableFuture<Void> commit() {
+ ListenableFuture<Void> commitFuture = delegate.commit();
+ Futures.addCallback(commitFuture, new FutureCallback<Void>() {
+ @Override
+ public void onFailure(final Throwable t) {
+ txChain.onTransactionFailed(transaction, t);
+ }
+
+ @Override
+ public void onSuccess(final Void result) {
+ txChain.onTransactionCommited(transaction);
+ }
+
+ });
+ return commitFuture;
+ }
+