}
private QueueMessageReference getMatchingMessage(MessageDispatchNotification messageDispatchNotification)
throws Exception {
QueueMessageReference message = null;
MessageId messageId = messageDispatchNotification.getMessageId();
pagedInPendingDispatchLock.writeLock().lock();
try {
for (MessageReference ref : pagedInPendingDispatch) {
if (messageId.equals(ref.getMessageId())) {
message = (QueueMessageReference)ref;
pagedInPendingDispatch.remove(ref);
break;
}
}
} finally {
pagedInPendingDispatchLock.writeLock().unlock();
}
if (message == null) {
pagedInMessagesLock.readLock().lock();
try {
message = pagedInMessages.get(messageId);
} finally {
pagedInMessagesLock.readLock().unlock();
}
}
if (message == null) {
messagesLock.writeLock().lock();
try {
try {
messages.setMaxBatchSize(getMaxPageSize());
messages.reset();
while (messages.hasNext()) {
MessageReference node = messages.next();
messages.remove();
if (messageId.equals(node.getMessageId())) {
message = this.createMessageReference(node.getMessage());
break;
}
}
} finally {