Search in sources :

Example 1 with XaQueueTxJournalEntry

use of org.mule.runtime.core.internal.util.journal.queue.XaQueueTxJournalEntry in project mule by mulesoft.

the class PersistentXaTransactionContext method size.

public int size(QueueStore queue) {
    final AtomicInteger addSize = new AtomicInteger(0);
    CollectionUtils.forAllDo(this.transactionJournal.getLogEntriesForTx(xid), new Closure() {

        @Override
        public void execute(Object value) {
            if (((XaQueueTxJournalEntry) value).isAdd() || ((XaQueueTxJournalEntry) value).isAddFirst()) {
                addSize.incrementAndGet();
            }
        }
    });
    return queue.getSize() + addSize.get();
}
Also used : Closure(org.apache.commons.collections.Closure) XaQueueTxJournalEntry(org.mule.runtime.core.internal.util.journal.queue.XaQueueTxJournalEntry) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 2 with XaQueueTxJournalEntry

use of org.mule.runtime.core.internal.util.journal.queue.XaQueueTxJournalEntry in project mule by mulesoft.

the class PersistentXaTransactionContext method doCommit.

@Override
public void doCommit() throws ResourceManagerException {
    try {
        Collection<XaQueueTxJournalEntry> logEntries = this.transactionJournal.getLogEntriesForTx(xid);
        for (XaQueueTxJournalEntry entry : logEntries) {
            if (entry.isAdd()) {
                queueProvider.getQueue(entry.getQueueName()).putNow(entry.getValue());
            } else if (entry.isAddFirst()) {
                queueProvider.getQueue(entry.getQueueName()).untake(entry.getValue());
            }
        }
        this.transactionJournal.logCommit(xid);
    } catch (Exception e) {
        throw new ResourceManagerException(e);
    }
}
Also used : XaQueueTxJournalEntry(org.mule.runtime.core.internal.util.journal.queue.XaQueueTxJournalEntry) ResourceManagerException(org.mule.runtime.core.api.transaction.xa.ResourceManagerException) ResourceManagerException(org.mule.runtime.core.api.transaction.xa.ResourceManagerException)

Example 3 with XaQueueTxJournalEntry

use of org.mule.runtime.core.internal.util.journal.queue.XaQueueTxJournalEntry in project mule by mulesoft.

the class PersistentXaTransactionContext method doRollback.

@Override
public void doRollback() throws ResourceManagerException {
    Collection<XaQueueTxJournalEntry> logEntries = this.transactionJournal.getLogEntriesForTx(xid);
    for (XaQueueTxJournalEntry entry : logEntries) {
        if (entry.isRemove()) {
            try {
                queueProvider.getQueue(entry.getQueueName()).putNow(entry.getValue());
            } catch (InterruptedException e) {
                throw new ResourceManagerException(e);
            }
        }
    }
    this.transactionJournal.logRollback(xid);
}
Also used : XaQueueTxJournalEntry(org.mule.runtime.core.internal.util.journal.queue.XaQueueTxJournalEntry) ResourceManagerException(org.mule.runtime.core.api.transaction.xa.ResourceManagerException)

Example 4 with XaQueueTxJournalEntry

use of org.mule.runtime.core.internal.util.journal.queue.XaQueueTxJournalEntry in project mule by mulesoft.

the class XaTransactionRecoverer method recover.

public synchronized Xid[] recover(int flag) throws XAException {
    // No need to do anything for XAResource.TMENDRSCAN
    if (flag == XAResource.TMENDRSCAN) {
        return new Xid[0];
    }
    // For XAResource.TMSTARTRSCAN and XAResource.TMNOFLAGS (only possible values despite XAResource.TMENDRSCAN we returns
    // the set of Xid to recover (no commit, no rollback) and bitronix will commit, rollback for Xid that are
    // dangling transactions and will do nothing for those that are currently being executed.
    Multimap<Xid, XaQueueTxJournalEntry> xidXaJournalEntryMultimap = xaTxQueueTransactionJournal.getAllLogEntries();
    if (logger.isDebugEnabled()) {
        logger.debug("Executing XA recover");
        logger.debug("Found " + xidXaJournalEntryMultimap.size() + " in the tx log");
    }
    List<Xid> txsToRecover = new ArrayList<Xid>();
    for (Xid xid : xidXaJournalEntryMultimap.keySet()) {
        Collection<XaQueueTxJournalEntry> entries = xidXaJournalEntryMultimap.get(xid);
        Object commitOrRollback = find(entries, new Predicate() {

            @Override
            public boolean evaluate(Object object) {
                XaQueueTxJournalEntry logEntry = (XaQueueTxJournalEntry) object;
                return logEntry.isCommit() || logEntry.isRollback();
            }
        });
        if (commitOrRollback != null) {
            continue;
        }
        txsToRecover.add(xid);
    }
    if (logger.isDebugEnabled()) {
        logger.debug("found " + txsToRecover.size() + " txs to recover");
    }
    return txsToRecover.toArray(new Xid[txsToRecover.size()]);
}
Also used : Xid(javax.transaction.xa.Xid) XaQueueTxJournalEntry(org.mule.runtime.core.internal.util.journal.queue.XaQueueTxJournalEntry) ArrayList(java.util.ArrayList) Predicate(org.apache.commons.collections.Predicate)

Aggregations

XaQueueTxJournalEntry (org.mule.runtime.core.internal.util.journal.queue.XaQueueTxJournalEntry)4 ResourceManagerException (org.mule.runtime.core.api.transaction.xa.ResourceManagerException)2 ArrayList (java.util.ArrayList)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Xid (javax.transaction.xa.Xid)1 Closure (org.apache.commons.collections.Closure)1 Predicate (org.apache.commons.collections.Predicate)1