public abstract class AbstractLifecycleDispatcher extends Object implements Dispatcher
Dispatcher
that has a lifecycle.Modifier and Type | Class and Description |
---|---|
class |
AbstractLifecycleDispatcher.Task |
Modifier and Type | Field and Description |
---|---|
ClassLoader |
context |
protected static int |
DEFAULT_BUFFER_SIZE |
Modifier | Constructor and Description |
---|---|
protected |
AbstractLifecycleDispatcher() |
Modifier and Type | Method and Description |
---|---|
boolean |
alive()
Determine whether this
Resource can be used. |
protected abstract AbstractLifecycleDispatcher.Task |
allocateRecursiveTask() |
protected abstract AbstractLifecycleDispatcher.Task |
allocateTask() |
boolean |
awaitAndShutdown()
Block until all submitted tasks have completed, then do a normal
Resource.shutdown() . |
<E> void |
dispatch(E event,
Consumer<E> eventConsumer,
Consumer<Throwable> errorConsumer)
Instruct the
Dispatcher to dispatch the data . |
protected abstract void |
execute(AbstractLifecycleDispatcher.Task task) |
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. |
protected ClassLoader |
getContext() |
boolean |
inContext()
Dispatchers can be traced through a
contextClassLoader to let producers adapting their dispatching
strategy |
protected static void |
route(AbstractLifecycleDispatcher.Task task) |
protected void |
scheduleLater(AbstractLifecycleDispatcher.Task task) |
void |
shutdown()
Shutdown this active
Resource such that it can no longer be used. |
String |
toString() |
protected AbstractLifecycleDispatcher.Task |
tryAllocateTask() |
<E> void |
tryDispatch(E event,
Consumer<E> eventConsumer,
Consumer<Throwable> errorConsumer)
Instruct the
Dispatcher to dispatch the data . |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
backlogSize, remainingSlots, supportsOrdering
awaitAndShutdown
protected static final int DEFAULT_BUFFER_SIZE
public final ClassLoader context
public boolean alive()
Resource
Resource
can be used.public boolean awaitAndShutdown()
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 boolean inContext()
contextClassLoader
to let producers adapting their dispatching
strategyinContext
in interface Dispatcher
protected final ClassLoader getContext()
public final <E> void tryDispatch(E event, Consumer<E> eventConsumer, Consumer<Throwable> errorConsumer) throws InsufficientCapacityException
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 eventeventConsumer
- The consumer that is driven if dispatch succeedserrorConsumer
- The consumer that is invoked if dispatch fails. May be null
InsufficientCapacityException
public final <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
protected void scheduleLater(AbstractLifecycleDispatcher.Task task)
protected AbstractLifecycleDispatcher.Task tryAllocateTask() throws InsufficientCapacityException
InsufficientCapacityException
protected abstract AbstractLifecycleDispatcher.Task allocateTask()
protected abstract AbstractLifecycleDispatcher.Task allocateRecursiveTask()
protected abstract void execute(AbstractLifecycleDispatcher.Task task)
protected static void route(AbstractLifecycleDispatcher.Task task)
Copyright © 2016. All rights reserved.