Search in sources :

Example 36 with MessageReference

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

the class ScheduledDeliveryHandlerTest method validateSequence.

private void validateSequence(ScheduledDeliveryHandlerImpl handler) throws Exception {
    long lastSequence = -1;
    for (MessageReference ref : handler.getScheduledReferences()) {
        assertEquals(lastSequence + 1, ref.getMessage().getMessageID());
        lastSequence = ref.getMessage().getMessageID();
    }
}
Also used : MessageReference(org.apache.activemq.artemis.core.server.MessageReference)

Example 37 with MessageReference

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

the class PagingSendTest method processCountThroughIterator.

/**
 * checks that there are no message duplicates in the page.  Any IDs found in the ignoreIds field will not be tested
 * this allows us to test only those messages that have been sent after the address has started paging (ignoring any
 * duplicates that may have happened before this point).
 */
protected int processCountThroughIterator(Queue queue) throws Exception {
    LinkedListIterator<MessageReference> pageIterator = queue.browserIterator();
    int count = 0;
    while (pageIterator.hasNext()) {
        MessageReference reference = pageIterator.next();
        count++;
    }
    return count;
}
Also used : MessageReference(org.apache.activemq.artemis.core.server.MessageReference)

Example 38 with MessageReference

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

the class PagingSendTest method checkBatchMessagesAreNotPagedTwice.

/**
 * checks that there are no message duplicates in the page.  Any IDs found in the ignoreIds field will not be tested
 * this allows us to test only those messages that have been sent after the address has started paging (ignoring any
 * duplicates that may have happened before this point).
 */
public void checkBatchMessagesAreNotPagedTwice(Queue queue) throws Exception {
    LinkedListIterator<MessageReference> pageIterator = queue.browserIterator();
    Set<String> messageOrderSet = new HashSet<>();
    int duplicates = 0;
    while (pageIterator.hasNext()) {
        MessageReference reference = pageIterator.next();
        String id = reference.getMessage().getStringProperty("id");
        // If add(id) returns true it means that this id was already added to this set.  Hence a duplicate is found.
        if (!messageOrderSet.add(id)) {
            duplicates++;
        }
    }
    assertTrue(duplicates == 0);
}
Also used : SimpleString(org.apache.activemq.artemis.api.core.SimpleString) MessageReference(org.apache.activemq.artemis.core.server.MessageReference) HashSet(java.util.HashSet)

Example 39 with MessageReference

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

the class PostOfficeImpl method processRoute.

@Override
public void processRoute(final Message message, final RoutingContext context, final boolean direct) throws Exception {
    final List<MessageReference> refs = new ArrayList<>();
    Transaction tx = context.getTransaction();
    Long deliveryTime = message.getScheduledDeliveryTime();
    for (Map.Entry<SimpleString, RouteContextList> entry : context.getContexListing().entrySet()) {
        PagingStore store = pagingManager.getPageStore(entry.getKey());
        if (storageManager.addToPage(store, message, context.getTransaction(), entry.getValue())) {
            if (message.isLargeMessage()) {
                confirmLargeMessageSend(tx, message);
            }
            // We need to kick delivery so the Queues may check for the cursors case they are empty
            schedulePageDelivery(tx, entry);
            continue;
        }
        for (Queue queue : entry.getValue().getNonDurableQueues()) {
            MessageReference reference = MessageReference.Factory.createReference(message, queue);
            if (deliveryTime != null) {
                reference.setScheduledDeliveryTime(deliveryTime);
            }
            refs.add(reference);
            message.incrementRefCount();
        }
        Iterator<Queue> iter = entry.getValue().getDurableQueues().iterator();
        while (iter.hasNext()) {
            Queue queue = iter.next();
            MessageReference reference = MessageReference.Factory.createReference(message, queue);
            if (context.isAlreadyAcked(context.getAddress(message), queue)) {
                reference.setAlreadyAcked();
                if (tx != null) {
                    queue.acknowledge(tx, reference);
                }
            }
            if (deliveryTime != null) {
                reference.setScheduledDeliveryTime(deliveryTime);
            }
            refs.add(reference);
            if (message.isDurable()) {
                int durableRefCount = message.incrementDurableRefCount();
                if (durableRefCount == 1) {
                    if (tx != null) {
                        storageManager.storeMessageTransactional(tx.getID(), message);
                    } else {
                        storageManager.storeMessage(message);
                    }
                    if (message.isLargeMessage()) {
                        confirmLargeMessageSend(tx, message);
                    }
                }
                if (tx != null) {
                    storageManager.storeReferenceTransactional(tx.getID(), queue.getID(), message.getMessageID());
                    tx.setContainsPersistent();
                } else {
                    storageManager.storeReference(queue.getID(), message.getMessageID(), !iter.hasNext());
                }
                if (deliveryTime > 0) {
                    if (tx != null) {
                        storageManager.updateScheduledDeliveryTimeTransactional(tx.getID(), reference);
                    } else {
                        storageManager.updateScheduledDeliveryTime(reference);
                    }
                }
            }
            message.incrementRefCount();
        }
    }
    if (tx != null) {
        tx.addOperation(new AddOperation(refs));
    } else {
        // This will use the same thread if there are no pending operations
        // avoiding a context switch on this case
        storageManager.afterCompleteOperations(new IOCallback() {

            @Override
            public void onError(final int errorCode, final String errorMessage) {
                ActiveMQServerLogger.LOGGER.ioErrorAddingReferences(errorCode, errorMessage);
            }

            @Override
            public void done() {
                addReferences(refs, direct);
            }
        });
    }
}
Also used : ArrayList(java.util.ArrayList) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) MessageReference(org.apache.activemq.artemis.core.server.MessageReference) IOCallback(org.apache.activemq.artemis.core.io.IOCallback) Transaction(org.apache.activemq.artemis.core.transaction.Transaction) RouteContextList(org.apache.activemq.artemis.core.server.RouteContextList) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) PagingStore(org.apache.activemq.artemis.core.paging.PagingStore) Queue(org.apache.activemq.artemis.core.server.Queue)

Example 40 with MessageReference

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

the class PostOfficeImpl method reroute.

@Override
public MessageReference reroute(final Message message, final Queue queue, final Transaction tx) throws Exception {
    setPagingStore(queue.getAddress(), message);
    MessageReference reference = MessageReference.Factory.createReference(message, queue);
    Long scheduledDeliveryTime = message.getScheduledDeliveryTime();
    if (scheduledDeliveryTime != null) {
        reference.setScheduledDeliveryTime(scheduledDeliveryTime);
    }
    message.incrementDurableRefCount();
    message.incrementRefCount();
    if (tx == null) {
        queue.reload(reference);
    } else {
        List<MessageReference> refs = new ArrayList<>(1);
        refs.add(reference);
        tx.addOperation(new AddOperation(refs));
    }
    return reference;
}
Also used : ArrayList(java.util.ArrayList) MessageReference(org.apache.activemq.artemis.core.server.MessageReference)

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