use of com.arjuna.mwlabs.wst11.at.context.TxContextImple in project narayana by jbosstm.
the class TransactionManagerImple method registerParticipant.
final W3CEndpointReference registerParticipant(final W3CEndpointReference participant, final String protocol) throws InvalidProtocolException, InvalidStateException, CannotRegisterException, SystemException {
TxContextImple currentTx = null;
try {
currentTx = (TxContextImple) _ctxManager.suspend();
if (currentTx == null)
throw new CannotRegisterException();
final CoordinationContextType coordinationContext = currentTx.context().getCoordinationContext();
final String messageId = MessageId.getMessageId();
return com.arjuna.wsc11.RegistrationCoordinator.register(coordinationContext, messageId, participant, protocol);
} catch (final SoapFault sf) {
throw new SystemException(sf.getMessage());
} catch (final CannotRegisterException cre) {
throw cre;
} catch (final InvalidStateException ise) {
throw ise;
} catch (final InvalidProtocolException ipe) {
throw ipe;
} catch (final Exception ex) {
throw new SystemException(ex.toString());
} finally {
try {
if (currentTx != null)
_ctxManager.resume(currentTx);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
use of com.arjuna.mwlabs.wst11.at.context.TxContextImple in project narayana by jbosstm.
the class UserTransactionImple method startTransaction.
protected final Context startTransaction(int timeout, TxContextImple current) throws com.arjuna.wsc.InvalidCreateParametersException, SystemException {
try {
// TODO: tricks for per app _activationCoordinatorService config, perhaps:
// InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("/foo.properties");
final Long expires = (timeout > 0 ? new Long(timeout) : null);
final String messageId = MessageId.getMessageId();
final CoordinationContext currentContext = (current != null ? getContext(current) : null);
final CoordinationContextType coordinationContext = ActivationCoordinator.createCoordinationContext(_activationCoordinatorService, messageId, AtomicTransactionConstants.WSAT_PROTOCOL, expires, currentContext);
if (coordinationContext == null) {
throw new SystemException(wstxLogger.i18NLogger.get_mwlabs_wst_at_remote_UserTransaction11Imple__2());
}
return new ContextImple(coordinationContext);
} catch (final InvalidCreateParametersException icpe) {
throw icpe;
} catch (final SoapFault sf) {
throw new SystemException(sf.getMessage());
} catch (final Exception ex) {
throw new SystemException(ex.toString());
}
}
use of com.arjuna.mwlabs.wst11.at.context.TxContextImple in project narayana by jbosstm.
the class UserTransactionImple method abortWithoutAck.
private final void abortWithoutAck() throws UnknownTransactionException, SecurityException, SystemException, WrongStateException {
TxContextImple ctx = null;
String id = null;
try {
ctx = (TxContextImple) _ctxManager.suspend();
if (ctx == null) {
throw new WrongStateException();
}
id = ctx.identifier();
/*
* By default the completionParticipantURL won't be set for an interposed (imported)
* bridged transaction. This is fine, because you shouldn't be able to commit that
* transaction from a node in the tree, only from the root. So, we can prevent commit
* or rollback at this stage. The alternative would be to setup the completionParticipantURL
* and throw the exception from the remote coordinator side (see enlistCompletionParticipants
* for how to do this).
*
* The same applies for an interposed subordinate transaction created via beginSubordinate.
*/
W3CEndpointReference completionCoordinator = (W3CEndpointReference) _completionCoordinators.get(id);
if (completionCoordinator == null)
throw new WrongStateException();
CompletionStub completionStub = new CompletionStub(id, completionCoordinator);
completionStub.rollback();
} catch (SystemException ex) {
throw ex;
} catch (UnknownTransactionException ex) {
throw ex;
} catch (SecurityException ex) {
throw ex;
} catch (WrongStateException ex) {
throw ex;
} catch (Exception ex) {
throw new SystemException(ex.toString());
} finally {
try {
if (ctx != null)
_ctxManager.resume(ctx);
} catch (Exception ex) {
ex.printStackTrace();
}
if (id != null)
_completionCoordinators.remove(id);
}
}
use of com.arjuna.mwlabs.wst11.at.context.TxContextImple in project narayana by jbosstm.
the class UserTransactionImple method enlistCompletionParticipants.
/*
* Not sure if this is right as it doesn't map to registering a participant
* with the coordinator.
*/
private final void enlistCompletionParticipants() throws WrongStateException, UnknownTransactionException, SystemException {
TransactionManagerImple tm = (TransactionManagerImple) TransactionManager.getTransactionManager();
final TxContextImple currentTx = (TxContextImple) tm.currentTransaction();
if (currentTx == null)
throw new UnknownTransactionException();
final String id = currentTx.identifier();
final W3CEndpointReference completionParticipant = getCompletionParticipant(id, currentTx.isSecure());
W3CEndpointReference completionCoordinator = null;
try {
completionCoordinator = tm.registerParticipant(completionParticipant, AtomicTransactionConstants.WSAT_SUB_PROTOCOL_COMPLETION);
} catch (com.arjuna.wsc.InvalidProtocolException ex) {
ex.printStackTrace();
throw new SystemException(ex.toString());
} catch (com.arjuna.wsc.InvalidStateException ex) {
throw new WrongStateException();
} catch (com.arjuna.wsc.CannotRegisterException ex) {
// cause could actually be no activity or already registered
throw new UnknownTransactionException();
}
_completionCoordinators.put(id, completionCoordinator);
}
use of com.arjuna.mwlabs.wst11.at.context.TxContextImple in project narayana by jbosstm.
the class SubordinateImporter method importContext.
public static TxContext importContext(CoordinationContextType cc) {
// get the subordinate transaction manager to install any existing
// subordinate tx for this one or create and install a new one.
final String identifier = cc.getIdentifier().getValue();
TxContext subordinateTxContext = subordinateContextMap.get(identifier);
if (subordinateTxContext == null) {
// create a context for a local coordinator
CoordinationContext context = null;
try {
context = baContextFactory.create(BusinessActivityConstants.WSBA_PROTOCOL_ATOMIC_OUTCOME, 0L, cc, false);
} catch (InvalidCreateParametersException e) {
// should not happen
}
subordinateTxContext = new TxContextImple(context);
subordinateContextMap.put(identifier, subordinateTxContext);
// register a cleanup callback with the subordinate transactionso that the entry gets removed
// when the transcation commits or rolls back
// remove "urn:" prefix
String subordinateId = context.getIdentifier().getValue().substring(4);
SubordinateBACoordinator.SubordinateCallback callback = new SubordinateBACoordinator.SubordinateCallback() {
public String parentId = identifier;
public void run() {
subordinateContextMap.remove(parentId);
}
};
SubordinateBACoordinator.addCallback(subordinateId, callback);
}
return subordinateTxContext;
}
Aggregations