Search in sources :

Example 16 with MessageEnqueueRecord

use of org.apache.qpid.server.store.MessageEnqueueRecord in project qpid-broker-j by apache.

the class AbstractQueueTestBase method testDeleteEntryPersistent.

@Test
public void testDeleteEntryPersistent() throws Exception {
    long messageNumber = 1L;
    final MessageEnqueueRecord record = mock(MessageEnqueueRecord.class);
    when(record.getMessageNumber()).thenReturn(messageNumber);
    when(record.getQueueId()).thenReturn(_queue.getId());
    deleteEntry(messageNumber, record);
}
Also used : MessageEnqueueRecord(org.apache.qpid.server.store.MessageEnqueueRecord) Test(org.junit.Test)

Example 17 with MessageEnqueueRecord

use of org.apache.qpid.server.store.MessageEnqueueRecord in project qpid-broker-j by apache.

the class AsyncAutoCommitTransaction method enqueue.

@Override
public void enqueue(TransactionLogResource queue, EnqueueableMessage message, EnqueueAction postTransactionAction) {
    Transaction txn = null;
    try {
        ListenableFuture<Void> future;
        final MessageEnqueueRecord enqueueRecord;
        if (queue.getMessageDurability().persist(message.isPersistent())) {
            LOGGER.debug("Enqueue of message number {} to transaction log. Queue : {}", message.getMessageNumber(), queue.getName());
            txn = _messageStore.newTransaction();
            enqueueRecord = txn.enqueueMessage(queue, message);
            future = txn.commitTranAsync(null);
            txn = null;
        } else {
            future = Futures.immediateFuture(null);
            enqueueRecord = null;
        }
        final EnqueueAction underlying = postTransactionAction;
        addEnqueueFuture(future, new Action() {

            @Override
            public void postCommit() {
                underlying.postCommit(enqueueRecord);
            }

            @Override
            public void onRollback() {
                underlying.onRollback();
            }
        }, message.isPersistent());
        postTransactionAction = null;
    } finally {
        final EnqueueAction underlying = postTransactionAction;
        rollbackIfNecessary(new Action() {

            @Override
            public void postCommit() {
            }

            @Override
            public void onRollback() {
                if (underlying != null) {
                    underlying.onRollback();
                }
            }
        }, txn);
    }
}
Also used : Transaction(org.apache.qpid.server.store.Transaction) MessageEnqueueRecord(org.apache.qpid.server.store.MessageEnqueueRecord)

Example 18 with MessageEnqueueRecord

use of org.apache.qpid.server.store.MessageEnqueueRecord in project qpid-broker-j by apache.

the class LocalTransaction method enqueue.

@Override
public void enqueue(Collection<? extends BaseQueue> queues, EnqueueableMessage message, EnqueueAction postTransactionAction) {
    sync();
    _outstandingWork = true;
    initTransactionStartTimeIfNecessaryAndAdvanceUpdateTime();
    _transactionObserver.onMessageEnqueue(this, message);
    try {
        final MessageEnqueueRecord[] records = new MessageEnqueueRecord[queues.size()];
        int i = 0;
        for (BaseQueue queue : queues) {
            if (queue.getMessageDurability().persist(message.isPersistent())) {
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("Enqueue of message number " + message.getMessageNumber() + " to transaction log. Queue : " + queue.getName());
                }
                beginTranIfNecessary();
                records[i] = _transaction.enqueueMessage(queue, message);
            }
            i++;
        }
        if (postTransactionAction != null) {
            final EnqueueAction underlying = postTransactionAction;
            _postTransactionActions.add(new Action() {

                @Override
                public void postCommit() {
                    underlying.postCommit(records);
                }

                @Override
                public void onRollback() {
                    underlying.onRollback();
                }
            });
            postTransactionAction = null;
        }
    } catch (RuntimeException e) {
        if (postTransactionAction != null) {
            final EnqueueAction underlying = postTransactionAction;
            _postTransactionActions.add(new Action() {

                @Override
                public void postCommit() {
                }

                @Override
                public void onRollback() {
                    underlying.onRollback();
                }
            });
        }
        tidyUpOnError(e);
    }
}
Also used : ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException) BaseQueue(org.apache.qpid.server.queue.BaseQueue) MessageEnqueueRecord(org.apache.qpid.server.store.MessageEnqueueRecord)

Example 19 with MessageEnqueueRecord

use of org.apache.qpid.server.store.MessageEnqueueRecord in project qpid-broker-j by apache.

the class AutoCommitTransaction method dequeue.

@Override
public void dequeue(Collection<MessageInstance> queueEntries, Action postTransactionAction) {
    Transaction txn = null;
    try {
        for (MessageInstance entry : queueEntries) {
            MessageEnqueueRecord enqueueRecord = entry.getEnqueueRecord();
            if (enqueueRecord != null) {
                LOGGER.debug("Dequeue of message number {} from transaction log. Queue : {}", enqueueRecord.getMessageNumber(), enqueueRecord.getQueueId());
                if (txn == null) {
                    txn = _messageStore.newTransaction();
                }
                txn.dequeueMessage(enqueueRecord);
            }
        }
        if (txn != null) {
            txn.commitTran();
            txn = null;
        }
        postTransactionAction.postCommit();
        postTransactionAction = null;
    } finally {
        rollbackIfNecessary(postTransactionAction, txn);
    }
}
Also used : MessageInstance(org.apache.qpid.server.message.MessageInstance) Transaction(org.apache.qpid.server.store.Transaction) MessageEnqueueRecord(org.apache.qpid.server.store.MessageEnqueueRecord)

Example 20 with MessageEnqueueRecord

use of org.apache.qpid.server.store.MessageEnqueueRecord in project qpid-broker-j by apache.

the class RingOverflowPolicyTest method enqueueTestMessage.

private ServerMessage<?> enqueueTestMessage(final Queue<?> queue) {
    final ServerMessage<?> message = createMessage(_messageId.incrementAndGet(), queue.getName());
    final MessageEnqueueRecord record = createMessageEnqueueRecord(queue.getId(), message.getMessageNumber());
    queue.enqueue(message, null, record);
    return message;
}
Also used : MessageEnqueueRecord(org.apache.qpid.server.store.MessageEnqueueRecord)

Aggregations

MessageEnqueueRecord (org.apache.qpid.server.store.MessageEnqueueRecord)24 Transaction (org.apache.qpid.server.store.Transaction)11 TransactionLogResource (org.apache.qpid.server.store.TransactionLogResource)7 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)6 MessageInstance (org.apache.qpid.server.message.MessageInstance)6 UUID (java.util.UUID)5 ServerMessage (org.apache.qpid.server.message.ServerMessage)5 InternalMessage (org.apache.qpid.server.message.internal.InternalMessage)4 BaseQueue (org.apache.qpid.server.queue.BaseQueue)4 MessageStore (org.apache.qpid.server.store.MessageStore)4 StoredMessage (org.apache.qpid.server.store.StoredMessage)4 Collections (java.util.Collections)2 List (java.util.List)2 TimeUnit (java.util.concurrent.TimeUnit)2 AMQMessageHeader (org.apache.qpid.server.message.AMQMessageHeader)2 ServerScopedRuntimeException (org.apache.qpid.server.util.ServerScopedRuntimeException)2 After (org.junit.After)2 Assert.assertEquals (org.junit.Assert.assertEquals)2 Assert.assertNotNull (org.junit.Assert.assertNotNull)2