Processoris a highly-efficient data processor that is backed by an LMAX Disruptor RingBuffer.
Rather than dealing with dynamic
Consumer registration and event routing, the
Processor gains its
extreme efficiency from pre-allocating the data objects (for which you pass a
Supplier whose job is to
provide new instances of the data class on startup) and by baking-in a
Consumer for published events.
Processor can be used in two different modes: single-operation or batch. For single operations, use the
prepare() method to allocate an object from the
Operation is also a
Supplier, so call
Supplier.get() to get access to the data object. One can then update the
members on the data object and, by calling
Operation.commit(), publish the event into
RingBuffer to be handled by the
To operate on the
Processor in batch mode, first set a
BatchConsumer as the
events. This interface provides two additional methods,
is invoked before the batch starts, and
BatchConsumer.end(), which is invoked when
batch is submitted. The
BatchConsumer will work for either single-operation mode or batch mode, but only a
BatchConsumer will be able to recognize the start and end of a batch.
|Constructor and Description|
|Modifier and Type||Method and Description|
Commit a list of
Get an object.
public void shutdown()
Processorby shutting down the thread pool.
Operationby allocating it from the buffer and preparing it to be submitted once
Operationinstance allocated from the buffer
Operationsby doing a batch publish.
Consumerset in the spec is a
BatchConsumer, then the start method will be invoked before the batch is published, then all the events of the batch are published to the consumer, then the batch end is published.
Consumer passed here is a mutator. Rather than accessing the data object directly, as one would do
prepare() call, pass a
Consumer here that will accept the allocated data object which one
can update with the appropriate data. Note that this is not an event handler. The event handler
specified in the spec (which is passed into the