public class DisruptorExample {
public static void main(String[] args) {
EventFactory<FooEvent> eventFactory = new EventFactory<FooEvent>() {
public FooEvent newInstance() {
return new FooEvent();
}
};
int bufferSize = 1024;
RingBuffer<FooEvent> ringBuffer =
RingBuffer.createSingleProducer(eventFactory, bufferSize);
EventHandler<FooEvent> eventHandler = (event, sequence, endOfBatch) -> {
System.out.println("Processing event: " + event);
};
Disruptor<FooEvent> disruptor = new Disruptor<>(eventFactory, bufferSize,
Executors.defaultThreadFactory(), ProducerType.SINGLE,
new BlockingWaitStrategy());
disruptor.handleEventsWith(eventHandler);
disruptor.start();
RingBufferProducer<FooEvent> producer = new RingBufferProducer<>(ringBuffer);
for (int i = 0; i < 10; i++) {
FooEvent event = new FooEvent();
producer.onData(event);
}
disruptor.shutdown();
}
}
class FooEvent {
}