jsmucr commented on code in PR #4752:
URL: https://github.com/apache/activemq-artemis/pull/4752#discussion_r1462744923


##########
artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ScheduledDeliveryHandlerImpl.java:
##########
@@ -188,6 +194,34 @@ private void scheduleDelivery(final long deliveryTime) {
       }
    }
 
+   protected void notifyScheduledReferencesUpdated() {
+      oldestMessage = null;
+   }
+
+   @Override
+   public MessageReference peekFirstScheduledMessage() {
+      synchronized (scheduledReferences) {
+         if (scheduledReferences.isEmpty()) {
+            return null;
+         }
+         if (oldestMessage != null) {
+            return oldestMessage;
+         }
+         MessageReference result = null;
+         long oldestTimestamp = Long.MAX_VALUE;
+         for (RefScheduled scheduledReference : scheduledReferences) {
+            MessageReference ref = scheduledReference.getRef();
+            long refTimestamp = ref.getMessage().getTimestamp();
+            if (refTimestamp < oldestTimestamp) {
+               oldestTimestamp = refTimestamp;
+               result = ref;
+            }
+         }
+         oldestMessage = result;
+         return result;
+      }
+   }

Review Comment:
   The `MessageReferenceComparator` uses scheduled delivery time as a measure, 
so if I'm not mistaken, `scheduledReferences.first()` returns the first message 
to be delivered, not the oldest message in the queue.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to