Search code examples
javadisruptor-pattern

Role of BatchEventProcessor LMAX Disruptor Pattern


What is the role of the BatchEventProcessor in the lmax disruptor pattern?

BatchEventProcessor<ValueEvent> eventProcessor 
            = new BatchEventProcessor<ValueEvent>(ringBuffer, barrier, handler);

EXECUTOR.execute(eventProcessor);

Solution

  • The BatchEventProcessor is an implementation of an eventProcessor that monitors the number of events available each time its invoked. It then delegates the actual handling of each event to your eventHandler and signals when the final event of the batch has been delivered to your event handler.

    The idea being that if you wanted to delay the publication of the event from your handler, e.g. adding a group of events into a single larger message.