InvokerBeanMgr invokerBeanMgr = storageManager.getInvokerBeanMgr();
//starting a transaction
transaction = storageManager.getTransaction();
InvokerBean invokerBean = invokerBeanMgr.retrieve(messageContextKey);
msgToInvoke = storageManager.retrieveMessageContext(messageContextKey, configurationContext);
// ending the transaction before invocation.
if(transaction != null) {
transaction.commit();
transaction = storageManager.getTransaction();
}
RMMsgContext rmMsg = MsgInitializer.initializeMessage(msgToInvoke);
// Lock the RMD Bean just to avoid deadlocks
SandeshaUtil.getRMDBeanFromSequenceId(storageManager, invokerBean.getSequenceID());
// Depending on the transaction support, the service will be invoked only once.
// Therefore we delete the invoker bean and message now, ahead of time
invokerBeanMgr.delete(messageContextKey);
// removing the corresponding message context as well.
storageManager.removeMessageContext(messageContextKey);
try {
boolean postFailureInvocation = false;
// StorageManagers should st following property to
// true, to indicate that the message received comes
// after a failure.
String postFaulureProperty = (String) msgToInvoke
.getProperty(Sandesha2Constants.POST_FAILURE_MESSAGE);
if (postFaulureProperty != null
&& Sandesha2Constants.VALUE_TRUE.equals(postFaulureProperty))
postFailureInvocation = true;
if (postFailureInvocation) {
makeMessageReadyForReinjection(msgToInvoke);
if (log.isDebugEnabled())
log.debug("Receiving message, key=" + messageContextKey + ", msgCtx="
+ msgToInvoke.getEnvelope().getHeader());
AxisEngine.receive(msgToInvoke);
} else {
if (log.isDebugEnabled())
log.debug("Resuming message, key=" + messageContextKey + ", msgCtx="
+ msgToInvoke.getEnvelope().getHeader());
msgToInvoke.setPaused(false);
AxisEngine.resumeReceive(msgToInvoke);
}
if (transaction != null && transaction.isActive()){
transaction.commit();
}
} catch (Exception e) {
if (log.isDebugEnabled())
log.debug("Exception :", e);
if (transaction != null && transaction.isActive()){
transaction.rollback();
}
handleFault(rmMsg, e);
}
transaction = storageManager.getTransaction();
if (rmMsg.getMessageType() == Sandesha2Constants.MessageTypes.APPLICATION) {
Sequence sequence = (Sequence) rmMsg
.getMessagePart(Sandesha2Constants.MessageParts.SEQUENCE);
boolean highestMessage = false;
if (sequence.getLastMessage() != null) {
//this will work for RM 1.0 only
highestMessage = true;
} else {
RMDBean rmdBean = SandeshaUtil.getRMDBeanFromSequenceId(storageManager, invokerBean.getSequenceID());
if (rmdBean!=null && rmdBean.isTerminated()) {
long highestInMsgNo = rmdBean.getHighestInMessageNumber();
if (invokerBean.getMsgNo()==highestInMsgNo)
highestMessage = true;
}
}
if (highestMessage) {
//do cleaning stuff that hs to be done after the invocation of the last message.
TerminateManager.cleanReceivingSideAfterInvocation(invokerBean.getSequenceID(), storageManager);
// exit from current iteration. (since an entry
// was removed)
if(log.isDebugEnabled()) log.debug("Exit: InvokerWorker::run Last message return");
if(transaction != null && transaction.isActive()) transaction.commit();
return;
}
}
if(!ignoreNextMsg){
// updating the next msg to invoke
RMDBean rMDBean = storageManager.getRMDBeanMgr().retrieve(invokerBean.getSequenceID());
long nextMsgNo = rMDBean.getNextMsgNoToProcess();
if (!(invokerBean.getMsgNo()==nextMsgNo)) {
String message = "Operated message number is different from the Next Message Number to invoke";
throw new SandeshaException (message);
}
nextMsgNo++;