|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.lmax.disruptor.dsl.Disruptor<T>
T - the type of event used.public class Disruptor<T>
A DSL-style API for setting up the disruptor pattern around a ring buffer.
A simple example of setting up the disruptor with two event handlers that must process events in order:
Disruptor disruptor = new Disruptor(MyEvent.FACTORY, 32, Executors.newCachedThreadPool());
EventHandler handler1 = new EventHandler() { ... };
EventHandler handler2 = new EventHandler() { ... };
disruptor.handleEventsWith(handler1);
disruptor.after(handler1).handleEventsWith(handler2);
RingBuffer ringBuffer = disruptor.start();
| Constructor Summary | |
|---|---|
Disruptor(EventFactory<T> eventFactory,
java.util.concurrent.Executor executor,
ClaimStrategy claimStrategy,
WaitStrategy waitStrategy)
Create a new Disruptor. |
|
Disruptor(EventFactory<T> eventFactory,
int ringBufferSize,
java.util.concurrent.Executor executor)
Create a new Disruptor. |
|
| Method Summary | |
|---|---|
EventHandlerGroup<T> |
after(EventHandler<T>... handlers)
Create a group of event handlers to be used as a dependency. |
EventHandlerGroup<T> |
after(EventProcessor... processors)
Create a group of event processors to be used as a dependency. |
SequenceBarrier |
getBarrierFor(EventHandler<T> handler)
Get the SequenceBarrier used by a specific handler. |
RingBuffer<T> |
getRingBuffer()
The the RingBuffer used by this Disruptor. |
void |
halt()
Calls EventProcessor.halt() on all of the event processors created via this disruptor. |
EventHandlerGroup<T> |
handleEventsWith(EventHandler<T>... handlers)
Set up event handlers to handleEventException events from the ring buffer. |
EventHandlerGroup<T> |
handleEventsWith(EventProcessor... processors)
Set up custom event processors to handleEventException events from the ring buffer. |
ExceptionHandlerSetting<?> |
handleExceptionsFor(EventHandler<T> eventHandler)
Override the default exception handler for a specific handler. |
void |
handleExceptionsWith(ExceptionHandler exceptionHandler)
Specify an exception handler to be used for any future event handlers. |
void |
publishEvent(EventTranslator<T> eventTranslator)
Publish an event to the ring buffer. |
void |
shutdown()
Waits until all events currently in the disruptor have been processed by all event processors and then halts the processors. |
RingBuffer<T> |
start()
Starts the event processors and returns the fully configured ring buffer. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public Disruptor(EventFactory<T> eventFactory,
int ringBufferSize,
java.util.concurrent.Executor executor)
eventFactory - the factory to create events in the ring buffer.ringBufferSize - the size of the ring buffer.executor - an Executor to execute event processors.
public Disruptor(EventFactory<T> eventFactory,
java.util.concurrent.Executor executor,
ClaimStrategy claimStrategy,
WaitStrategy waitStrategy)
eventFactory - the factory to create events in the ring buffer.executor - an Executor to execute event processors.claimStrategy - the claim strategy to use for the ring buffer.waitStrategy - the wait strategy to use for the ring buffer.| Method Detail |
|---|
public EventHandlerGroup<T> handleEventsWith(EventHandler<T>... handlers)
This method can be used as the start of a chain. For example if the handler A must
process events before handler B:
dw.handleEventsWith(A).then(B);
handlers - the event handlers that will process events.
EventHandlerGroup that can be used to chain dependencies.public EventHandlerGroup<T> handleEventsWith(EventProcessor... processors)
start() is called.
processors - the event processors that will process events.
EventHandlerGroup that can be used to chain dependencies.public void handleExceptionsWith(ExceptionHandler exceptionHandler)
exceptionHandler - the exception handler to use for any future EventProcessor.public ExceptionHandlerSetting<?> handleExceptionsFor(EventHandler<T> eventHandler)
disruptorWizard.handleExceptionsIn(eventHandler).with(exceptionHandler);
eventHandler - the event handler to set a different exception handler for.
public EventHandlerGroup<T> after(EventHandler<T>... handlers)
A must process events before handler B:
dw.after(A).handleEventsWith(B);
handlers - the event handlers, previously set up with handleEventsWith(com.lmax.disruptor.EventHandler[]),
that will form the barrier for subsequent handlers or processors.
EventHandlerGroup that can be used to setup a dependency barrier over the specified event handlers.public EventHandlerGroup<T> after(EventProcessor... processors)
processors - the event processors, previously set up with handleEventsWith(com.lmax.disruptor.EventProcessor...),
that will form the barrier for subsequent handlers or processors.
EventHandlerGroup that can be used to setup a SequenceBarrier over hte specified event processors.after(com.lmax.disruptor.EventHandler[])public void publishEvent(EventTranslator<T> eventTranslator)
eventTranslator - the translator that will load data into the event.public RingBuffer<T> start()
public void halt()
EventProcessor.halt() on all of the event processors created via this disruptor.
public void shutdown()
This method will not shutdown the executor, nor will it await the final termination of the processor threads.
public RingBuffer<T> getRingBuffer()
RingBuffer used by this Disruptor. This is useful for creating custom
event processors if the behaviour of BatchEventProcessor is not suitable.
public SequenceBarrier getBarrierFor(EventHandler<T> handler)
SequenceBarrier used by a specific handler. Note that the SequenceBarrier
may be shared by multiple event handlers.
handler - the handler to get the barrier for.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||