try {
enforceLimit = destMessages.getEnforceLimits();
destMessages.enforceLimits(false);
Store store = Globals.getStore();
Enumeration msgs = null;
try {
msgs = store.messageEnumeration(this);
} catch (DestinationNotFoundException e) {
if (noerrnotfound) {
logger.log(Logger.INFO, br.getKString(
BrokerResources.I_LOAD_DST_NOTFOUND_INSTORE,
getName(), e.getMessage()));
return null;
}
throw e;
}
SortedSet s = null;
try { // no other store access should occur in this block
HAMonitorService haMonitor = Globals.getHAMonitorService();
boolean takingoverCheck = (takeoverMsgs == null &&
Globals.getHAEnabled() && haMonitor != null &&
haMonitor.checkTakingoverDestination(this));
s = new TreeSet(new RefCompare());
while (msgs.hasMoreElements()) {
Packet p = (Packet)msgs.nextElement();
PacketReference pr =PacketReference.createReference(p, uid, null);
if (takeoverMsgs != null && takeoverMsgs.contains(pr)) {
pr = null;
continue;
}
if (takingoverCheck && haMonitor.checkTakingoverMessage(p)) {
pr = null;
continue;
}
if (neverExpire)
pr.overrideExpireTime(0);
// mark already stored and make packet a SoftReference to
// prevent running out of memory if dest has lots of msgs
pr.setLoaded();
if (DEBUG) {
logger.log(Logger.INFO,"Loaded Message " + p +
" into destination " + this);
}
try {
if (!isDMQ && !addNewMessage(false, pr)) {
// expired
deadMsgs.add(pr);
}
} catch (Exception ex) {
String args[] = { pr.getSysMessageID().toString(),
pr.getDestinationUID().toString(),
ex.getMessage() };
logger.logStack(Logger.WARNING,
BrokerResources.W_CAN_NOT_LOAD_MSG,
args, ex);
continue;
}
s.add(pr);
packetlistAdd(pr.getSysMessageID(), pr.getDestinationUID());
curcnt ++;
if (curcnt > 0 && (curcnt % LOAD_COUNT == 0
|| (curcnt > LOAD_COUNT && curcnt == size))) {
String args[] = { toString(),
String.valueOf(curcnt),
String.valueOf(maxloadcnt),
String.valueOf((curcnt*100)/maxloadcnt) };
logger.log(Logger.INFO,
BrokerResources.I_LOADING_DEST_IN_PROCESS,
args);
}
}
} finally {
store.closeEnumeration(msgs);
}
// now we're sorted, process
Iterator itr = s.iterator();
while (itr.hasNext()) {
PacketReference pr = (PacketReference)itr.next();
// ok .. see if we need to remove the message
ConsumerUID[] consumers = store.
getConsumerUIDs(getDestinationUID(),
pr.getSysMessageID());
if (consumers == null) consumers = new ConsumerUID[0];
if (consumers.length == 0 &&
store.hasMessageBeenAcked(uid,pr.getSysMessageID())) {
if (DEBUG) {
logger.log(Logger.INFO,"Message " +
pr.getSysMessageID()+"["+this+"] has been acked, destory..");
}
decrementDestinationSize(pr);
removePacketList(pr.getSysMessageID(), pr.getDestinationUID());
pr.destroy();
continue;
}
if (consumers.length > 0) {
pr.setStoredWithInterest(true);
} else {
pr.setStoredWithInterest(false);
}
// first producer side transactions
boolean dontRoute = false;
if (pr.getTransactionID() != null) {
// if unrouted and not in rollback -> remove
Boolean state = (Boolean) (transactionStates == null ?
null : transactionStates.get(
pr.getTransactionID()));
// at this point, we should be down to 3 states
if (state == null ) // committed
{
if (consumers.length == 0) {
// route the message, it depends on the type of
// message
try {
consumers = routeLoadedTransactionMessage(pr);
} catch (Exception ex) {
logger.log(Logger.INFO,"Internal Error "
+ "loading/routing transacted message, "
+ "throwing out message " +
pr.getSysMessageID(), ex);
}
if (consumers.length > 0) {
int[] states = new int[consumers.length];
for (int i=0; i < states.length; i ++)
states[i] = Store.INTEREST_STATE_ROUTED;
try {
Globals.getStore().storeInterestStates(
getDestinationUID(),
pr.getSysMessageID(),
consumers, states, true, null);
pr.setStoredWithInterest(true);
} catch (Exception ex) {
// ok .. maybe weve already been routed
}
} else {
if (DEBUG) {
logger.log(Logger.INFO, "Message "+pr.getSysMessageID()+
" [TUID="+pr.getTransactionID()+", "+this+"] no interest" +", destroy...");
}
decrementDestinationSize(pr);
removePacketList(pr.getSysMessageID(), pr.getDestinationUID());
pr.destroy();
continue;
}
}
} else if (state == Boolean.TRUE) // prepared
{
if (preparedTrans == null)
preparedTrans = new LinkedHashMap();
preparedTrans.put(pr.getSysMessageID(),
pr.getTransactionID());
dontRoute = true;
} else { // rolledback
if (DEBUG) {
logger.log(Logger.INFO, "Message "+pr.getSysMessageID()+
" [TUID="+pr.getTransactionID()+", "+this+"] to be rolled back" +", destroy...");
}
decrementDestinationSize(pr);
removePacketList(pr.getSysMessageID(), pr.getDestinationUID());
pr.destroy();
continue;
}
}
// if the message has a transactionID AND there are
// no consumers, we never had time to route it
//
if (consumers.length == 0 && !dontRoute) {
logger.log(Logger.DEBUG,"Unrouted packet " + pr+", "+this);
decrementDestinationSize(pr);
removePacketList(pr.getSysMessageID(), pr.getDestinationUID());
pr.destroy();
continue;
}
int states[] = new int[consumers.length];
for (int i = 0; i < consumers.length; i ++) {
states[i] = store.getInterestState(
getDestinationUID(),
pr.getSysMessageID(), consumers[i]);
}
if (consumers.length > 0 ) {