}
packetlistAdd(pr.getSysMessageID(), pr.getDestinationUID());
Set l = null;
if ((l = (Set)m.get(dUID)) == null) {
l = new TreeSet(new RefCompare());
m.put(dUID, l);
}
l.add(pr);
}
// OK, handle determining how to queue the messages
// first add all messages
Iterator dsts = m.entrySet().iterator();
while (dsts.hasNext()) {
Map.Entry entry = (Map.Entry)dsts.next();
DestinationUID dst = (DestinationUID) entry.getKey();
Set l = (Set)entry.getValue();
Destination d = Destination.getDestination(dst);
if (d == null) { // create it
try {
d = Destination.getDestination(dst.getName(),
(dst.isQueue()? DestType.DEST_TYPE_QUEUE:
DestType.DEST_TYPE_TOPIC) , true, true);
} catch (IOException ex) {
throw new BrokerException(
Globals.getBrokerResources().getKString(
BrokerResources.X_CANT_LOAD_DEST, d.getName()));
}
} else {
synchronized(d) {
if (d.isLoaded()) {
// Destination has already been loaded so just called
// initialize() to update the size and bytes variables
d.initialize();
}
d.load(l);
}
}
logger.log(Logger.INFO,
BrokerResources.I_LOADING_DST,
d.getName(), String.valueOf(l.size()));
// now we're sorted, process
Iterator litr = l.iterator();
try {
while (litr.hasNext()) {
PacketReference pr = (PacketReference)litr.next();
try {
// ok allow overrun
boolean el = d.destMessages.getEnforceLimits();
d.destMessages.enforceLimits(false);
pr.lock();
d.putMessage(pr, AddReason.LOADED, true);
// turn off overrun
d.destMessages.enforceLimits(el);
} catch (IllegalStateException ex) {
// thats ok, we already exists
String args[] = { pr.getSysMessageID().toString(),
pr.getDestinationUID().toString(),
ex.getMessage() };
logger.logStack(Logger.WARNING,
BrokerResources.W_CAN_NOT_LOAD_MSG,
args, ex);
continue;
} catch (OutOfLimitsException ex) {
String args[] = { pr.getSysMessageID().toString(),
pr.getDestinationUID().toString(),
ex.getMessage() };
logger.logStack(Logger.WARNING,
BrokerResources.W_CAN_NOT_LOAD_MSG,
args, ex);
continue;
}
}
// then resort the destination
d.sort(new RefCompare());
} catch (Exception ex) {
}
}
// now route