+ } else {
+ return future;
+ }
+ }
+
+ @Override
+ protected <T> void onTransactionReady(final TransactionIdentifier transaction,
+ final Collection<Future<T>> cohortFutures) {
+ final State localState = currentState;
+ checkState(localState instanceof Allocated, "Readying transaction %s while state is %s", transaction,
+ localState);
+ final TransactionIdentifier currentTx = ((Allocated)localState).getIdentifier();
+ checkState(transaction.equals(currentTx), "Readying transaction %s while %s is allocated", transaction,
+ currentTx);
+
+ // Transaction ready and we are not waiting for futures -- go to idle
+ if (cohortFutures.isEmpty()) {
+ currentState = IDLE_STATE;
+ return;
+ }
+
+ // Combine the ready Futures into 1
+ final Future<Iterable<T>> combined = Futures.sequence(cohortFutures, getActorUtils().getClientDispatcher());
+
+ // Record the we have outstanding futures
+ final State newState = new Submitted(transaction, combined);
+ currentState = newState;
+
+ // Attach a completion reset, but only if we do not allocate a transaction
+ // in-between
+ combined.onComplete(new OnComplete<Iterable<T>>() {
+ @Override
+ public void onComplete(final Throwable arg0, final Iterable<T> arg1) {
+ STATE_UPDATER.compareAndSet(TransactionChainProxy.this, newState, IDLE_STATE);
+ }
+ }, getActorUtils().getClientDispatcher());
+ }
+
+ @Override
+ protected void onTransactionContextCreated(final TransactionIdentifier transactionId) {
+ Promise<Object> promise = priorReadOnlyTxPromises.remove(transactionId);
+ if (promise != null) {
+ promise.success(null);