use of com.arjuna.wst.WrongStateException in project wildfly by wildfly.
the class ATSuperService method invokeWithCallName.
/**
* Adding 2 participants - Volatile and Durable
*
* @param callName call name works for differentiate several calls to the same webservice
* if you don't want care pass null (or overloaded method :)
* @param serviceCommands service commands that service will react on
* @throws WrongStateException
* @throws com.arjuna.wst.SystemException
* @throws UnknownTransactionException
* @throws SecurityException
* @throws javax.transaction.SystemException
* @throws IllegalStateException
*/
public void invokeWithCallName(String callName, ServiceCommand[] serviceCommands) throws TestApplicationException {
log.infof("[AT SERVICE] web method invoke(%s) with eventLog %s", callName, eventLog);
eventLog.foundEventLogName(callName);
UserTransaction userTransaction;
try {
userTransaction = UserTransactionFactory.userTransaction();
String transactionId = userTransaction.transactionIdentifier();
log.debug("RestaurantServiceAT transaction id =" + transactionId);
// Enlist the Durable Participant for this service
TransactionManager transactionManager = TransactionManagerFactory.transactionManager();
ATDurableParticipant durableParticipant = new ATDurableParticipant(serviceCommands, callName, eventLog, transactionId);
log.trace("[SERVICE] Enlisting a Durable2PC participant into the AT");
transactionManager.enlistForDurableTwoPhase(durableParticipant, "ATServiceDurable:" + new Uid().toString());
// Enlist the Volatile Participant for this service
ATVolatileParticipant volatileParticipant = new ATVolatileParticipant(serviceCommands, callName, eventLog, transactionId);
log.trace("[SERVICE] Enlisting a VolatilePC participant into the AT");
transactionManager.enlistForVolatileTwoPhase(volatileParticipant, "ATServiceVolatile:" + new Uid().toString());
} catch (Exception e) {
throw new RuntimeException("Error when enlisting participants", e);
}
if (ServiceCommand.isPresent(APPLICATION_EXCEPTION, serviceCommands)) {
throw new TestApplicationException("Intentionally thrown Application Exception - service command was set to: " + APPLICATION_EXCEPTION);
}
if (ServiceCommand.isPresent(ROLLBACK_ONLY, serviceCommands)) {
log.trace("Intentionally the service settings transaction to rollback only - service command was set to: " + ROLLBACK_ONLY);
try {
userTransaction.rollback();
} catch (Exception e) {
throw new RuntimeException("The rollback is not possible", e);
}
}
// There will be some business logic here normally
log.trace("|AT SERVICE] I'm working on nothing...");
}
use of com.arjuna.wst.WrongStateException in project narayana by jbosstm.
the class UserBusinessActivityStandaloneImple method complete.
public void complete() throws UnknownTransactionException, SystemException, WrongStateException {
try {
final TxContextImple ctx = ((TxContextImple) _ctxManager.currentTransaction());
if (ctx == null) {
throw new WrongStateException();
}
final String id = ctx.identifier();
final W3CEndpointReference terminatorCoordinatorRPC = getTerminationCoordinatorRPC(ctx);
BusinessActivityTerminatorRPCStub terminatorRPCStub = new BusinessActivityTerminatorRPCStub(id, terminatorCoordinatorRPC);
terminatorRPCStub.complete();
} catch (SystemException ex) {
throw ex;
} catch (UnknownTransactionException ex) {
throw ex;
} catch (WrongStateException ex) {
throw ex;
} catch (Exception ex) {
throw new SystemException(ex.toString());
}
}
use of com.arjuna.wst.WrongStateException in project narayana by jbosstm.
the class UserBusinessActivityStandaloneImple method begin.
public void begin(int timeout) throws WrongStateException, SystemException {
try {
if (_ctxManager.currentTransaction() != null)
throw new WrongStateException();
Context ctx = startTransaction(timeout, null);
_ctxManager.resume(new TxContextImple(ctx));
} catch (InvalidCreateParametersException ex) {
tidyup();
throw new SystemException(ex.toString());
} catch (UnknownTransactionException ex) {
tidyup();
throw new SystemException(ex.toString());
} catch (SystemException ex) {
tidyup();
throw ex;
}
}
use of com.arjuna.wst.WrongStateException in project narayana by jbosstm.
the class UserTransactionImple method beginSubordinate.
/**
* method provided for the benefit of UserSubordinateTransactionImple to allow it
* to begin a subordinate transaction which requires an existing context to be
* installed on the thread before it will start and instal la new transaction
*
* @param timeout
* @throws WrongStateException
* @throws SystemException
*/
public void beginSubordinate(int timeout) throws WrongStateException, SystemException {
try {
TxContext current = _ctxManager.currentTransaction();
if ((current == null) || !(current instanceof TxContextImple))
throw new WrongStateException();
TxContextImple currentImple = (TxContextImple) current;
Context ctx = startTransaction(timeout, currentImple);
_ctxManager.resume(new TxContextImple(ctx));
// n.b. we don't enlist the subordinate transaction for completion
// that ensures that any attempt to commit or rollback will fail
} catch (com.arjuna.wsc.InvalidCreateParametersException ex) {
tidyup();
throw new SystemException(ex.toString());
} catch (com.arjuna.wst.UnknownTransactionException ex) {
tidyup();
throw new SystemException(ex.toString());
} catch (SystemException ex) {
tidyup();
throw ex;
}
}
use of com.arjuna.wst.WrongStateException in project narayana by jbosstm.
the class UserTransactionImple method commitWithoutAck.
private final void commitWithoutAck() throws TransactionRolledBackException, 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.
*/
final W3CEndpointReference completionCoordinator = (W3CEndpointReference) _completionCoordinators.get(id);
if (completionCoordinator == null)
throw new WrongStateException();
CompletionStub completionStub = new CompletionStub(id, completionCoordinator);
completionStub.commit();
} catch (SystemException ex) {
throw ex;
} catch (TransactionRolledBackException ex) {
throw ex;
} catch (UnknownTransactionException ex) {
throw ex;
} catch (SecurityException ex) {
throw ex;
} catch (WrongStateException ex) {
throw ex;
} catch (Exception ex) {
ex.printStackTrace();
throw new SystemException(ex.toString());
} finally {
try {
if (ctx != null)
_ctxManager.resume(ctx);
} catch (Exception ex) {
ex.printStackTrace();
}
if (id != null)
_completionCoordinators.remove(id);
}
}
Aggregations