Domanda

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

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

EXECUTOR.execute(eventProcessor);
È stato utile?

Soluzione

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.

Altri suggerimenti

If we are talking about the task of "adding a group of events into a single larger message" from Sam answer, BatchEventProcessor makes it possible for us two main things:

  1. We will get "endOfBatch==true" at the last invocation of the event series, so we can postpone bulk message publishing to invocation with "endOfBatch==true" and we don't stuck in a situation when there are no events for some minutes and we didn't send already collected once and we need additionally handle this situation.
  2. BatchEventProcessor will move its own Sequence value only after all messages from batch proceed by Handler. It makes possible to hold previous events of current batch in our Handler and use them to produce a bulk message, for example, and you shouldn't think about Producers, that could damage content of this reused events. Producers don't have an access to these events and related sequences until handler returns from onEvent(, endOfBatch==true)
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top