// Update the RMDBean
storageManager.getRMDBeanMgr().update(bean);
// If an outbound message has already gone out with that relatesTo, then we can terminate
// right away.
RMSBean rmsBean = SandeshaUtil.getRMSBeanFromInternalSequenceId(storageManager, responseSideInternalSequenceId);
if(rmsBean != null) {
String highestOutRelatesTo = rmsBean.getHighestOutRelatesTo();
if (highestOutRelatesTo != null && highestOutRelatesTo.equals(inMsgId)) {
highestOutMsgNo = rmsBean.getHighestOutMessageNumber();
addResponseSideTerminate = true;
// It is possible that the message has gone out, but not been acked yet. In that case
// we can store the HIGHEST_OUT_MSG_NUMBER as the LAST_OUT_MESSAGE_NO, so that when the
// ack arrives we will terminate the sequence
rmsBean.setLastOutMessage(highestOutMsgNo);
storageManager.getRMSBeanMgr().update(rmsBean);
}
}
}
// If all the out message have been acked, add the outgoing
// terminate seq msg.
String outgoingSequnceID = SandeshaUtil.getSequenceIDFromInternalSequenceID(responseSideInternalSequenceId, storageManager);
if (addResponseSideTerminate && highestOutMsgNo > 0 && responseSideInternalSequenceId != null
&& outgoingSequnceID != null) {
boolean allAcked = SandeshaUtil.isAllMsgsAckedUpto(highestOutMsgNo, responseSideInternalSequenceId, storageManager);
if (allAcked)
{
RMSBean rmsBean = SandeshaUtil.getRMSBeanFromSequenceId(storageManager, outgoingSequnceID);
if (!rmsBean.isTerminateAdded()) {
TerminateManager.addTerminateSequenceMessage(terminateRMMsg, rmsBean.getInternalSequenceID(), outgoingSequnceID , storageManager);
String referenceMsgKey = rmsBean.getReferenceMessageStoreKey();
if (referenceMsgKey==null) {
String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.referenceMessageNotSetForSequence,rmsBean.getSequenceID());
throw new SandeshaException (message);
}
MessageContext referenceMessage = storageManager.retrieveMessageContext(referenceMsgKey, configCtx);
if (referenceMessage==null) {
String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.referencedMessageNotFound, rmsBean.getSequenceID());
throw new SandeshaException (message);
}
//RMMsgContext referenceRMMsg = MsgInitializer.initializeMessage(referenceMessage);