Hi Tirthankar,
Generally speaking, you have to go out of your way to make
messageReceived not process messages from the same connection in order
one at a time (something to do with UnorderedExecutorFilter in the
trunk, I believe). So, if all your messages are on a single TCP/IP
connection then I don't think there's a race condition in that code
snippet.
If you have multiple FIX sessions running then each will have its own
sequencing, so in that case you won't have any guarantees except that
they'll be processed in the order they arrived relative to other
messages in the same session. Also, the fix protocol has resend
requests that can cause "old" messages to be sent again, leading to old
messages with lower sequence numbers arriving after previously processed
messages with higher sequence numbers.
You appear to be using quickfix/j to parse the messages, but you're not
using the standard quickfix/j interfaces. Is this because you're not
using the standard fix session layer?
Hope that helps your investigation.
Brad.
Tirthankar Ghosh wrote:
Hi,
We are using MINA to capture high-throughput messages over network. It is
important for us to process the messages in the exact sequence they come in
to our application, over the network. The messages contain sequence numbers
and processing needs to ensure that lower sequence numbers are being
processed before the higher ones.
Given this context, please look at the code snippet below. It would help us,
if you could let me know if the code marked within the comments, // IS THIS
SECTION PRONED TO RACE CONDITION, can possibly lead to a race condition
leading to the higher sequenced messages getting queued and hence processed
before the lower ones.
The code below shows how we have messageReceived callback coded. After the
message gets queued in a blockingqueue, the subsequent code is to poll and
queue and process the messages one at a time. But there is some bit of code
even before the message gets queued and that is where I am under the
impression that a race condition can occur. Please let me know what you
think since we are currently experiencing this problem under rare cases, and
reproducing the problem in QA has not been successful so far.
public void messageReceived(IoSession ioSession, Object message) throws
Exception {
// IS THIS SECTION PRONED TO RACE CONDITION
String messageString = (String) message;
SessionID remoteSessionID =
MessageUtils.getReverseSessionID(messageString);
Session fixSession = findQFSession(ioSession, remoteSessionID);
if (fixSession != null) {
fixSession.getLog().onIncoming(messageString); // log the
incoming message in database
MessageFactory messageFactory = fixSession.getMessageFactory();
DataDictionary dataDictionary = fixSession.getDataDictionary();
Message fixMessage;
try {
fixMessage = MessageUtils.parse(messageFactory,
dataDictionary, messageString);
// IS THIS SECTION PRONED TO RACE CONDITION
queue.put(fixMessage); // put the message into a singleton
linkedblockingqueue
} catch (InvalidMessage e) {
log.error("Invalid message: " + e.getMessage());
}
} else {
log.error("Disconnecting; received message for unknown session:
" + messageString);
ioSession.close();
}
}
Any help would be appreciated.
Thanks and regards,
Tirthankar