use of org.mule.runtime.core.internal.util.journal.queue.LocalQueueTxJournalEntry in project mule by mulesoft.
the class PersistentQueueTransactionContext method size.
public int size(final QueueStore queue) {
int numberOfElementsAdded = 0;
Collection<LocalQueueTxJournalEntry> logEntries = this.transactionJournal.getLogEntriesForTx(txId);
for (LocalQueueTxJournalEntry logEntry : logEntries) {
if (logEntry.getQueueName().equals(queue.getName()) && (logEntry.isAdd() || logEntry.isAddFirst())) {
numberOfElementsAdded++;
}
}
return queue.getSize() + numberOfElementsAdded;
}
use of org.mule.runtime.core.internal.util.journal.queue.LocalQueueTxJournalEntry in project mule by mulesoft.
the class TransactionJournalFileTestCase method largeQueueName.
@Test
public void largeQueueName() throws Exception {
final String queueName = RandomStringUtils.randomAlphanumeric(129);
final Serializable payload = "Hello World!";
final int txId = 1;
TransactionJournalFile<Integer, LocalQueueTxJournalEntry> journal = openJournal();
journal.logOperation(new LocalQueueTxJournalEntry(txId, (byte) 6, queueName, payload));
journal.close();
journal = openJournal();
Collection<LocalQueueTxJournalEntry> entries = journal.getLogEntries(txId);
assertThat(entries, is(notNullValue()));
assertThat(entries.size(), equalTo(1));
LocalQueueTxJournalEntry entry = entries.iterator().next();
assertThat(entry.getQueueName(), equalTo(queueName));
assertThat(entry.getValue(), equalTo(payload));
}
use of org.mule.runtime.core.internal.util.journal.queue.LocalQueueTxJournalEntry in project mule by mulesoft.
the class PersistentQueueTransactionContext method doCommit.
@Override
public void doCommit() throws ResourceManagerException {
try {
Collection<LocalQueueTxJournalEntry> logEntries = this.transactionJournal.getLogEntriesForTx(txId);
for (LocalQueueTxJournalEntry 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(txId);
} catch (Exception e) {
throw new ResourceManagerException(e);
}
}
use of org.mule.runtime.core.internal.util.journal.queue.LocalQueueTxJournalEntry in project mule by mulesoft.
the class PersistentQueueTransactionContext method doRollback.
@Override
public void doRollback() throws ResourceManagerException {
Collection<LocalQueueTxJournalEntry> logEntries = this.transactionJournal.getLogEntriesForTx(txId);
for (LocalQueueTxJournalEntry entry : logEntries) {
if (entry.isRemove()) {
try {
queueProvider.getQueue(entry.getQueueName()).putNow(entry.getValue());
} catch (InterruptedException e) {
throw new ResourceManagerException(e);
}
}
}
this.transactionJournal.logRollback(txId);
}
Aggregations