Search in sources :

Example 6 with BaseQueue

use of org.apache.qpid.server.queue.BaseQueue in project qpid-broker-j by apache.

the class AutoCommitTransactionTest method createTestQueueEntries.

private Collection<MessageInstance> createTestQueueEntries(boolean[] queueDurableFlags, boolean[] messagePersistentFlags) {
    Collection<MessageInstance> queueEntries = new ArrayList<MessageInstance>();
    assertTrue("Boolean arrays must be the same length", queueDurableFlags.length == messagePersistentFlags.length);
    for (int i = 0; i < queueDurableFlags.length; i++) {
        final BaseQueue queue = createTestAMQQueue(queueDurableFlags[i]);
        final ServerMessage message = createTestMessage(messagePersistentFlags[i]);
        final boolean hasRecord = queueDurableFlags[i] && messagePersistentFlags[i];
        queueEntries.add(new MockMessageInstance() {

            @Override
            public ServerMessage getMessage() {
                return message;
            }

            @Override
            public TransactionLogResource getOwningResource() {
                return queue;
            }

            @Override
            public MessageEnqueueRecord getEnqueueRecord() {
                if (hasRecord) {
                    return mock(MessageEnqueueRecord.class);
                } else {
                    return null;
                }
            }
        });
    }
    return queueEntries;
}
Also used : MockMessageInstance(org.apache.qpid.server.queue.MockMessageInstance) MessageInstance(org.apache.qpid.server.message.MessageInstance) MockMessageInstance(org.apache.qpid.server.queue.MockMessageInstance) ArrayList(java.util.ArrayList) BaseQueue(org.apache.qpid.server.queue.BaseQueue) ServerMessage(org.apache.qpid.server.message.ServerMessage) MessageEnqueueRecord(org.apache.qpid.server.store.MessageEnqueueRecord) TransactionLogResource(org.apache.qpid.server.store.TransactionLogResource)

Example 7 with BaseQueue

use of org.apache.qpid.server.queue.BaseQueue in project qpid-broker-j by apache.

the class LocalTransactionTest method createQueue.

private BaseQueue createQueue(final boolean durable) {
    BaseQueue queue = mock(BaseQueue.class);
    when(queue.getMessageDurability()).thenReturn(durable ? MessageDurability.DEFAULT : MessageDurability.NEVER);
    return queue;
}
Also used : BaseQueue(org.apache.qpid.server.queue.BaseQueue)

Example 8 with BaseQueue

use of org.apache.qpid.server.queue.BaseQueue 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)

Aggregations

BaseQueue (org.apache.qpid.server.queue.BaseQueue)8 MessageEnqueueRecord (org.apache.qpid.server.store.MessageEnqueueRecord)5 Transaction (org.apache.qpid.server.store.Transaction)2 ArrayList (java.util.ArrayList)1 MessageInstance (org.apache.qpid.server.message.MessageInstance)1 ServerMessage (org.apache.qpid.server.message.ServerMessage)1 MockMessageInstance (org.apache.qpid.server.queue.MockMessageInstance)1 TransactionLogResource (org.apache.qpid.server.store.TransactionLogResource)1 ServerScopedRuntimeException (org.apache.qpid.server.util.ServerScopedRuntimeException)1