EventProcessor without EventHandler

182 views
Skip to first unread message

igor.petrouk

unread,
Jan 30, 2012, 8:46:46 AM1/30/12
to Disruptor
Hi.

I have a feeling that deeply misunderstand Disruptor best practices. I
need to write a code that runs in it's thread and polls and waits for
disruptor event depending on some conditions. In this case I don't
need EventHandler, just EventProcessor. I try the following code.

RingBuffer<TestEvent> ringBuffer = disruptor.getRingBuffer();
SequenceBarrier barrier = ringBuffer.newBarrier();
final MyEventProcessor customProcessor = new
MyEventProcessor(ringBuffer, barrier);
disruptor.handleEventsWith(customProcessor);
disruptor.start();

Just for testing I don't update sequence in processor and sleep
infinitely there. The publisher keeps publishing wrapping around and
around. Why is that? In order to make it work I should hack the
disruptor.

disruptor.after(customProcessor).handleEventsWith(dummyEmptyHandler);

Is there a cleaner way? I don't need this handler, I never call it.
Everything I have in EventProcessor is enough for me.

Thanks.

Best regards,
Igor Petruk

Michael Barker

unread,
Feb 1, 2012, 5:19:06 PM2/1/12
to lmax-di...@googlegroups.com
I think this could be a bug. It looks like the Sequence from the
event processor is not being set as the gating sequence. I'll check
with the author of the Disruptor DSL tomorrow. You can wire this
together manually, which may be the better option if you are not using
the standard EventHandler interface.

Executor executor = Executors.newCachedThreadPool();
RingBuffer<TestEvent> ringBuffer = new
RingBuffer<TestEvent>(new TestEventFactory(), 1024);
SequenceBarrier barrier = ringBuffer.newBarrier();


MyEventProcessor customProcessor = new
MyEventProcessor(ringBuffer, barrier);

ringBuffer.setGatingSequences(customProcessor.getSequence());
// This line is crucial to prevent wrapping.
executor.execute(customProcessor);

Mike.

mikeb01

unread,
Feb 5, 2012, 2:27:03 PM2/5/12
to lmax-di...@googlegroups.com
This is a bug and will be fixed in the next release of the disruptor (2.8)
Reply all
Reply to author
Forward
0 new messages