質問

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

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

EXECUTOR.execute(eventProcessor);
役に立ちましたか?

解決

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.

他のヒント

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)
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top