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();
}
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);
}
}
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);
}
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()]);
}
Aggregations