use of org.mule.runtime.core.api.transaction.xa.ResourceManagerException in project mule by mulesoft.
the class DefaultXASession method end.
public void end(Xid xid, int flags) throws XAException {
if (logger.isDebugEnabled()) {
logger.debug(new StringBuilder(128).append("Thread ").append(Thread.currentThread()).append(flags == TMSUSPEND ? " suspends" : flags == TMFAIL ? " fails" : " ends").append(" work on behalf of transaction branch ").append(xid).toString());
}
// No transaction is already begun
if (localContext == null) {
throw new XAException(XAException.XAER_NOTA);
}
// This session has already been associated with an xid
if (localXid == null || !localXid.equals(xid)) {
throw new XAException(XAException.XAER_PROTO);
}
try {
switch(flags) {
case TMSUSPEND:
// TODO: suspend context
resourceManager.addSuspendedTransactionalResource(localXid, localContext);
resourceManager.removeActiveTransactionalResource(localXid);
break;
case TMFAIL:
resourceManager.setTransactionRollbackOnly(localContext);
break;
// no-op
case TMSUCCESS:
default:
// no-op
break;
}
} catch (ResourceManagerException e) {
throw (XAException) new XAException(XAException.XAER_RMERR).initCause(e);
}
localXid = null;
localContext = null;
}
use of org.mule.runtime.core.api.transaction.xa.ResourceManagerException in project mule by mulesoft.
the class DefaultXASession method rollback.
public void rollback(Xid xid) throws XAException {
if (xid == null) {
throw new XAException(XAException.XAER_PROTO);
}
AbstractTransactionContext context = resourceManager.getActiveTransactionalResource(xid);
if (context == null) {
if (logger.isDebugEnabled()) {
logger.debug("Rollback called without a transaction context");
}
rollbackDandlingTransaction(xid);
return;
}
if (logger.isDebugEnabled()) {
logger.debug("Rolling back transaction branch " + xid);
}
try {
resourceManager.rollbackTransaction(context);
localContext = null;
} catch (ResourceManagerException e) {
throw (XAException) new XAException(XAException.XAER_RMERR).initCause(e);
}
resourceManager.removeActiveTransactionalResource(xid);
resourceManager.removeSuspendedTransactionalResource(xid);
}
use of org.mule.runtime.core.api.transaction.xa.ResourceManagerException in project mule by mulesoft.
the class LocalTxQueueTransactionRecovererTestCase method offerAndFailBetweenRealOfferAndCommitThenRecover.
@Test
public void offerAndFailBetweenRealOfferAndCommitThenRecover() throws Exception {
txLog = new TestTransactionLogger(temporaryFolder.getRoot().getAbsolutePath(), muleContext).failDuringLogCommit();
final DefaultQueueStore outQueue = new DefaultQueueStore(QUEUE_NAME, muleContext, new DefaultQueueConfiguration(0, true));
persistentTransactionContext = new PersistentQueueTransactionContext(txLog, createQueueProvider(outQueue));
persistentTransactionContext.offer(outQueue, testEvent(), TIMEOUT);
try {
persistentTransactionContext.doCommit();
fail();
} catch (ResourceManagerException e) {
// expected
}
txLog.close();
txLog = new TestTransactionLogger(temporaryFolder.getRoot().getAbsolutePath(), muleContext);
queueTransactionRecoverer = new LocalTxQueueTransactionRecoverer(txLog, createQueueProvider(outQueue));
queueTransactionRecoverer.recover();
Serializable muleEvent = outQueue.poll(TIMEOUT);
assertThat(muleEvent, nullValue());
}
use of org.mule.runtime.core.api.transaction.xa.ResourceManagerException in project mule by mulesoft.
the class XaTransactionRecoverer method commitDandlingTransaction.
public void commitDandlingTransaction(Xid xid, boolean onePhase) throws XAException {
try {
logger.info("Commiting dangling tx with id " + xid);
new PersistentXaTransactionContext(xaTxQueueTransactionJournal, queueProvider, xid).doCommit();
} catch (ResourceManagerException e) {
logger.warn(e.getMessage());
if (logger.isDebugEnabled()) {
logger.debug("Error committing dangling transaction", e);
}
throw new XAException(XAException.XAER_NOTA);
}
}
use of org.mule.runtime.core.api.transaction.xa.ResourceManagerException in project mule by mulesoft.
the class XaTransactionRecoverer method rollbackDandlingTransaction.
public void rollbackDandlingTransaction(Xid xid) throws XAException {
try {
logger.info("Rollbacking dangling tx with id " + xid);
new PersistentXaTransactionContext(xaTxQueueTransactionJournal, queueProvider, xid).doRollback();
} catch (ResourceManagerException e) {
logger.warn(e.getMessage());
if (logger.isDebugEnabled()) {
logger.debug("Error rollbacking dangling transaction", e);
}
throw new XAException(XAException.XAER_NOTA);
}
}
Aggregations