Search in sources :

Example 71 with MessageReference

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

the class QueueImpl method changeReferencePriority.

@Override
public synchronized boolean changeReferencePriority(final long messageID, final byte newPriority) throws Exception {
    try (LinkedListIterator<MessageReference> iter = iterator()) {
        while (iter.hasNext()) {
            MessageReference ref = iter.next();
            if (ref.getMessage().getMessageID() == messageID) {
                iter.remove();
                refRemoved(ref);
                ref.getMessage().setPriority(newPriority);
                addTail(ref, false);
                return true;
            }
        }
        return false;
    }
}
Also used : MessageReference(org.apache.activemq.artemis.core.server.MessageReference)

Example 72 with MessageReference

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

the class QueueImpl method deliverScheduledMessages.

@Override
public void deliverScheduledMessages() throws ActiveMQException {
    List<MessageReference> scheduledMessages = scheduledDeliveryHandler.cancel(null);
    if (scheduledMessages != null && scheduledMessages.size() > 0) {
        for (MessageReference ref : scheduledMessages) {
            ref.getMessage().setScheduledDeliveryTime(ref.getScheduledDeliveryTime());
            ref.setScheduledDeliveryTime(0);
        }
        this.addHead(scheduledMessages, true);
    }
}
Also used : MessageReference(org.apache.activemq.artemis.core.server.MessageReference)

Example 73 with MessageReference

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

the class ScaleDownHandler method scaleDownRegularMessages.

public long scaleDownRegularMessages(final SimpleString address, final Set<Queue> queues, final ClientSession clientSession, final ClientProducer producer) throws Exception {
    logger.debug("Scaling down messages on address " + address);
    long messageCount = 0;
    final HashMap<Queue, QueuesXRefInnerManager> controls = new HashMap<>();
    PagingStore pageStore = pagingManager.getPageStore(address);
    Transaction tx = new TransactionImpl(storageManager);
    pageStore.disableCleanup();
    try {
        for (Queue queue : queues) {
            controls.put(queue, new QueuesXRefInnerManager(clientSession, queue, pageStore));
        }
        // compile a list of all the relevant queues and queue iterators for this address
        for (Queue loopQueue : queues) {
            logger.debug("Scaling down messages on address " + address + " / performing loop on queue " + loopQueue);
            try (LinkedListIterator<MessageReference> messagesIterator = loopQueue.browserIterator()) {
                while (messagesIterator.hasNext()) {
                    MessageReference messageReference = messagesIterator.next();
                    Message message = messageReference.getMessage().copy();
                    logger.debug("Reading message " + message + " from queue " + loopQueue);
                    Set<QueuesXRefInnerManager> queuesFound = new HashSet<>();
                    for (Map.Entry<Queue, QueuesXRefInnerManager> controlEntry : controls.entrySet()) {
                        if (controlEntry.getKey() == loopQueue) {
                            // no need to lookup on itself, we just add it
                            queuesFound.add(controlEntry.getValue());
                        } else if (controlEntry.getValue().lookup(messageReference)) {
                            logger.debug("Message existed on queue " + controlEntry.getKey().getID() + " removeID=" + controlEntry.getValue().getQueueID());
                            queuesFound.add(controlEntry.getValue());
                        }
                    }
                    // get the ID for every queue that contains the message
                    ByteBuffer buffer = ByteBuffer.allocate(queuesFound.size() * 8);
                    for (QueuesXRefInnerManager control : queuesFound) {
                        long queueID = control.getQueueID();
                        buffer.putLong(queueID);
                    }
                    message.putBytesProperty(Message.HDR_ROUTE_TO_IDS.toString(), buffer.array());
                    if (logger.isDebugEnabled()) {
                        if (messageReference.isPaged()) {
                            logger.debug("*********************<<<<< Scaling down pdgmessage " + message);
                        } else {
                            logger.debug("*********************<<<<< Scaling down message " + message);
                        }
                    }
                    producer.send(address, message);
                    messageCount++;
                    messagesIterator.remove();
                    // We need to perform the ack / removal after sending, otherwise the message could been removed before the send is finished
                    for (QueuesXRefInnerManager queueFound : queuesFound) {
                        ackMessageOnQueue(tx, queueFound.getQueue(), messageReference);
                    }
                }
            } catch (NoSuchElementException ignored) {
            // this could happen through paging browsing
            }
        }
        tx.commit();
        for (QueuesXRefInnerManager controlRemoved : controls.values()) {
            controlRemoved.close();
        }
        return messageCount;
    } finally {
        pageStore.enableCleanup();
        pageStore.getCursorProvider().scheduleCleanup();
    }
}
Also used : ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) Message(org.apache.activemq.artemis.api.core.Message) HashMap(java.util.HashMap) TransactionImpl(org.apache.activemq.artemis.core.transaction.impl.TransactionImpl) MessageReference(org.apache.activemq.artemis.core.server.MessageReference) ByteBuffer(java.nio.ByteBuffer) Transaction(org.apache.activemq.artemis.core.transaction.Transaction) Queue(org.apache.activemq.artemis.core.server.Queue) PagingStore(org.apache.activemq.artemis.core.paging.PagingStore) HashMap(java.util.HashMap) Map(java.util.Map) NoSuchElementException(java.util.NoSuchElementException) HashSet(java.util.HashSet)

Example 74 with MessageReference

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

the class ScheduledDeliveryHandlerImpl method cancel.

@Override
public List<MessageReference> cancel(final Filter filter) throws ActiveMQException {
    List<MessageReference> refs = new ArrayList<>();
    synchronized (scheduledReferences) {
        Iterator<RefScheduled> iter = scheduledReferences.iterator();
        while (iter.hasNext()) {
            MessageReference ref = iter.next().getRef();
            if (filter == null || filter.match(ref.getMessage())) {
                iter.remove();
                refs.add(ref);
                metrics.decrementMetrics(ref);
            }
        }
    }
    return refs;
}
Also used : ArrayList(java.util.ArrayList) MessageReference(org.apache.activemq.artemis.core.server.MessageReference)

Example 75 with MessageReference

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

the class ServerSessionImpl method doRollback.

private void doRollback(final boolean clientFailed, final boolean lastMessageAsDelived, final Transaction theTx) throws Exception {
    boolean wasStarted = started;
    List<MessageReference> toCancel = new ArrayList<>();
    for (ServerConsumer consumer : consumers.values()) {
        if (wasStarted) {
            consumer.setStarted(false);
        }
        toCancel.addAll(consumer.cancelRefs(clientFailed, lastMessageAsDelived, theTx));
    }
    // we add them to a new tx and roll them back as the calling client will assume that this has happened.
    if (theTx.getState() == State.ROLLEDBACK) {
        Transaction newTX = newTransaction();
        cancelAndRollback(clientFailed, newTX, wasStarted, toCancel);
    } else {
        cancelAndRollback(clientFailed, theTx, wasStarted, toCancel);
    }
}
Also used : Transaction(org.apache.activemq.artemis.core.transaction.Transaction) ArrayList(java.util.ArrayList) MessageReference(org.apache.activemq.artemis.core.server.MessageReference) ServerConsumer(org.apache.activemq.artemis.core.server.ServerConsumer)

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