Search in sources :

Example 51 with ServerMessage

use of org.apache.qpid.server.message.ServerMessage in project qpid-broker-j by apache.

the class ManagementNode method enqueue.

@Override
public void enqueue(final ServerMessage message, final Action<? super MessageInstance> action, final MessageEnqueueRecord record) {
    @SuppressWarnings("unchecked") MessageConverter<ServerMessage, InternalMessage> converter = (MessageConverter<ServerMessage, InternalMessage>) MessageConverterRegistry.getConverter((message.getClass()), InternalMessage.class);
    final InternalMessage msg = converter.convert(message, _addressSpace);
    try {
        if (action != null) {
            action.performAction(new ConsumedMessageInstance(msg));
        }
        processRequest(msg);
    } finally {
        converter.dispose(msg);
    }
}
Also used : InternalMessage(org.apache.qpid.server.message.internal.InternalMessage) ServerMessage(org.apache.qpid.server.message.ServerMessage) MessageConverter(org.apache.qpid.server.plugin.MessageConverter)

Example 52 with ServerMessage

use of org.apache.qpid.server.message.ServerMessage in project qpid-broker-j by apache.

the class AMQChannel method deadLetter.

private void deadLetter(long deliveryTag) {
    final UnacknowledgedMessageMap unackedMap = getUnacknowledgedMessageMap();
    final MessageConsumerAssociation association = unackedMap.remove(deliveryTag, true);
    if (association == null) {
        LOGGER.warn("No message found, unable to DLQ delivery tag: " + deliveryTag);
    } else {
        final MessageInstance messageInstance = association.getMessageInstance();
        final ServerMessage msg = messageInstance.getMessage();
        int requeues = 0;
        if (messageInstance.makeAcquisitionUnstealable(association.getConsumer())) {
            requeues = messageInstance.routeToAlternate(new Action<MessageInstance>() {

                @Override
                public void performAction(final MessageInstance requeueEntry) {
                    messageWithSubject(ChannelMessages.DEADLETTERMSG(msg.getMessageNumber(), requeueEntry.getOwningResource().getName()));
                }
            }, null);
        }
        if (requeues == 0) {
            final TransactionLogResource owningResource = messageInstance.getOwningResource();
            if (owningResource instanceof Queue) {
                final Queue<?> queue = (Queue<?>) owningResource;
                final MessageDestination alternateBindingDestination = queue.getAlternateBindingDestination();
                if (alternateBindingDestination == null) {
                    messageWithSubject(ChannelMessages.DISCARDMSG_NOALTEXCH(msg.getMessageNumber(), queue.getName(), msg.getInitialRoutingAddress()));
                } else {
                    messageWithSubject(ChannelMessages.DISCARDMSG_NOROUTE(msg.getMessageNumber(), alternateBindingDestination.getName()));
                }
            }
        }
    }
}
Also used : MessageInstance(org.apache.qpid.server.message.MessageInstance) PrivilegedAction(java.security.PrivilegedAction) Action(org.apache.qpid.server.util.Action) MessageDestination(org.apache.qpid.server.message.MessageDestination) ServerMessage(org.apache.qpid.server.message.ServerMessage) TransactionLogResource(org.apache.qpid.server.store.TransactionLogResource) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) Queue(org.apache.qpid.server.model.Queue)

Example 53 with ServerMessage

use of org.apache.qpid.server.message.ServerMessage in project qpid-broker-j by apache.

the class ReportRunnerTest method createMockMessageForQueue.

protected ServerMessage createMockMessageForQueue() {
    final ServerMessage message = mock(ServerMessage.class);
    final AMQMessageHeader header = mock(AMQMessageHeader.class);
    when(message.getMessageHeader()).thenReturn(header);
    when(message.getContent()).thenReturn(QpidByteBuffer.emptyQpidByteBuffer());
    return message;
}
Also used : ServerMessage(org.apache.qpid.server.message.ServerMessage) AMQMessageHeader(org.apache.qpid.server.message.AMQMessageHeader)

Example 54 with ServerMessage

use of org.apache.qpid.server.message.ServerMessage in project qpid-broker-j by apache.

the class AbstractQueue method checkMessageStatus.

@Override
public void checkMessageStatus() {
    QueueEntryIterator queueListIterator = getEntries().iterator();
    final Set<NotificationCheck> perMessageChecks = new HashSet<>();
    final Set<NotificationCheck> queueLevelChecks = new HashSet<>();
    for (NotificationCheck check : getNotificationChecks()) {
        if (check.isMessageSpecific()) {
            perMessageChecks.add(check);
        } else {
            queueLevelChecks.add(check);
        }
    }
    QueueNotificationListener listener = _notificationListener;
    final long currentTime = System.currentTimeMillis();
    final long thresholdTime = currentTime - getAlertRepeatGap();
    while (!_stopped.get() && queueListIterator.advance()) {
        final QueueEntry node = queueListIterator.getNode();
        // Only process nodes that are not currently deleted and not dequeued
        if (!node.isDeleted()) {
            // If the node has expired then acquire it
            if (node.expired()) {
                deleteEntry(node, () -> _queueStatistics.addToExpired(node.getSizeWithHeader()));
            } else {
                node.checkHeld(currentTime);
                // There is a chance that the node could be deleted by
                // the time the check actually occurs. So verify we
                // can actually get the message to perform the check.
                ServerMessage msg = node.getMessage();
                if (msg != null) {
                    try (MessageReference messageReference = msg.newReference()) {
                        for (NotificationCheck check : perMessageChecks) {
                            checkForNotification(msg, listener, currentTime, thresholdTime, check);
                        }
                    } catch (MessageDeletedException e) {
                    // Ignore
                    }
                }
            }
        }
    }
    for (NotificationCheck check : queueLevelChecks) {
        checkForNotification(null, listener, currentTime, thresholdTime, check);
    }
}
Also used : MessageDeletedException(org.apache.qpid.server.message.MessageDeletedException) ServerMessage(org.apache.qpid.server.message.ServerMessage) MessageReference(org.apache.qpid.server.message.MessageReference) HashSet(java.util.HashSet)

Example 55 with ServerMessage

use of org.apache.qpid.server.message.ServerMessage in project qpid-broker-j by apache.

the class AbstractQueue method reallocateMessages.

@Override
public void reallocateMessages() {
    QueueEntryIterator queueListIterator = getEntries().iterator();
    while (!_stopped.get() && queueListIterator.advance()) {
        final QueueEntry node = queueListIterator.getNode();
        if (!node.isDeleted() && !node.expired()) {
            try {
                final ServerMessage message = node.getMessage();
                final MessageReference messageReference = message.newReference();
                try {
                    message.getStoredMessage().reallocate();
                } finally {
                    messageReference.release();
                }
            } catch (MessageDeletedException mde) {
            // Ignore
            }
        }
    }
}
Also used : MessageDeletedException(org.apache.qpid.server.message.MessageDeletedException) ServerMessage(org.apache.qpid.server.message.ServerMessage) MessageReference(org.apache.qpid.server.message.MessageReference)

Aggregations

ServerMessage (org.apache.qpid.server.message.ServerMessage)103 HashMap (java.util.HashMap)26 AMQMessageHeader (org.apache.qpid.server.message.AMQMessageHeader)16 TransactionLogResource (org.apache.qpid.server.store.TransactionLogResource)16 Exchange (org.apache.qpid.server.model.Exchange)14 MessageReference (org.apache.qpid.server.message.MessageReference)13 ArrayList (java.util.ArrayList)9 MessageInstance (org.apache.qpid.server.message.MessageInstance)8 InstanceProperties (org.apache.qpid.server.message.InstanceProperties)7 Queue (org.apache.qpid.server.model.Queue)7 StoredMessage (org.apache.qpid.server.store.StoredMessage)6 MessageEnqueueRecord (org.apache.qpid.server.store.MessageEnqueueRecord)4 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)3 TestConsumerTarget (org.apache.qpid.server.consumer.TestConsumerTarget)3 MessageDeletedException (org.apache.qpid.server.message.MessageDeletedException)3 PrivilegedAction (java.security.PrivilegedAction)2 UUID (java.util.UUID)2 MessageDestination (org.apache.qpid.server.message.MessageDestination)2 MessageInstanceConsumer (org.apache.qpid.server.message.MessageInstanceConsumer)2 RoutingResult (org.apache.qpid.server.message.RoutingResult)2