Search in sources :

Example 6 with MessageEnqueueRecord

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

the class LocalTransaction method dequeue.

@Override
public void dequeue(Collection<MessageInstance> queueEntries, Action postTransactionAction) {
    sync();
    _outstandingWork = true;
    _postTransactionActions.add(postTransactionAction);
    initTransactionStartTimeIfNecessaryAndAdvanceUpdateTime();
    try {
        for (MessageInstance entry : queueEntries) {
            final MessageEnqueueRecord record = entry.getEnqueueRecord();
            if (record != null) {
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("Dequeue of message number " + record.getMessageNumber() + " from transaction log. Queue : " + record.getQueueId());
                }
                beginTranIfNecessary();
                _transaction.dequeueMessage(record);
            }
        }
    } catch (RuntimeException e) {
        tidyUpOnError(e);
    }
}
Also used : MessageInstance(org.apache.qpid.server.message.MessageInstance) ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException) MessageEnqueueRecord(org.apache.qpid.server.store.MessageEnqueueRecord)

Example 7 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(TransactionLogResource queue, EnqueueableMessage message, EnqueueAction postTransactionAction) {
    sync();
    _outstandingWork = true;
    initTransactionStartTimeIfNecessaryAndAdvanceUpdateTime();
    _transactionObserver.onMessageEnqueue(this, message);
    if (queue.getMessageDurability().persist(message.isPersistent())) {
        try {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Enqueue of message number " + message.getMessageNumber() + " to transaction log. Queue : " + queue.getName());
            }
            beginTranIfNecessary();
            final MessageEnqueueRecord record = _transaction.enqueueMessage(queue, message);
            if (postTransactionAction != null) {
                final EnqueueAction underlying = postTransactionAction;
                _postTransactionActions.add(new Action() {

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

                    @Override
                    public void onRollback() {
                        underlying.onRollback();
                    }
                });
            }
        } 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);
        }
    } else {
        if (postTransactionAction != null) {
            final EnqueueAction underlying = postTransactionAction;
            _postTransactionActions.add(new Action() {

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

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

Example 8 with MessageEnqueueRecord

use of org.apache.qpid.server.store.MessageEnqueueRecord 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 9 with MessageEnqueueRecord

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

the class DtxBranch method prePrepareTransaction.

public void prePrepareTransaction() throws StoreException {
    _transaction = _dtxRegistry.getMessageStore().newTransaction();
    for (final EnqueueRecord enqueue : _enqueueRecords) {
        final MessageEnqueueRecord record;
        if (enqueue.isDurable()) {
            record = _transaction.enqueueMessage(enqueue.getResource(), enqueue.getMessage());
        } else {
            record = null;
        }
        enqueue.getEnqueueAction().performAction(record);
    }
    for (DequeueRecord dequeue : _dequeueRecords) {
        _transaction.dequeueMessage(dequeue.getEnqueueRecord());
    }
}
Also used : MessageEnqueueRecord(org.apache.qpid.server.store.MessageEnqueueRecord) MessageEnqueueRecord(org.apache.qpid.server.store.MessageEnqueueRecord)

Example 10 with MessageEnqueueRecord

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

the class AutoCommitTransaction method enqueue.

@Override
public void enqueue(TransactionLogResource queue, EnqueueableMessage message, EnqueueAction postTransactionAction) {
    Transaction txn = null;
    try {
        final MessageEnqueueRecord record;
        if (queue.getMessageDurability().persist(message.isPersistent())) {
            LOGGER.debug("Enqueue of message number {} to transaction log. Queue : {}", message.getMessageNumber(), queue.getName());
            txn = _messageStore.newTransaction();
            record = txn.enqueueMessage(queue, message);
            txn.commitTran();
            txn = null;
        } else {
            record = null;
        }
        if (postTransactionAction != null) {
            postTransactionAction.postCommit(record);
        }
        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)

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