+public class TransactionChainProxy implements DOMStoreTransactionChain {
+
+ private interface State {
+ boolean isReady();
+
+ List<Future<ActorSelection>> getPreviousReadyFutures();
+ }
+
+ private static class Allocated implements State {
+ private final ChainedTransactionProxy transaction;
+
+ Allocated(ChainedTransactionProxy transaction) {
+ this.transaction = transaction;
+ }
+
+ @Override
+ public boolean isReady() {
+ return transaction.isReady();
+ }
+
+ @Override
+ public List<Future<ActorSelection>> getPreviousReadyFutures() {
+ return transaction.getReadyFutures();
+ }
+ }
+
+ private static abstract class AbstractDefaultState implements State {
+ @Override
+ public List<Future<ActorSelection>> getPreviousReadyFutures() {
+ return Collections.emptyList();
+ }
+ }
+
+ private static final State IDLE_STATE = new AbstractDefaultState() {
+ @Override
+ public boolean isReady() {
+ return true;
+ }
+ };
+
+ private static final State CLOSED_STATE = new AbstractDefaultState() {
+ @Override
+ public boolean isReady() {
+ throw new TransactionChainClosedException("Transaction chain has been closed");
+ }
+ };
+
+ private static final AtomicInteger counter = new AtomicInteger(0);
+
+ private final ActorContext actorContext;
+ private final String transactionChainId;
+ private volatile State currentState = IDLE_STATE;
+
+ public TransactionChainProxy(ActorContext actorContext) {
+ this.actorContext = actorContext;
+ transactionChainId = actorContext.getCurrentMemberName() + "-txn-chain-" + counter.incrementAndGet();
+ }
+
+ public String getTransactionChainId() {
+ return transactionChainId;
+ }
+