Transaction transaction = null;
try {
RMDBeanMgr nextMsgMgr = storageManager.getRMDBeanMgr();
InvokerBeanMgr storageMapMgr = storageManager
.getInvokerBeanMgr();
transaction = storageManager.getTransaction();
// Pick a sequence using a round-robin approach
ArrayList allSequencesList = getSequences();
int size = allSequencesList.size();
log.debug("Choosing one from " + size + " sequences");
if(nextIndex >= size) {
nextIndex = 0;
// We just looped over the set of sequences. If we didn't process any
// messages on this loop then we sleep before the next one
if(size == 0 || !processedMessage) {
sleep = true;
}
processedMessage = false;
if (log.isDebugEnabled()) log.debug("Exit: Invoker::internalRun, looped over all sequences, sleep " + sleep);
return sleep;
}
SequenceEntry entry = (SequenceEntry) allSequencesList.get(nextIndex++);
String sequenceId = entry.getSequenceId();
log.debug("Chose sequence " + sequenceId);
RMDBean nextMsgBean = nextMsgMgr.retrieve(sequenceId);
if (nextMsgBean == null) {
log.debug("Next message not set correctly. Removing invalid entry.");
stopThreadForSequence(sequenceId, entry.isRmSource());
allSequencesList = getSequences();
if (allSequencesList.size() == 0)
sleep = true;
if (log.isDebugEnabled()) log.debug("Exit: Invoker::internalRun, sleep " + sleep);
return sleep;
}
long nextMsgno = nextMsgBean.getNextMsgNoToProcess();
if (nextMsgno <= 0) {
// Make sure we sleep on the next loop, so that we don't spin in a tight loop
sleep = true;
if (log.isDebugEnabled())
log.debug("Invalid Next Message Number " + nextMsgno);
String message = SandeshaMessageHelper.getMessage(
SandeshaMessageKeys.invalidMsgNumber, Long
.toString(nextMsgno));
throw new SandeshaException(message);
}
InvokerBean selector = new InvokerBean();
selector.setSequenceID(sequenceId);
selector.setMsgNo(nextMsgno);
List invokerBeans = storageMapMgr.find(selector);
//add any msgs that belong to out of order windows
addOutOfOrderInvokerBeansToList(sequenceId,
storageManager, invokerBeans);