https://issues.apache.org/jira/browse/AMQ-4930 - fix regression in MBeanTest - need to page in up to max messages if they are present for a browse

This commit is contained in:
gtully 2013-12-20 14:39:45 +00:00
parent c50b6c39ba
commit 14d24cca30
1 changed files with 17 additions and 2 deletions

View File

@ -1150,8 +1150,11 @@ public class Queue extends BaseDestination implements Task, UsageListener {
public void doBrowse(List<Message> browseList, int max) {
final ConnectionContext connectionContext = createConnectionContext();
try {
// allow some page in even if we are full and producers are blocked on pfc
pageInMessages(!memoryUsage.isFull(110));
while (shouldPageInMoreForBrowse(max)) {
pageInMessages(!memoryUsage.isFull(110));
};
List<MessageReference> toExpire = new ArrayList<MessageReference>();
pagedInPendingDispatchLock.writeLock().lock();
@ -1198,6 +1201,18 @@ public class Queue extends BaseDestination implements Task, UsageListener {
}
}
private boolean shouldPageInMoreForBrowse(int max) {
pagedInMessagesLock.readLock().lock();
try {
int alreadyPagedIn = pagedInMessages.size();
return alreadyPagedIn < max
&& alreadyPagedIn < getDestinationStatistics().getMessages().getCount()
&& !memoryUsage.isFull(110);
} finally {
pagedInMessagesLock.readLock().unlock();
}
}
private void addAll(Collection<? extends MessageReference> refs, List<Message> l, int max,
List<MessageReference> toExpire) throws Exception {
for (Iterator<? extends MessageReference> i = refs.iterator(); i.hasNext() && l.size() < max;) {