I am publishing 2 or more different events to an output disruptor at the same time (one right after the other) and the disruptor onEvent is usually sending only the last to be published event to the IO session. Basically the event data is overwritten. Whereas I want to see a copy of each event on the session layer. I have tried synchronizing the session layer on a lock but the publisher is usually still too fast even for the lock (sometimes it is working but most of the time it's not).
Here's some code:
private final Object lock = new Object();
public void onEvent(final FixEvent event, final long sequence, final boolean endOfBatch)
{
synchronized(lock)
{
sendMessage(event.message);
}
}
Has this happened to anyone else? Is there another solution besides a speed bump in the publisher?
Here is the producer code:
public void onData(Message message, SessionID s)
{
long sequence = ringBuffer.next(); // Grab the next sequence
try
{
FixEvent event = ringBuffer.get(sequence);
event.set(message, s);
}
finally
{
ringBuffer.publish(sequence);
}
}