protected void cleanPendingMessages(long currentTime) {
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, "UserAgent.cleanPendingMessages(" + messagesTable.size() + ')');
Message message = null;
DMQManager dmqManager = null;
for (Iterator values = messagesTable.values().iterator(); values.hasNext();) {
message = (Message) values.next();
if ((message == null) || message.isValid(currentTime))
continue;
values.remove();
if (message.durableAcksCounter > 0)
message.delete();
if (dmqManager == null)
dmqManager = new DMQManager(dmqId, null);
nbMsgsSentToDMQSinceCreation++;
dmqManager.addDeadMessage(message.getFullMessage(), MessageErrorConstants.EXPIRED);
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, "UserAgent expired message " + message.getIdentifier());
}
Iterator subs = subsTable.values().iterator();
while (subs.hasNext()) {
((ClientSubscription) subs.next()).cleanMessageIds();
}
// If needed, sending the dead messages to the DMQ:
if (dmqManager != null)
dmqManager.sendToDMQ();
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, "UserAgent.cleanPendingMessages -> " + messagesTable.size());
}