Search in sources :

Example 1 with ResourceManagerException

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;
}
Also used : XAException(javax.transaction.xa.XAException) ResourceManagerException(org.mule.runtime.core.api.transaction.xa.ResourceManagerException)

Example 2 with ResourceManagerException

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);
}
Also used : XAException(javax.transaction.xa.XAException) ResourceManagerException(org.mule.runtime.core.api.transaction.xa.ResourceManagerException)

Example 3 with ResourceManagerException

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());
}
Also used : Serializable(java.io.Serializable) DefaultQueueConfiguration(org.mule.runtime.core.api.util.queue.DefaultQueueConfiguration) LocalTxQueueTransactionRecoverer(org.mule.runtime.core.internal.util.journal.queue.LocalTxQueueTransactionRecoverer) ResourceManagerException(org.mule.runtime.core.api.transaction.xa.ResourceManagerException) Test(org.junit.Test)

Example 4 with ResourceManagerException

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);
    }
}
Also used : XAException(javax.transaction.xa.XAException) PersistentXaTransactionContext(org.mule.runtime.core.internal.util.queue.PersistentXaTransactionContext) ResourceManagerException(org.mule.runtime.core.api.transaction.xa.ResourceManagerException)

Example 5 with ResourceManagerException

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);
    }
}
Also used : XAException(javax.transaction.xa.XAException) PersistentXaTransactionContext(org.mule.runtime.core.internal.util.queue.PersistentXaTransactionContext) ResourceManagerException(org.mule.runtime.core.api.transaction.xa.ResourceManagerException)

Aggregations

ResourceManagerException (org.mule.runtime.core.api.transaction.xa.ResourceManagerException)11 XAException (javax.transaction.xa.XAException)5 Serializable (java.io.Serializable)2 LocalQueueTxJournalEntry (org.mule.runtime.core.internal.util.journal.queue.LocalQueueTxJournalEntry)2 XaQueueTxJournalEntry (org.mule.runtime.core.internal.util.journal.queue.XaQueueTxJournalEntry)2 PersistentXaTransactionContext (org.mule.runtime.core.internal.util.queue.PersistentXaTransactionContext)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Test (org.junit.Test)1 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)1 DefaultQueueConfiguration (org.mule.runtime.core.api.util.queue.DefaultQueueConfiguration)1 LocalTxQueueTransactionRecoverer (org.mule.runtime.core.internal.util.journal.queue.LocalTxQueueTransactionRecoverer)1