}
try {
StorageManager storageManager = SandeshaUtil
.getSandeshaStorageManager(context);
NextMsgBeanMgr nextMsgMgr = storageManager.getNextMsgBeanMgr();
InvokerBeanMgr storageMapMgr = storageManager
.getStorageMapBeanMgr();
SequencePropertyBeanMgr sequencePropMgr = storageManager
.getSequencePropretyBeanMgr();
Transaction preInvocationTransaction = storageManager.getTransaction();
//Getting the incomingSequenceIdList
SequencePropertyBean allSequencesBean = (SequencePropertyBean) sequencePropMgr
.retrieve(
Sandesha2Constants.SequenceProperties.ALL_SEQUENCES,
Sandesha2Constants.SequenceProperties.INCOMING_SEQUENCE_LIST);
if (allSequencesBean == null)
continue;
ArrayList allSequencesList = SandeshaUtil.getArrayListFromString (allSequencesBean
.getValue());
preInvocationTransaction.commit();
Iterator allSequencesItr = allSequencesList.iterator();
currentIteration: while (allSequencesItr.hasNext()) {
String sequenceId = (String) allSequencesItr.next();
Transaction invocationTransaction = storageManager.getTransaction(); //Transaction based invocation
NextMsgBean nextMsgBean = nextMsgMgr.retrieve(sequenceId);
if (nextMsgBean == null) {
String message = "Next message not set correctly. Removing invalid entry.";
log.debug(message);
allSequencesItr.remove();
//cleaning the invalid data of the all sequences.
allSequencesBean.setValue(allSequencesList.toString());
sequencePropMgr.update(allSequencesBean);
throw new SandeshaException (message);
}
long nextMsgno = nextMsgBean.getNextMsgNoToProcess();
if (nextMsgno <= 0) {
String message = "Invalid messaage number as the Next Message Number. Removing invalid entry";
throw new SandeshaException(message);
}
Iterator stMapIt = storageMapMgr.find(
new InvokerBean(null, nextMsgno, sequenceId))
.iterator();
boolean invoked = false;
while (stMapIt.hasNext()) {
InvokerBean stMapBean = (InvokerBean) stMapIt
.next();
String key = stMapBean.getMessageContextRefKey();
MessageContext msgToInvoke = storageManager.retrieveMessageContext(key,context);
RMMsgContext rmMsg = MsgInitializer
.initializeMessage(msgToInvoke);
Sequence seq = (Sequence) rmMsg
.getMessagePart(Sandesha2Constants.MessageParts.SEQUENCE);
long msgNo = seq.getMessageNumber().getMessageNumber();
try {
//Invoking the message.
//currently Transaction based invocation can be supplied only for the in-only case.
if (!AxisOperationFactory.MEP_URI_IN_ONLY.equals(msgToInvoke.getAxisOperation().getMessageExchangePattern())) {
invocationTransaction.commit();
}
new AxisEngine (msgToInvoke.getConfigurationContext())
.resume(msgToInvoke);
invoked = true;
if (!AxisOperationFactory.MEP_URI_IN_ONLY.equals(msgToInvoke.getAxisOperation().getMessageExchangePattern())) {
invocationTransaction = storageManager.getTransaction();
}
storageMapMgr.delete(key);
} catch (AxisFault e) {
throw new SandeshaException(e);
}
//undating the next msg to invoke
if (rmMsg.getMessageType() == Sandesha2Constants.MessageTypes.APPLICATION) {
Sequence sequence = (Sequence) rmMsg
.getMessagePart(Sandesha2Constants.MessageParts.SEQUENCE);
if (sequence.getLastMessage() != null) {
TerminateManager.cleanReceivingSideAfterInvocation(context, sequenceId);
//this sequence has no more invocations
// stopInvokerForTheSequence(sequenceId);
//exit from current iteration. (since an entry was removed)
invocationTransaction.commit();
break currentIteration;
}
}
}
if (invoked) {
nextMsgno++;
nextMsgBean.setNextMsgNoToProcess(nextMsgno);
nextMsgMgr.update(nextMsgBean);
invocationTransaction.commit();
}
}
} catch (SandeshaException e1) {