{
ReferenceInfo info = (ReferenceInfo) iter.next();
long msgId = info.getMessageId();
MessageReference ref = ms.reference(msgId);
if (ref != null)
{
refMap.put(new Long(msgId), ref);
}
else
{
// Add id to list of msg ids to load
msgIdsToLoad.add(new Long(msgId));
}
}
// Load the messages (if any)
List messages = null;
if (!msgIdsToLoad.isEmpty())
{
messages = pm.getMessages(msgIdsToLoad);
if (messages.size() != msgIdsToLoad.size())
{
// Sanity check
throw new IllegalStateException("Did not load correct number of messages, wanted:" +
msgIdsToLoad.size() + " but got:" +
messages.size());
}
// Create references for these messages and add them to the reference map
iter = messages.iterator();
while (iter.hasNext())
{
Message m = (Message)iter.next();
// Message might actually be know to the store since we did the
// first check since might have been added by different channel
// in intervening period, but this is ok - the store knows to only
// return a reference to the pre-existing message
MessageReference ref = ms.reference(m);
refMap.put(new Long(m.getMessageID()), ref);
}
}