@InterfaceAudience.Public @InterfaceStability.Evolving public class AsyncDispatcher extends AbstractService implements Dispatcher
Event
s in a separate thread. Currently only single thread
does that. Potentially there could be multiple channels for each event type
class and a thread pool can be used to dispatch the events.Modifier and Type | Field and Description |
---|---|
protected Map<Class<? extends Enum>,EventHandler> |
eventDispatchers |
DEFAULT_DISPATCHER_EXIT_ON_ERROR, DISPATCHER_EXIT_ON_ERROR_KEY
Constructor and Description |
---|
AsyncDispatcher() |
AsyncDispatcher(BlockingQueue<Event> eventQueue) |
AsyncDispatcher(String dispatcherName)
Set a name for this dispatcher thread.
|
Modifier and Type | Method and Description |
---|---|
protected void |
dispatch(Event event) |
EventHandler |
getEventHandler() |
protected boolean |
isDrained() |
protected boolean |
isEventThreadWaiting() |
protected boolean |
isStopped() |
void |
register(Class<? extends Enum> eventType,
EventHandler handler) |
protected void |
serviceInit(Configuration conf)
All initialization code needed by a service.
|
protected void |
serviceStart()
Actions called during the INITED to STARTED transition.
|
protected void |
serviceStop()
Actions called during the transition to the STOPPED state.
|
void |
setDrainEventsOnStop() |
close, getBlockers, getConfig, getFailureCause, getFailureState, getLifecycleHistory, getName, getServiceState, getStartTime, init, isInState, noteFailure, putBlocker, registerGlobalListener, registerServiceListener, removeBlocker, setConfig, start, stop, toString, unregisterGlobalListener, unregisterServiceListener, waitForServiceToStop
protected final Map<Class<? extends Enum>,EventHandler> eventDispatchers
public AsyncDispatcher()
public AsyncDispatcher(BlockingQueue<Event> eventQueue)
public AsyncDispatcher(String dispatcherName)
dispatcherName
- name of the dispatcher threadprotected void serviceInit(Configuration conf) throws Exception
AbstractService
AbstractService.init(Configuration)
prevents re-entrancy.
The base implementation checks to see if the subclass has created
a new configuration instance, and if so, updates the base class valueserviceInit
in class AbstractService
conf
- configurationException
- on a failure -these will be caught,
possibly wrapped, and wil; trigger a service stopprotected void serviceStart() throws Exception
AbstractService
AbstractService.start()
prevents re-entrancy.serviceStart
in class AbstractService
Exception
- if needed -these will be caught,
wrapped, and trigger a service stoppublic void setDrainEventsOnStop()
protected void serviceStop() throws Exception
AbstractService
AbstractService.stop()
prevents re-entrancy.
Implementations MUST write this to be robust against failures, including
checks for null references -and for the first failure to not stop other
attempts to shut down parts of the service.serviceStop
in class AbstractService
Exception
- if needed -these will be caught and logged.protected void dispatch(Event event)
public void register(Class<? extends Enum> eventType, EventHandler handler)
register
in interface Dispatcher
public EventHandler getEventHandler()
getEventHandler
in interface Dispatcher
protected boolean isEventThreadWaiting()
protected boolean isDrained()
protected boolean isStopped()
Copyright © 2019 Apache Software Foundation. All rights reserved.