if (duids.size() == 0) {
route = false; // nothing to do
} else {
Iterator itr = duids.iterator();
while (itr.hasNext()) {
PacketReference ref = null;
Exception lastthr = null;
boolean isLast = false;
DestinationUID duid = (DestinationUID)itr.next();
isLast = !itr.hasNext();
Destination d = Destination.getDestination(duid);
try {
if (d == null) {
throw new BrokerException("Unknown Destination:" + msg.getDestination());
}
if (realduid.isWildcard() && d.isTemporary()) {
logger.log(Logger.DEBUG,"L10N-XXX: Wildcard production with destination name of "
+ realduid + " to temporary destination " +
d.getUniqueName() + " is not supported, ignoring");
continue;
}
if (realduid.isWildcard() && d.isInternal()) {
logger.log(Logger.DEBUG,"L10N-XXX: Wildcard production with destination name of "
+ realduid + " to internal destination " +
d.getUniqueName() + " is not supported, ignoring");
continue;
}
if (realduid.isWildcard() && d.isDMQ() ) {
logger.log(Logger.DEBUG,"L10N-XXX: Wildcard production with destination name of "
+ realduid + " to the DeadMessageQueue" +
d.getUniqueName() + " is not supported, ignoring");
continue;
}
if (pausedProducer != null) {
pauseProducer(d, duid, pausedProducer, con);
pausedProducer = null;
}
if (packetUsed) {
// create a new Packet for the message
// we need a new sysmsgid with it
Packet newp = new Packet();
newp.fill(msg);
newp.generateSequenceNumber(true);
newp.generateTimestamp(true);
newp.prepareToSend();
newp.generateSequenceNumber(false);
newp.generateTimestamp(false);
msg = newp;
}
packetUsed = true;
// OK generate a ref. This checks message size and
// will be needed for later operations
ref = createReference(msg, duid, con, isadmin);
// dont bother calling route if there are no messages
//
// to improve performance, we route and later forward
route |= queueMessage(d, ref, transacted);
// ok ...
if (isLast && route && ack && !ref.isPersistent()) {
sendAcknowledge(refid, cid, status, con, reason, props, transacted);
ack = false;
}
Set s = routeMessage(transacted, ref, route, d);
if (s != null && ! s.isEmpty()) {
if (routedSet == null)
routedSet = new HashMap();
routedSet.put(ref, s);
}
// handle producer flow control
pauseProducer(d, duid, pausedProducer, con);
} catch (Exception ex) {
if (ref != null) {
if (failedrefs == null)
failedrefs = new ArrayList();
failedrefs.add(ref);
}
lastthr = ex;
logger.log(Logger.DEBUG, BrokerResources.W_MESSAGE_STORE_FAILED,
con.toString(), ex);
} finally {
if (pausedProducer != null) {
pauseProducer(d, duid, pausedProducer, con);
pausedProducer = null;
}
if (isLast && lastthr != null) {
throw lastthr;
}
}
} //while
}
} catch (BrokerException ex) {
// dont log on dups if indemponent
int loglevel = (isIndemp && ex.getStatusCode()
== Status.NOT_MODIFIED) ? Logger.DEBUG
: Logger.WARNING;
logger.log(loglevel,
BrokerResources.W_MESSAGE_STORE_FAILED,
con.toString(), ex);
reason = ex.getMessage();
//LKS - we may want an improved error message in the wildcard case
status = ex.getStatusCode();
} catch (IOException ex) {
logger.log(Logger.WARNING, BrokerResources.W_MESSAGE_STORE_FAILED,
con.toString(), ex);
reason = ex.getMessage();
status = Status.ERROR;
} catch (SecurityException ex) {
logger.log(Logger.WARNING, BrokerResources.W_MESSAGE_STORE_FAILED,
con.toString(), ex);
reason = ex.getMessage();
status = Status.FORBIDDEN;
} catch (OutOfMemoryError err) {
logger.logStack(Logger.WARNING, BrokerResources.W_MESSAGE_STORE_FAILED,
con.toString() + ":" + msg.getPacketSize(), err);
reason = err.getMessage();
status = Status.ERROR;
} catch (Exception ex) {
logger.logStack(Logger.WARNING, BrokerResources.W_MESSAGE_STORE_FAILED,
con.toString(), ex);
reason = ex.getMessage();
status = Status.ERROR;
}
if (status == Status.ERROR && failedrefs != null ) {
// make sure we remove the message
//
// NOTE: we only want to remove the last failure (its too late
// for the rest). In the non-wildcard case, this will be the
// only entry. In the wildcard cause, it will be the one that had an issue
Iterator itr = failedrefs.iterator();
while (itr.hasNext()) {
PacketReference ref = (PacketReference)itr.next();
Destination d = Destination.getDestination(ref.getDestinationUID());
if (d != null)
cleanupOnError(d, ref);
}
}
if (ack)
sendAcknowledge(refid, cid, status, con, reason, props, transacted);
if (route && routedSet != null) {
Iterator itr = routedSet.keySet().iterator();
while (itr.hasNext()) {
PacketReference pktref = (PacketReference)itr.next();
DestinationUID duid = pktref.getDestinationUID();
Destination dest = Destination.getDestination(duid);
Set s = (Set)routedSet.get(pktref);
forwardMessage(dest, pktref, s);
}
}