*/
protected void deliverMessages(int index) {
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, "Queue.deliverMessages(" + index + ')');
ReceiveRequest notRec = null;
Message message;
QueueMsgReply notMsg;
List lsMessages = null;
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, " -> requests = " + requests + ')');
long current = System.currentTimeMillis();
cleanWaitingRequest(current);
// Cleaning the possibly expired messages.
DMQManager dmqManager = cleanPendingMessage(current);
// Processing each request as long as there are deliverable messages:
while (! messages.isEmpty() && index < requests.size()) {
notRec = (ReceiveRequest) requests.get(index);
notMsg = new QueueMsgReply(notRec);
lsMessages = getMessages(notRec.getMessageCount(), notRec.getSelector(), notRec.getAutoAck());
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, "Queue.deliverMessages: notRec.getAutoAck() = " + notRec.getAutoAck()
+ ", lsMessages = " + lsMessages);
Iterator itMessages = lsMessages.iterator();
while (itMessages.hasNext()) {
message = (Message) itMessages.next();
notMsg.addMessage(message.getFullMessage());
if (!notRec.getAutoAck()) {
// putting the message in the delivered messages table:
consumers.put(message.getIdentifier(), notRec.requester);
contexts.put(message.getIdentifier(),
new Integer(notRec.getClientContext()));
deliveredMsgs.put(message.getIdentifier(), message);
messages.remove(message);
}
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG,
"Message " + message.getIdentifier() + " to " + notRec.requester +
" as reply to " + notRec.getRequestId());
}
if (isLocal(notRec.requester)) {
notMsg.setPersistent(false);
}
if (notMsg.isPersistent() && !notRec.getAutoAck()) {
// state change, so save.
setSave();
}
// Next request: