use of org.mule.runtime.core.internal.util.queue.RecoverableQueueStore in project mule by mulesoft.
the class LocalTxQueueTransactionRecoverer method recover.
/**
* Recover all the pending transactions.
*
* Will undo all operations done over queues that were not commit or rolled back.
*
* Clears the transaction log after processing all the log entries since does entries are not longer required.
*/
public void recover() {
if (logger.isDebugEnabled()) {
logger.debug("Executing transaction recovery");
}
Multimap<Integer, LocalQueueTxJournalEntry> allEntries = this.localTxQueueTransactionJournal.getAllLogEntries();
if (logger.isDebugEnabled()) {
logger.debug("Found " + allEntries.size() + " txs to recover");
}
int txRecovered = 0;
for (Integer txId : allEntries.keySet()) {
Collection<LocalQueueTxJournalEntry> entries = allEntries.get(txId);
Object commitOrRollback = find(entries, new Predicate() {
@Override
public boolean evaluate(Object object) {
LocalQueueTxJournalEntry logEntry = (LocalQueueTxJournalEntry) object;
return logEntry.isCommit() || logEntry.isRollback();
}
});
if (commitOrRollback != null) {
continue;
}
txRecovered++;
for (LocalQueueTxJournalEntry logEntry : entries) {
if (logEntry.isRemove()) {
String queueName = logEntry.getQueueName();
RecoverableQueueStore queue = queueProvider.getRecoveryQueue(queueName);
Serializable polledValue = logEntry.getValue();
if (!queue.contains(polledValue)) {
if (logger.isDebugEnabled()) {
logger.debug("re-adding polled element that was not commited to queue " + queue.getName());
}
try {
queue.putNow(polledValue);
} catch (InterruptedException e) {
throw new MuleRuntimeException(e);
}
}
} else if (logEntry.isAdd() || logEntry.isAddFirst()) {
Serializable offeredValue = logEntry.getValue();
String queueName = logEntry.getQueueName();
RecoverableQueueStore queue = queueProvider.getRecoveryQueue(queueName);
if (queue.contains(offeredValue)) {
if (logger.isDebugEnabled()) {
logger.debug("removing offer element that was not commited to queue " + queue.getName());
}
queue.remove(offeredValue);
}
}
}
}
if (logger.isDebugEnabled()) {
logger.debug("Recovered " + txRecovered + " txs to recover");
}
this.localTxQueueTransactionJournal.clear();
}
Aggregations