Source:
<code>private synchronized int iterQueue(final int flushLimit, final Filter filter1, QueueIterateAction messageAction, final boolean remove) throws Exception { int count = 0; int txCount = 0; Transaction tx = new TransactionImpl(storageManager); try (LinkedListIterator<MessageReference> iter = iterator()) { while (iter.hasNext()) { MessageReference ref = iter.next(); if (ref.isPaged() && queueDestroyed) { continue; } <START> if (filter1 == null || filter1.match(ref.getMessage())) { <END> messageAction.actMessage(tx, ref); if (remove) { iter.remove(); } txCount++; count++; } } if (txCount > 0) { tx.commit(); tx = new TransactionImpl(storageManager); txCount = 0; } List<MessageReference> cancelled = scheduledDeliveryHandler.cancel(filter1); for (MessageReference messageReference : cancelled) { messageAction.actMessage(tx, messageReference, false); count++; txCount++; } if (txCount > 0) { tx.commit(); tx = new TransactionImpl(storageManager); txCount = 0; } if (pageIterator != null && !queueDestroyed) { while (pageIterator.hasNext()) { PagedReference reference = pageIterator.next(); pageIterator.remove(); if (filter1 == null || filter1.match(reference.getMessage())) { count++; txCount++; messageAction.actMessage(tx, reference, false); } else { addTail(reference, false); } if (txCount > 0 && txCount % flushLimit == 0) { tx.commit(); tx = new TransactionImpl(storageManager); txCount = 0; } } } if (txCount > 0) { tx.commit(); tx = null; } if (filter != null && !queueDestroyed && pageSubscription != null) { scheduleDepage(false); } return count; } }</code><technical_language>Do need check for scheduledDelivery messages (<LINK_0> paged messages (<LINK_1></technical_language>

Target:
private synchronized int iterQueue(final int flushLimit, final Filter filter1, QueueIterateAction messageAction, final boolean remove) throws Exception { int count = 0; int txCount = 0; Transaction tx = new TransactionImpl(storageManager); synchronized (this) { try (LinkedListIterator<MessageReference> iter = iterator()) { while (iter.hasNext()) { MessageReference ref = iter.next(); if (ref.isPaged() && queueDestroyed) { continue; } if (filter1 == null || filter1.match(ref.getMessage())) { messageAction.actMessage(tx, ref); if (remove) { iter.remove(); } txCount++; count++; } } if (txCount > 0) { tx.commit(); tx = new TransactionImpl(storageManager); txCount = 0; } List<MessageReference> cancelled = scheduledDeliveryHandler.cancel(filter1); for (MessageReference messageReference : cancelled) { messageAction.actMessage(tx, messageReference, false); count++; txCount++; } if (txCount > 0) { tx.commit(); tx = new TransactionImpl(storageManager); txCount = 0; } } if (pageIterator != null && !queueDestroyed) { while (pageIterator.hasNext()) { PagedReference reference = pageIterator.next(); pageIterator.remove(); if (filter1 == null || filter1.match(reference.getMessage())) { count++; txCount++; messageAction.actMessage(tx, reference, false); } else { addTail(reference, false); } if (txCount > 0 && txCount % flushLimit == 0) { tx.commit(); tx = new TransactionImpl(storageManager); txCount = 0; } } } if (txCount > 0) { tx.commit(); tx = null; } if (filter != null && !queueDestroyed && pageSubscription != null) { scheduleDepage(false); } return count; } }