public final class SynchronousDispatcher extends Object implements Dispatcher
Dispatcher
implementation that dispatches events using the calling thread.Modifier and Type | Field and Description |
---|---|
static SynchronousDispatcher |
INSTANCE |
Constructor and Description |
---|
SynchronousDispatcher() |
Modifier and Type | Method and Description |
---|---|
boolean |
alive()
Determine whether this
Resource can be used. |
boolean |
awaitAndShutdown()
Block until all submitted tasks have completed, then do a normal
Resource.shutdown() . |
boolean |
awaitAndShutdown(long timeout,
TimeUnit timeUnit)
Block until all submitted tasks have completed, then do a normal
Resource.shutdown() . |
long |
backlogSize()
Request the capacity for the underlying shared state structure.
|
<E> void |
dispatch(E event,
Consumer<E> eventConsumer,
Consumer<Throwable> errorConsumer)
Instruct the
Dispatcher to dispatch the data . |
void |
execute(Runnable command) |
void |
forceShutdown()
Shutdown this
Resource , forcibly halting any work currently executing and discarding any tasks that
have not yet been executed. |
boolean |
inContext()
A dispatcher context can be bound to the thread(s) it runs on.
|
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. |
boolean |
supportsOrdering()
Inspect if the dispatcher supports ordered dispatching:
Single threaded dispatchers naturally preserve event ordering on dispatch.
|
String |
toString() |
<E> void |
tryDispatch(E event,
Consumer<E> consumer,
Consumer<Throwable> errorConsumer)
Instruct the
Dispatcher to dispatch the data . |
public static final SynchronousDispatcher INSTANCE
public boolean alive()
Resource
Resource
can be used.public boolean awaitAndShutdown()
Resource
Resource.shutdown()
.awaitAndShutdown
in interface Resource
public 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.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
public <E> void tryDispatch(E event, Consumer<E> consumer, Consumer<Throwable> errorConsumer)
Dispatcher
Dispatcher
to dispatch the data
.
If the dispatcher doesn't have enough capacity and might block on the next produced event,
The event Consumer
will receive the event. In the event of an error during dispatching, the errorConsumer
will be called.tryDispatch
in interface Dispatcher
E
- type of the eventevent
- The eventconsumer
- The consumer that is driven if dispatch succeedserrorConsumer
- The consumer that is invoked if dispatch fails. May be null
public <E> void dispatch(E event, Consumer<E> eventConsumer, Consumer<Throwable> errorConsumer)
Dispatcher
Dispatcher
to dispatch the data
. The event Consumer
will receive the event. In the event of an error during dispatching, the errorConsumer
will be called.dispatch
in interface Dispatcher
E
- type of the eventevent
- The eventeventConsumer
- The consumer that is driven if dispatch succeedserrorConsumer
- The consumer that is invoked if dispatch fails. May be null
public long remainingSlots()
Dispatcher
RingBufferDispatcher
will return
RingBuffer.remainingCapacity()
.
remainingSlots
in interface Dispatcher
public boolean supportsOrdering()
Dispatcher
supportsOrdering
in interface Dispatcher
public long backlogSize()
Dispatcher
RingBufferDispatcher
will return
RingBuffer.getBufferSize()
.
backlogSize
in interface Dispatcher
public boolean inContext()
Dispatcher
inContext
in interface Dispatcher
Copyright © 2017. All rights reserved.