SandeshaMessageKeys.invalidMsgNumber, Long
.toString(nextMsgno));
throw new SandeshaException(message);
}
InvokerBean selector = new InvokerBean();
selector.setSequenceID(sequenceId);
selector.setMsgNo(nextMsgno);
List<InvokerBean> invokerBeans = storageMapMgr.find(selector);
//add any msgs that belong to out of order windows
addOutOfOrderInvokerBeansToList(sequenceId,
storageManager, invokerBeans);
// If there aren't any beans to process then move on to the next sequence
if (invokerBeans.size() == 0) {
if (log.isDebugEnabled()) log.debug("Exit: Invoker::internalRun, no beans to invoke on sequence " + sequenceId + ", sleep " + sleep);
if(transaction != null && transaction.isActive()) transaction.commit();
transaction = null;
return sleep;
}
Iterator<InvokerBean> stMapIt = invokerBeans.iterator();
//TODO correct the locking mechanism to have one lock per sequence.
//TODO should this be a while, not an if?
if (stMapIt.hasNext()) { //some invokation work is present
InvokerBean bean = (InvokerBean) stMapIt.next();
//see if this is an out of order msg
boolean beanIsOutOfOrderMsg = bean.getMsgNo()!=nextMsgno;
String workId = sequenceId;
//check whether the bean is already assigned to a worker.
if (getWorkerLock().isWorkPresent(workId)) {
// As there is already a worker assigned we are probably dispatching
// messages too quickly, so we sleep before trying the next sequence.
sleep = true;
String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.workAlreadyAssigned, workId);
if (log.isDebugEnabled()) log.debug("Exit: Invoker::internalRun, " + message + ", sleep " + sleep);
if(transaction != null) {
transaction.commit();
transaction = null;
}
return sleep;
}
if(transaction != null) {
transaction.commit();
transaction = null;
}
// start a new worker thread and let it do the invocation.
InvokerWorker worker = new InvokerWorker(context, bean);
if(beanIsOutOfOrderMsg) worker.forceOutOfOrder();
worker.setPooled();
worker.setWorkId(workId);
// Wrap the invoker worker with the correct context, if needed.
Runnable work = worker;
ContextManager contextMgr = SandeshaUtil.getContextManager(context);
if(contextMgr != null) {
work = contextMgr.wrapWithContext(work, bean.getContext());
}
try {
// Set the lock up before we start the thread, but roll it back
// if we hit any problems
if(worker.getLock().addWork(workId, worker))