Skip to content

Commit

Permalink
Skip removed/re-added messages when scheduling new renewal
Browse files Browse the repository at this point in the history
  • Loading branch information
mziccard committed Jun 1, 2016
1 parent d4b8f6c commit 501ba7d
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,19 @@ private void unsetAndScheduleNextRenewal() {
private void scheduleNextRenewal() {
// Schedules next renewal if there are still messages to process and no renewals scheduled that
// could handle them, otherwise does nothing
Message nextMessage;
synchronized (lock) {
Message peek = messageQueue.peek();
// We remove from the queue messages that were removed from the ack deadline renewer (and
// possibly re-added)
while (peek != null && (!messageDeadlines.containsKey(peek.messageId())
|| messageDeadlines.get(peek.messageId()) > peek.expectedDeadline())) {
messageQueue.poll();
peek = messageQueue.peek();
}
nextMessage = peek;
}
synchronized (futureLock) {
Message nextMessage = messageQueue.peek();
if (renewerFuture == null && nextMessage != null) {
long delay =
(nextMessage.expectedDeadline() - clock.millis()) - NEXT_RENEWAL_THRESHOLD_MILLIS;
Expand Down

0 comments on commit 501ba7d

Please sign in to comment.