}
if (ref.getDestinationUID().isWildcard()) {
dsts = Destination.findMatchingIDs(ref.getDestinationUID());
} else {
// ok, autocreate the destination if necessary
Destination d = Destination.getDestination(
ref.getDestinationUID().getName(),
ref.getDestinationUID().isQueue() ? DestType.DEST_TYPE_QUEUE
: DestType.DEST_TYPE_TOPIC, true, true);
if (d != null) {
dsts = new ArrayList();
dsts.add(d.getDestinationUID());
}
}
if (dsts == null || dsts.isEmpty()) {
ignoreVector.addAll(targetVector);
targetVector.clear();
} else {
if (!exists && !targetVector.isEmpty()) {
ref.setNeverStore(true);
// OK .. we dont need to route .. its already happened
ref.store(targetVector);
boolean enforcelimit = false;
itr = dsts.iterator();
while (itr.hasNext()) {
DestinationUID did = (DestinationUID)itr.next();
Destination d = Destination.getDestination(did);
if (!hasflowcontrol) {
enforcelimit = true;
} else {
String k = ENFORCE_REMOTE_DEST_LIMIT_PROP+did.getLongString();
if (Globals.getConfig().getProperty(k) == null) {
enforcelimit = ENFORCE_REMOTE_DEST_LIMIT;
} else {
enforcelimit = Globals.getConfig().getBooleanProperty(k);
}
}
if (DEBUG) {
logger.log(logger.INFO, "Route remote message "+ref+ " sent from "+sender+
" to destination(s) "+did+" for consumer(s) "+targetVector+" hasflowcontrol="+
hasflowcontrol+", enforcelimit="+enforcelimit);
}
if ((Destination.CHECK_MSGS_RATE_FOR_ALL ||
!ref.getDestinationUID().isQueue()) && !ROUTE_REJECTED_REMOTE_MSG) {
Consumer cs = null;
Subscription sub = null;
Iterator csitr = targetVector.iterator();
while (csitr.hasNext()) {
cs = (Consumer)csitr.next();
sub = cs.getSubscription();
if (Destination.CHECK_MSGS_RATE_FOR_ALL ||
(CHECK_MSGRATE_ON_ARRIVAL &&
sub != null && sub.getShared() && !sub.isDurable())) {
int ret = cs.checkIfMsgsInRateGTOutRate(d);
if (ret == 0) {
ignoreVector.addAll(targetVector);
targetVector.clear();
ignoreProps = ignoreUnroutableProp;
break;
}
}
}
if (targetVector.isEmpty()) {
break;
}
}
if (!d.queueMessage(ref, false, enforcelimit)) { // add to message count
ignoreVector.addAll(targetVector);
if (!ROUTE_REJECTED_REMOTE_MSG) {
targetVector.clear();
}
break;
} else {
cleanupDests.add(d);
}
}
} else if (exists) {
ref.add(targetVector);
}
}
} catch (IOException ex) {
logger.logStack(logger.INFO,"Internal Exception ", ex);
ignoreVector.addAll(targetVector);
if (!ROUTE_REJECTED_REMOTE_MSG) {
targetVector.clear();
ignoreProps = ignoreUnroutableProp;
}
} catch (BrokerException ex) {
// unable to store
ignoreVector.addAll(targetVector);
if (!ROUTE_REJECTED_REMOTE_MSG) {
targetVector.clear();
ignoreProps = ignoreUnroutableProp;
}
}
if (targetVector.isEmpty()) {
Destination d = null;
itr = cleanupDests.iterator();
while (itr.hasNext()) {
try {
d = (Destination)itr.next();
d.removeMessage(ref.getSysMessageID(), null);
} catch (Throwable e) {
Object[] args = { ref.getSysMessageID(),
(sender == null ? "":sender),
d, targetVector.toString(), e.toString() };
String emsg = Globals.getBrokerResources().getKString(
BrokerResources.W_UNABLE_CLEANUP_REMOTE_MSG_ON_ROUTE, args);
if (DEBUG) {
logger.logStack(Logger.WARNING, emsg, e);
} else {
logger.log(Logger.WARNING, emsg);
}
}
}
cleanupDests.clear();
}
// Now deliver the message...
String debugString = "\n";
int i;
for (i = 0; i < targetVector.size(); i++) {
Consumer interest = (Consumer)targetVector.get(i);
if (!interest.routeMessage(ref, false)) {
// it disappeard on us, take care of it
try {
if (ref.acknowledged(interest.getConsumerUID(),
interest.getStoredConsumerUID(), true, false)) {
if (dsts == null) continue;
itr = dsts.iterator();
while (itr.hasNext()) {
DestinationUID did = (DestinationUID)itr.next();
Destination d=Destination.getDestination(did);
d.removeRemoteMessage(ref.getSysMessageID(),
RemoveReason.ACKNOWLEDGED, ref);
}
}
} catch (Exception ex) {
logger.log(logger.INFO,"Internal error processing ack",
ex);
}
} else {
ref.addRemoteConsumerUID(interest.getConsumerUID(),
interest.getConsumerUID().getConnectionUID());
}
if (DEBUG) {
debugString = debugString +
"\t" + interest.getConsumerUID() + "\n";
}
}
if (DEBUG) {
logger.log(logger.DEBUGHIGH,
"MessageBus: Delivering message to : {0}",
debugString);
}
debugString = "\n";
// Finally, send ClusterGlobals.MB_MSG_IGNORED acks if any...
Object o = null;
ConsumerUID cuid = null;
Consumer interest = null;
for (i = 0; i < ignoreVector.size(); i++) {
try {
o = ignoreVector.get(i);
if (o instanceof Consumer) {
cuid = ((Consumer)o).getConsumerUID();
interest = (Consumer)o;
} else {
cuid = (ConsumerUID)o;
interest = Consumer.getConsumer(cuid);
}
if (interest != null && dsts != null && ignoreProps == ignoreUnroutableProp) {
long msgoutt = 0, t = 0;
Destination d = null;
Iterator ditr = dsts.iterator();
while (ditr.hasNext()) {
d = Destination.findDestination((DestinationUID)ditr.next());
if (d == null) {
continue;