public abstract class AbstractLifecycleDispatcher extends java.lang.Object implements Dispatcher
Dispatcher that has a lifecycle.| Modifier and Type | Class and Description |
|---|---|
class |
AbstractLifecycleDispatcher.Task |
| Modifier and Type | Field and Description |
|---|---|
java.lang.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<java.lang.Throwable> errorConsumer)
Instruct the
Dispatcher to dispatch the data. |
protected abstract void |
execute(AbstractLifecycleDispatcher.Task task) |
void |
execute(java.lang.Runnable command) |
void |
forceShutdown()
Shutdown this
Resource, forcibly halting any work currently executing and discarding any tasks that
have not yet been executed. |
protected java.lang.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. |
java.lang.String |
toString() |
protected AbstractLifecycleDispatcher.Task |
tryAllocateTask() |
<E> void |
tryDispatch(E event,
Consumer<E> eventConsumer,
Consumer<java.lang.Throwable> errorConsumer)
Instruct the
Dispatcher to dispatch the data. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitbacklogSize, remainingSlots, supportsOrderingawaitAndShutdownprotected static final int DEFAULT_BUFFER_SIZE
public final java.lang.ClassLoader context
public boolean alive()
ResourceResource can be used.public boolean awaitAndShutdown()
ResourceResource.shutdown().awaitAndShutdown in interface Resourcepublic void shutdown()
ResourceResource 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()
ResourceResource, forcibly halting any work currently executing and discarding any tasks that
have not yet been executed.forceShutdown in interface Resourcepublic boolean inContext()
contextClassLoader to let producers adapting their dispatching
strategyinContext in interface Dispatcherprotected final java.lang.ClassLoader getContext()
public final <E> void tryDispatch(E event,
Consumer<E> eventConsumer,
Consumer<java.lang.Throwable> errorConsumer)
throws InsufficientCapacityException
DispatcherDispatcher 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 DispatcherE - type of the eventevent - The eventeventConsumer - The consumer that is driven if dispatch succeedserrorConsumer - The consumer that is invoked if dispatch fails. May be nullInsufficientCapacityExceptionpublic final <E> void dispatch(E event,
Consumer<E> eventConsumer,
Consumer<java.lang.Throwable> errorConsumer)
DispatcherDispatcher 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 DispatcherE - type of the eventevent - The eventeventConsumer - The consumer that is driven if dispatch succeedserrorConsumer - The consumer that is invoked if dispatch fails. May be nullpublic void execute(java.lang.Runnable command)
execute in interface java.util.concurrent.Executorprotected void scheduleLater(AbstractLifecycleDispatcher.Task task)
protected AbstractLifecycleDispatcher.Task tryAllocateTask() throws InsufficientCapacityException
InsufficientCapacityExceptionprotected abstract AbstractLifecycleDispatcher.Task allocateTask()
protected abstract AbstractLifecycleDispatcher.Task allocateRecursiveTask()
protected abstract void execute(AbstractLifecycleDispatcher.Task task)
protected static void route(AbstractLifecycleDispatcher.Task task)
public java.lang.String toString()
toString in class java.lang.Object