Search in sources :

Example 1 with BaseQueue

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

the class AsyncAutoCommitTransaction method enqueue.

@Override
public void enqueue(Collection<? extends BaseQueue> queues, EnqueueableMessage message, EnqueueAction postTransactionAction) {
    Transaction txn = null;
    try {
        final MessageEnqueueRecord[] records = new MessageEnqueueRecord[queues.size()];
        int i = 0;
        for (BaseQueue queue : queues) {
            if (queue.getMessageDurability().persist(message.isPersistent())) {
                LOGGER.debug("Enqueue of message number {} to transaction log. Queue : {}", message.getMessageNumber(), queue.getName());
                if (txn == null) {
                    txn = _messageStore.newTransaction();
                }
                records[i] = txn.enqueueMessage(queue, message);
            }
            i++;
        }
        ListenableFuture<Void> future;
        if (txn != null) {
            future = txn.commitTranAsync((Void) null);
            txn = null;
        } else {
            future = Futures.immediateFuture(null);
        }
        final EnqueueAction underlying = postTransactionAction;
        addEnqueueFuture(future, new Action() {

            @Override
            public void postCommit() {
                if (underlying != null) {
                    underlying.postCommit(records);
                }
            }

            @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) BaseQueue(org.apache.qpid.server.queue.BaseQueue) MessageEnqueueRecord(org.apache.qpid.server.store.MessageEnqueueRecord)

Example 2 with BaseQueue

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

the class DistributedTransaction method enqueue.

@Override
public void enqueue(Collection<? extends BaseQueue> queues, EnqueueableMessage message, final EnqueueAction postTransactionAction) {
    if (_branch != null) {
        final MessageEnqueueRecord[] enqueueRecords = new MessageEnqueueRecord[queues.size()];
        int i = 0;
        for (BaseQueue queue : queues) {
            final int pos = i;
            _branch.enqueue(queue, message, new org.apache.qpid.server.util.Action<MessageEnqueueRecord>() {

                @Override
                public void performAction(final MessageEnqueueRecord record) {
                    enqueueRecords[pos] = record;
                }
            });
            i++;
        }
        addPostTransactionAction(new Action() {

            @Override
            public void postCommit() {
                postTransactionAction.postCommit(enqueueRecords);
            }

            @Override
            public void onRollback() {
                postTransactionAction.onRollback();
            }
        });
    } else {
        _autoCommitTransaction.enqueue(queues, message, postTransactionAction);
    }
}
Also used : BaseQueue(org.apache.qpid.server.queue.BaseQueue) MessageEnqueueRecord(org.apache.qpid.server.store.MessageEnqueueRecord)

Example 3 with BaseQueue

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

the class AutoCommitTransaction method enqueue.

@Override
public void enqueue(Collection<? extends BaseQueue> queues, EnqueueableMessage message, EnqueueAction postTransactionAction) {
    Transaction txn = null;
    try {
        MessageEnqueueRecord[] enqueueRecords = new MessageEnqueueRecord[queues.size()];
        int i = 0;
        for (BaseQueue queue : queues) {
            if (queue.getMessageDurability().persist(message.isPersistent())) {
                LOGGER.debug("Enqueue of message number {} to transaction log. Queue : {}", message.getMessageNumber(), queue.getName());
                if (txn == null) {
                    txn = _messageStore.newTransaction();
                }
                enqueueRecords[i] = txn.enqueueMessage(queue, message);
            }
            i++;
        }
        if (txn != null) {
            txn.commitTran();
            txn = null;
        }
        if (postTransactionAction != null) {
            postTransactionAction.postCommit(enqueueRecords);
        }
        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) BaseQueue(org.apache.qpid.server.queue.BaseQueue) MessageEnqueueRecord(org.apache.qpid.server.store.MessageEnqueueRecord)

Example 4 with BaseQueue

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

the class AutoCommitTransactionTest method createTestAMQQueue.

private BaseQueue createTestAMQQueue(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 5 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)

Aggregations

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