Skip to content

Commit

Permalink
Merge pull request wildfly#34 from n1hility/disassociate
Browse files Browse the repository at this point in the history
WFTC-36 Add support for disassociating a remote transaction in limited single-use cases
  • Loading branch information
dmlloyd committed Sep 28, 2017
2 parents 9ba8b42 + 8b79544 commit 46f0635
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,28 @@ public void setLocation(URI location) throws IllegalArgumentException, IllegalSt
}
}

/**
* Attempt to clear the location set on this transaction, disassociating it
* with the remote transport provider. There is only a limited time window
* at which this can occur, before the transaction is ever used. Typically
* this is only useful for retrying an initial invocation on a transaction.
*
* @return whether the attempt was successful
*/
public boolean tryClearLocation() {
return stateRef.get().tryToDisassociate(stateRef);
}

abstract static class State {
State() {
}

abstract void join(AtomicReference<State> stateRef, URI location, SimpleTransactionControl control) throws IllegalStateException;

boolean tryToDisassociate(AtomicReference<State> stateRef) {
return false;
}

abstract void commit(AtomicReference<State> stateRef) throws RollbackException, HeuristicMixedException, HeuristicRollbackException, SecurityException, SystemException;

abstract void rollback(AtomicReference<State> stateRef) throws IllegalStateException, SystemException;
Expand Down Expand Up @@ -302,11 +318,16 @@ void setRollbackOnly(final AtomicReference<State> stateRef) throws IllegalStateE
int getStatus() {
return status;
}

boolean tryToDisassociate(AtomicReference<State> stateRef) {
return true;
}
}

abstract static class Located extends Unresolved {
final URI location;
final SimpleTransactionControl control;
volatile boolean multipleJoins = false;

Located(final URI location, final SimpleTransactionControl control) {
this.location = location;
Expand All @@ -317,6 +338,7 @@ void join(final AtomicReference<State> stateRef, final URI location, final Simpl
if (! this.location.equals(location)) {
throw Log.log.locationAlreadyInitialized(location, this.location);
}
multipleJoins = true;
}

void rollback(final AtomicReference<State> stateRef) throws IllegalStateException, SystemException {
Expand Down Expand Up @@ -385,6 +407,10 @@ void setRollbackOnly(final AtomicReference<State> stateRef) throws IllegalStateE
control.setRollbackOnly();
}
}

boolean tryToDisassociate(AtomicReference<State> stateRef) throws IllegalStateException {
return !multipleJoins && (stateRef.compareAndSet(this, Unlocated.ACTIVE) || stateRef.get().tryToDisassociate(stateRef));
}
}

static final class RollbackOnly extends Located {
Expand Down

0 comments on commit 46f0635

Please sign in to comment.