public final class RingBufferDispatcher extends SingleThreadDispatcher implements WaitingMood
Dispatcher
that uses a RingBuffer
to queue tasks to execute.SingleThreadDispatcher.SingleThreadTask
AbstractLifecycleDispatcher.Task
backlog, tailRecurseSeq, tailRecursionPile, tailRecursionPileSize
context, DEFAULT_BUFFER_SIZE
Constructor and Description |
---|
RingBufferDispatcher(String name)
Creates a new
RingBufferDispatcher with the given name . |
RingBufferDispatcher(String name,
int bufferSize)
Creates a new
RingBufferDispatcher with the given name and ,
configured with a producer type of MULTI and a blocking
wait
strategy . |
RingBufferDispatcher(String name,
int bufferSize,
Consumer<Throwable> uncaughtExceptionHandler)
Creates a new RingBufferDispatcher with the given
name . |
RingBufferDispatcher(String name,
int bufferSize,
Consumer<Throwable> uncaughtExceptionHandler,
com.lmax.disruptor.dsl.ProducerType producerType,
com.lmax.disruptor.WaitStrategy waitStrategy)
Creates a new RingBufferDispatcher with the given
name . |
Modifier and Type | Method and Description |
---|---|
protected AbstractLifecycleDispatcher.Task |
allocateTask() |
boolean |
awaitAndShutdown(long timeout,
TimeUnit timeUnit)
Block until all submitted tasks have completed, then do a normal
Resource.shutdown() . |
void |
calm()
Turn the mood into eco CPU demand mode to save resources from the underlying component.
|
protected void |
execute(AbstractLifecycleDispatcher.Task task) |
void |
forceShutdown()
Shutdown this
Resource , forcibly halting any work currently executing and discarding any tasks that
have not yet been executed. |
void |
nervous()
Turn the mood into aggressive CPU demand mode to effectively give an an additional resources boost to the underlying
component.
|
long |
remainingSlots()
Request the remaining capacity for the underlying shared state structure.
|
void |
shutdown()
Shutdown this active
Resource such that it can no longer be used. |
protected AbstractLifecycleDispatcher.Task |
tryAllocateTask() |
allocateRecursiveTask, backlogSize, expandTailRecursionPile, getTailRecursionPileSize, supportsOrdering
alive, awaitAndShutdown, dispatch, execute, getContext, inContext, route, scheduleLater, toString, tryDispatch
public RingBufferDispatcher(String name)
RingBufferDispatcher
with the given name
. It will use a RingBuffer with 1024 slots,
configured with a producer type of MULTI
and a blocking
wait
strategy
.name
- The name of the dispatcher.public RingBufferDispatcher(String name, int bufferSize)
RingBufferDispatcher
with the given name
and ,
configured with a producer type of MULTI
and a blocking
wait
strategy
.name
- The name of the dispatcherbufferSize
- The size to configure the ring buffer withpublic RingBufferDispatcher(String name, int bufferSize, Consumer<Throwable> uncaughtExceptionHandler)
name
. It will use a RingBuffer
with
bufferSize
slots, configured with a producer type of MULTI
and a blocking wait. A given @param uncaughtExceptionHandler
will catch anything not
handled e.g. by the owning reactor.bus.EventBus
or reactor.rx.Stream
.name
- The name of the dispatcherbufferSize
- The size to configure the ring buffer withuncaughtExceptionHandler
- The last resort exception handlerpublic RingBufferDispatcher(String name, int bufferSize, Consumer<Throwable> uncaughtExceptionHandler, com.lmax.disruptor.dsl.ProducerType producerType, com.lmax.disruptor.WaitStrategy waitStrategy)
name
. It will use a RingBuffer
with
bufferSize
slots, configured with the given producerType
,
and waitStrategy
. A null will make this dispatcher logging such
exceptions.name
- The name of the dispatcherbufferSize
- The size to configure the ring buffer withproducerType
- The producer type to configure the ring buffer withwaitStrategy
- The wait strategy to configure the ring buffer withuncaughtExceptionHandler
- The last resort exception handlerpublic boolean awaitAndShutdown(long timeout, TimeUnit timeUnit)
Resource
Resource.shutdown()
.awaitAndShutdown
in interface Resource
public void shutdown()
Resource
Resource
such that it can no longer be used. If the resource carries any work,
it will wait (but NOT blocking the caller) for all the remaining tasks to perform before closing the resource.shutdown
in interface Resource
shutdown
in class AbstractLifecycleDispatcher
public void forceShutdown()
Resource
Resource
, forcibly halting any work currently executing and discarding any tasks that
have not yet been executed.forceShutdown
in interface Resource
forceShutdown
in class AbstractLifecycleDispatcher
public long remainingSlots()
Dispatcher
RingBufferDispatcher
will return
RingBuffer.remainingCapacity()
.
remainingSlots
in interface Dispatcher
public void nervous()
WaitingMood
nervous
in interface WaitingMood
public void calm()
WaitingMood
calm
in interface WaitingMood
protected AbstractLifecycleDispatcher.Task tryAllocateTask() throws InsufficientCapacityException
tryAllocateTask
in class AbstractLifecycleDispatcher
InsufficientCapacityException
protected AbstractLifecycleDispatcher.Task allocateTask()
allocateTask
in class SingleThreadDispatcher
protected void execute(AbstractLifecycleDispatcher.Task task)
execute
in class AbstractLifecycleDispatcher
Copyright © 2016. All rights reserved.