Search in sources :

Example 1 with RouteContextList

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

the class RoutingContextImpl method addQueueWithAck.

@Override
public void addQueueWithAck(SimpleString address, Queue queue) {
    addQueue(address, queue);
    RouteContextList listing = getContextListing(address);
    listing.addAckedQueue(queue);
}
Also used : RouteContextList(org.apache.activemq.artemis.core.server.RouteContextList)

Example 2 with RouteContextList

use of org.apache.activemq.artemis.core.server.RouteContextList 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 3 with RouteContextList

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

the class RoutingContextImpl method getContextListing.

@Override
public RouteContextList getContextListing(SimpleString address) {
    RouteContextList listing = map.get(address);
    if (listing == null) {
        listing = new ContextListing();
        map.put(address, listing);
    }
    return listing;
}
Also used : RouteContextList(org.apache.activemq.artemis.core.server.RouteContextList)

Example 4 with RouteContextList

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

the class RoutingContextImpl method addQueue.

@Override
public void addQueue(final SimpleString address, final Queue queue) {
    RouteContextList listing = getContextListing(address);
    if (queue.isDurableMessage()) {
        listing.getDurableQueues().add(queue);
    } else {
        listing.getNonDurableQueues().add(queue);
    }
    queueCount++;
}
Also used : RouteContextList(org.apache.activemq.artemis.core.server.RouteContextList)

Aggregations

RouteContextList (org.apache.activemq.artemis.core.server.RouteContextList)4 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)1 IOCallback (org.apache.activemq.artemis.core.io.IOCallback)1 PagingStore (org.apache.activemq.artemis.core.paging.PagingStore)1 MessageReference (org.apache.activemq.artemis.core.server.MessageReference)1 Queue (org.apache.activemq.artemis.core.server.Queue)1 Transaction (org.apache.activemq.artemis.core.transaction.Transaction)1