AMQ-6947 - Update Queue metrics on expiration

The updated dropMessage method only decrements the destination metrics
if a message is removed from the pagedInMessages list to prevent
duplicate updates.  There is also a case where we still need to update
metrics if the message never makes it into the pagedInMessages list in
the first place and that is on expiration so this patch fixes that. A
couple existing tests found this issue.

(cherry picked from commit 6e468b4540)
This commit is contained in:
Christopher L. Shannon (cshannon) 2018-04-18 09:04:11 -04:00
parent 1fe096cb2a
commit bca0af4133
1 changed files with 11 additions and 2 deletions

View File

@ -1842,8 +1842,7 @@ public class Queue extends BaseDestination implements Task, UsageListener, Index
pagedInMessagesLock.writeLock().lock();
try {
if (pagedInMessages.remove(reference) != null) {
getDestinationStatistics().getDequeues().increment();
getDestinationStatistics().getMessages().decrement();
updateMetricsOnMessageDrop();
}
} finally {
pagedInMessagesLock.writeLock().unlock();
@ -1851,6 +1850,11 @@ public class Queue extends BaseDestination implements Task, UsageListener, Index
}
}
private void updateMetricsOnMessageDrop() {
getDestinationStatistics().getDequeues().increment();
getDestinationStatistics().getMessages().decrement();
}
public void messageExpired(ConnectionContext context, MessageReference reference) {
messageExpired(context, null, reference);
}
@ -2007,6 +2011,11 @@ public class Queue extends BaseDestination implements Task, UsageListener, Index
if (processExpired && ref.isExpired()) {
if (broker.isExpired(ref)) {
messageExpired(createConnectionContext(), ref);
//We need to update the metrics here because the drop message
//method will only update if the message was removed from the
//pagedInMessages list which won't happen in this case
updateMetricsOnMessageDrop();
} else {
ref.decrementReferenceCount();
}