Search in sources :

Example 1 with MessageDeletedException

use of org.apache.qpid.server.message.MessageDeletedException 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 2 with MessageDeletedException

use of org.apache.qpid.server.message.MessageDeletedException 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)

Example 3 with MessageDeletedException

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

the class AbstractQueue method getOldestMessageArrivalTime.

@Override
public long getOldestMessageArrivalTime() {
    long oldestMessageArrivalTime = -1L;
    while (oldestMessageArrivalTime == -1L) {
        QueueEntryList entries = getEntries();
        QueueEntry entry = entries == null ? null : entries.getOldestEntry();
        if (entry != null) {
            ServerMessage message = entry.getMessage();
            if (message != null) {
                try (MessageReference reference = message.newReference()) {
                    oldestMessageArrivalTime = reference.getMessage().getArrivalTime();
                } catch (MessageDeletedException e) {
                // ignore - the oldest message was deleted after it was discovered - we need to find the new oldest message
                }
            }
        } else {
            oldestMessageArrivalTime = 0;
        }
    }
    return oldestMessageArrivalTime;
}
Also used : MessageDeletedException(org.apache.qpid.server.message.MessageDeletedException) ServerMessage(org.apache.qpid.server.message.ServerMessage) MessageReference(org.apache.qpid.server.message.MessageReference)

Aggregations

MessageDeletedException (org.apache.qpid.server.message.MessageDeletedException)3 MessageReference (org.apache.qpid.server.message.MessageReference)3 ServerMessage (org.apache.qpid.server.message.ServerMessage)3 HashSet (java.util.HashSet)1