Search in sources :

Example 1 with LocalQueueTxJournalEntry

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;
}
Also used : LocalQueueTxJournalEntry(org.mule.runtime.core.internal.util.journal.queue.LocalQueueTxJournalEntry)

Example 2 with LocalQueueTxJournalEntry

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

Example 3 with LocalQueueTxJournalEntry

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

Example 4 with LocalQueueTxJournalEntry

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

Aggregations

LocalQueueTxJournalEntry (org.mule.runtime.core.internal.util.journal.queue.LocalQueueTxJournalEntry)4 ResourceManagerException (org.mule.runtime.core.api.transaction.xa.ResourceManagerException)2 Serializable (java.io.Serializable)1 Test (org.junit.Test)1