Search in sources :

Example 66 with MessageReference

use of org.apache.activemq.artemis.core.server.MessageReference in project activemq-artemis by apache.

the class QueueImpl method sendMessagesToDeadLetterAddress.

@Override
public synchronized int sendMessagesToDeadLetterAddress(Filter filter) throws Exception {
    int count = 0;
    try (LinkedListIterator<MessageReference> iter = iterator()) {
        while (iter.hasNext()) {
            MessageReference ref = iter.next();
            if (filter == null || filter.match(ref.getMessage())) {
                incDelivering(ref);
                sendToDeadLetterAddress(null, ref);
                iter.remove();
                refRemoved(ref);
                count++;
            }
        }
        return count;
    }
}
Also used : MessageReference(org.apache.activemq.artemis.core.server.MessageReference)

Example 67 with MessageReference

use of org.apache.activemq.artemis.core.server.MessageReference in project activemq-artemis by apache.

the class QueueImpl method iterQueue.

/**
 * This is a generic method for any method interacting on the Queue to move or delete messages
 * Instead of duplicate the feature we created an abstract class where you pass the logic for
 * each message.
 *
 * @param filter1
 * @param messageAction
 * @return
 * @throws Exception
 */
private synchronized int iterQueue(final int flushLimit, final Filter filter1, QueueIterateAction messageAction) throws Exception {
    int count = 0;
    int txCount = 0;
    Transaction tx = new TransactionImpl(storageManager);
    try (LinkedListIterator<MessageReference> iter = iterator()) {
        while (iter.hasNext()) {
            MessageReference ref = iter.next();
            if (ref.isPaged() && queueDestroyed) {
                // page cleanup
                continue;
            }
            if (filter1 == null || filter1.match(ref.getMessage())) {
                messageAction.actMessage(tx, ref);
                iter.remove();
                txCount++;
                count++;
            }
        }
        if (txCount > 0) {
            tx.commit();
            tx = new TransactionImpl(storageManager);
            txCount = 0;
        }
        List<MessageReference> cancelled = scheduledDeliveryHandler.cancel(filter1);
        for (MessageReference messageReference : cancelled) {
            messageAction.actMessage(tx, messageReference);
            count++;
            txCount++;
        }
        if (txCount > 0) {
            tx.commit();
            tx = new TransactionImpl(storageManager);
            txCount = 0;
        }
        if (pageIterator != null && !queueDestroyed) {
            while (pageIterator.hasNext()) {
                PagedReference reference = pageIterator.next();
                pageIterator.remove();
                if (filter1 == null || filter1.match(reference.getMessage())) {
                    count++;
                    txCount++;
                    messageAction.actMessage(tx, reference, false);
                } else {
                    addTail(reference, false);
                }
                if (txCount > 0 && txCount % flushLimit == 0) {
                    tx.commit();
                    tx = new TransactionImpl(storageManager);
                    txCount = 0;
                }
            }
        }
        if (txCount > 0) {
            tx.commit();
            tx = null;
        }
        if (filter != null && !queueDestroyed && pageSubscription != null) {
            scheduleDepage(false);
        }
        return count;
    }
}
Also used : PagedReference(org.apache.activemq.artemis.core.paging.cursor.PagedReference) Transaction(org.apache.activemq.artemis.core.transaction.Transaction) TransactionImpl(org.apache.activemq.artemis.core.transaction.impl.TransactionImpl) BindingsTransactionImpl(org.apache.activemq.artemis.core.transaction.impl.BindingsTransactionImpl) MessageReference(org.apache.activemq.artemis.core.server.MessageReference)

Example 68 with MessageReference

use of org.apache.activemq.artemis.core.server.MessageReference in project activemq-artemis by apache.

the class QueueImpl method addHead.

/* Called when a message is cancelled back into the queue */
@Override
public void addHead(final List<MessageReference> refs, boolean scheduling) {
    enterCritical(CRITICAL_PATH_ADD_HEAD);
    synchronized (this) {
        try {
            for (MessageReference ref : refs) {
                addHead(ref, scheduling);
            }
            resetAllIterators();
            deliverAsync();
        } finally {
            leaveCritical(CRITICAL_PATH_ADD_HEAD);
        }
    }
}
Also used : MessageReference(org.apache.activemq.artemis.core.server.MessageReference)

Example 69 with MessageReference

use of org.apache.activemq.artemis.core.server.MessageReference in project activemq-artemis by apache.

the class QueueImpl method expireReferences.

@Override
public synchronized int expireReferences(final Filter filter) throws Exception {
    if (isExpirationRedundant()) {
        return 0;
    }
    Transaction tx = new TransactionImpl(storageManager);
    int count = 0;
    try (LinkedListIterator<MessageReference> iter = iterator()) {
        while (iter.hasNext()) {
            MessageReference ref = iter.next();
            if (filter == null || filter.match(ref.getMessage())) {
                incDelivering(ref);
                expire(tx, ref);
                iter.remove();
                refRemoved(ref);
                count++;
            }
        }
        tx.commit();
        return count;
    }
}
Also used : Transaction(org.apache.activemq.artemis.core.transaction.Transaction) TransactionImpl(org.apache.activemq.artemis.core.transaction.impl.TransactionImpl) BindingsTransactionImpl(org.apache.activemq.artemis.core.transaction.impl.BindingsTransactionImpl) MessageReference(org.apache.activemq.artemis.core.server.MessageReference)

Example 70 with MessageReference

use of org.apache.activemq.artemis.core.server.MessageReference in project activemq-artemis by apache.

the class QueueImpl method moveReference.

@Override
public synchronized boolean moveReference(final long messageID, final SimpleString toAddress, final Binding binding, final boolean rejectDuplicate) throws Exception {
    try (LinkedListIterator<MessageReference> iter = iterator()) {
        while (iter.hasNext()) {
            MessageReference ref = iter.next();
            if (ref.getMessage().getMessageID() == messageID) {
                iter.remove();
                refRemoved(ref);
                incDelivering(ref);
                try {
                    move(null, toAddress, binding, ref, rejectDuplicate, AckReason.NORMAL);
                } catch (Exception e) {
                    decDelivering(ref);
                    throw e;
                }
                return true;
            }
        }
        return false;
    }
}
Also used : MessageReference(org.apache.activemq.artemis.core.server.MessageReference) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

MessageReference (org.apache.activemq.artemis.core.server.MessageReference)82 ArrayList (java.util.ArrayList)29 QueueImpl (org.apache.activemq.artemis.core.server.impl.QueueImpl)26 Test (org.junit.Test)26 FakeConsumer (org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakeConsumer)18 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)17 Transaction (org.apache.activemq.artemis.core.transaction.Transaction)14 Message (org.apache.activemq.artemis.api.core.Message)12 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)11 TransactionImpl (org.apache.activemq.artemis.core.transaction.impl.TransactionImpl)11 Queue (org.apache.activemq.artemis.core.server.Queue)10 HashMap (java.util.HashMap)9 NoSuchElementException (java.util.NoSuchElementException)9 Map (java.util.Map)8 Filter (org.apache.activemq.artemis.core.filter.Filter)7 LinkedList (java.util.LinkedList)5 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)5 ActiveMQIllegalStateException (org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException)4 BindingsTransactionImpl (org.apache.activemq.artemis.core.transaction.impl.BindingsTransactionImpl)4 HashSet (java.util.HashSet)3