|
||||||||||
| PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES | |||||||||
See:
Description
| Interface Summary | |
|---|---|
| ClaimStrategy | Strategy contract for claiming the sequence of events in the Sequencer by event publishers. |
| EventFactory<T> | Called by the RingBuffer to pre-populate all the events to fill the RingBuffer. |
| EventHandler<T> | Callback interface to be implemented for processing events as they become available in the RingBuffer |
| EventProcessor | EventProcessors waitFor events to become available for consumption from the RingBuffer
An EventProcessor will be associated with a Thread for execution. |
| EventTranslator<T> | Implementations translate another data representations into events claimed from the RingBuffer |
| ExceptionHandler | Callback handler for uncaught exceptions in the event processing cycle of the BatchEventProcessor |
| LifecycleAware | Implement this interface to be notified when a thread for the BatchEventProcessor starts and shuts down. |
| SequenceBarrier | Coordination barrier for tracking the cursor for publishers and sequence of
dependent EventProcessors for processing a data structure |
| SequenceReportingEventHandler<T> | Used by the BatchEventProcessor to set a callback allowing the EventHandler to notify
when it has finished consuming an event if this happens after the EventHandler.onEvent(Object, long, boolean) call. |
| WaitStrategy | Strategy employed for making EventProcessors wait on a cursor Sequence. |
| WorkHandler<T> | Callback interface to be implemented for processing units of work as they become available in the RingBuffer |
| Class Summary | |
|---|---|
| AbstractMultithreadedClaimStrategy | |
| AggregateEventHandler<T> | An aggregate collection of EventHandlers that get called in sequence for each event. |
| BatchDescriptor | Used to record the batch of sequences claimed via a Sequencer. |
| BatchEventProcessor<T> | Convenience class for handling the batching semantics of consuming entries from a RingBuffer
and delegating the available events to a EventHandler. |
| BlockingWaitStrategy | Blocking strategy that uses a lock and condition variable for EventProcessors waiting on a barrier. |
| BusySpinWaitStrategy | Busy Spin strategy that uses a busy spin loop for EventProcessors waiting on a barrier. |
| EventPublisher<E> | Utility class for simplifying publication to the ring buffer. |
| FatalExceptionHandler | Convenience implementation of an exception handler that using standard JDK logging to log
the exception as Level.SEVERE and re-throw it wrapped in a RuntimeException |
| IgnoreExceptionHandler | Convenience implementation of an exception handler that using standard JDK logging to log
the exception as Level.INFO |
| MultiThreadedClaimStrategy | Strategy to be used when there are multiple publisher threads claiming sequences. |
| MultiThreadedLowContentionClaimStrategy | Strategy to be used when there are multiple publisher threads claiming sequences. |
| NoOpEventProcessor | No operation version of a EventProcessor that simply tracks a Sequencer. |
| RingBuffer<T> | Ring based store of reusable entries containing the data representing an event being exchanged between event publisher and EventProcessors. |
| Sequence | |
| SequenceGroup | Sequence group that can dynamically have Sequences added and removed while being
thread safe. |
| Sequencer | Coordinator for claiming sequences for access to a data structure while tracking dependent Sequences |
| SingleThreadedClaimStrategy | Optimised strategy can be used when there is a single publisher thread claiming sequences. |
| SleepingWaitStrategy | Sleeping strategy that initially spins, then uses a Thread.yield(), and eventually for the minimum number of nanos
the OS and JVM will allow while the EventProcessors are waiting on a barrier. |
| WorkerPool<T> | A pool of WorkProcessors that will consume sequences so jobs can be farmed out across a pool of workers
which are implemented the WorkHandler interface. |
| WorkProcessor<T> | WorkProcessor for ensuring each sequence is handled by only a single processor, effectively consuming the sequence. |
| YieldingWaitStrategy | Yielding strategy that uses a Thread.yield() for EventProcessors waiting on a barrier
after an initially spinning. |
| Exception Summary | |
|---|---|
| AlertException | Used to alert EventProcessors waiting at a SequenceBarrier of status changes. |
| InsufficientCapacityException | |
| TimeoutException | Used to signal that an operation has timed out and been aborted. |
The Disruptor is a concurrent programming framework for exchanging and coordinating work as a continuous series of events. It can be used as an alternative to wiring processing stages together via queues. The Disruptor design has the characteristics of generating significantly less garbage than queues and separates the concurrency concerns so non-locking algorithms can be employed resulting in greater scalability and performance.
It works on the principle of having a number of stages that are each single threaded with local state and memory. No global memory exists and all communication is achieved by passing messages/state via managed ring buffers.
Almost any graph or pipeline structure can be composed via one or more Disruptor patterns.
UniCast a series of items between 1 publisher and 1 EventProcessor.
track to prevent wrap
+------------------+
| |
| v
+----+ +-----+ +----+ +====+ +====+ +-----+
| P1 |--->| EP1 | | P1 |--->| RB |<---| SB | | EP1 |
+----+ +-----+ +----+ +====+ +====+ +-----+
claim get ^ |
| |
+--------+
waitFor
Sequence a series of messages from multiple publishers
track to prevent wrap
+--------------------+
| |
| v
+----+ +----+ +====+ +====+ +-----+
| P1 |-------+ | P1 |--->| RB |<---| SB | | EP1 |
+----+ | +----+ +====+ +====+ +-----+
v ^ get ^ |
+----+ +-----+ +----+ | | |
| P2 |--->| EP1 | | P2 |------+ +---------+
+----+ +-----+ +----+ | waitFor
^ |
+----+ | +----+ |
| P3 |-------+ | P3 |------+
+----+ +----+
Pipeline a series of messages
+----+ +-----+ +-----+ +-----+
| P1 |--->| EP1 |--->| EP2 |--->| EP3 |
+----+ +-----+ +-----+ +-----+
track to prevent wrap
+----------------------------------------------------------------+
| |
| v
+----+ +====+ +=====+ +-----+ +=====+ +-----+ +=====+ +-----+
| P1 |--->| RB | | SB1 |<---| EP1 |<---| SB2 |<---| EP2 |<---| SB3 |<---| EP3 |
+----+ +====+ +=====+ +-----+ +=====+ +-----+ +=====+ +-----+
claim ^ get | waitFor | waitFor | waitFor
| | | |
+---------+---------------------+---------------------+
Multicast a series of messages to multiple EventProcessors
+-----+ track to prevent wrap
+----->| EP1 | +--------------------+----------+----------+
| +-----+ | | | |
| | v v v
+----+ +-----+ +----+ +====+ +====+ +-----+ +-----+ +-----+
| P1 |--->| EP2 | | P1 |--->| RB |<---| SB | | EP1 | | EP2 | | EP3 |
+----+ +-----+ +----+ +====+ +====+ +-----+ +-----+ +-----+
| claim get ^ | | |
| +-----+ | | | |
+----->| EP3 | +---------+----------+----------+
+-----+ waitFor
Replicate a message then fold back the results
+-----+ track to prevent wrap
+----->| EP1 |-----+ +-------------------------------+
| +-----+ | | |
| v | v
+----+ +-----+ +----+ +====+ +=====+ +-----+
| P1 | | EP3 | | P1 |--->| RB |<--------------| SB2 |<---| EP3 |
+----+ +-----+ +----+ +====+ +=====+ +-----+
| ^ claim ^ get | waitFor
| +-----+ | | |
+----->| EP2 |-----+ +=====+ +-----+ |
+-----+ | SB1 |<---| EP1 |<-----+
+=====+ +-----+ |
^ |
| +-----+ |
+-------| EP2 |<-----+
waitFor +-----+
// Event holder for data to be exchanged
public final class ValueEvent
{
private long value;
public long getValue()
{
return value;
}
public void setValue(final long value)
{
this.value = value;
}
public final static EventFactory<ValueEvent> EVENT_FACTORY = new EventFactory<ValueEvent>()
{
public ValueEvent newInstance()
{
return new ValueEvent();
}
};
}
// Callback handler which can be implemented by EventProcessors
final EventHandler<ValueEvent> eventHandler = new EventHandler<ValueEvent>()
{
public void onEvent(final ValueEvent event, final long sequence, final boolean endOfBatch)
throws Exception
{
// process a new event as it becomes available.
}
};
RingBuffer<ValueEvent> ringBuffer =
new RingBuffer<ValueEvent>(ValueEvent.EVENT_FACTORY,
new SingleThreadedClaimStrategy(BUFFER_SIZE),
new SleepingWaitStrategy());
SequenceBarrier<ValueEvent> sequenceBarrier = ringBuffer.newBarrier();
BatchEventProcessor<ValueEvent> batchProcessor = new BatchEventProcessor<ValueEvent>(sequenceBarrier, eventHandler);
ringBuffer.setGatingSequences(batchProcessor.getSequence());
// Each processor runs on a separate thread
EXECUTOR.submit(batchProcessor);
// Publishers claim events in sequence
long sequence = ringBuffer.next();
ValueEvent event = ringBuffer.get(sequence);
event.setValue(1234);
// publish the event so it is available to EventProcessors
ringBuffer.publish(sequence);
|
||||||||||
| PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES | |||||||||