public synchronized void sendMessage(Message message,
SessionID targetSession,
String sourceSession,
int counter,
MessageContext msgCtx,
String targetEPR) throws SessionNotFound {
if (sourceSession != null && counter != -1) {
int expectedValue;
if (countersMap.containsKey(sourceSession)) {
expectedValue = countersMap.get(sourceSession);
}
else {
//create new entries in the respective Maps
//counter starts at 1
countersMap.put(sourceSession, 1);
messagesMap.put(sourceSession, new HashMap< Integer,Object[] >());
expectedValue = 1;
}
if (expectedValue == counter) {
sendToTarget(msgCtx, targetEPR, message, targetSession);
countersMap.put(sourceSession, expectedValue++);
sendQueuedMessages(expectedValue, sourceSession);
}
else {
//save the message to be sent later...
Map< Integer,Object[] > messages = messagesMap.get(sourceSession);
Object[] obj = new Object[4];
obj[0] = message;
obj[1] = targetSession;
obj[2] = msgCtx;
obj[3] = targetEPR;
messages.put(counter, obj);
messagesMap.put(sourceSession, messages);
}
}
else {
//insufficient information to send the messages in order...
// send it right away...
sendToTarget(msgCtx, targetEPR, message, targetSession);
}
}
Performs the actual send operation on the message. Tries to send the messages in the order they
arrived over the FIX transport |