Note
The dispatcher is orthogonal to the subscriber's Executor. The dispatcher
controls the order in which events are dispatched, while the executor controls how (i.e. on which
thread) the subscriber is actually called when an event is dispatched to it.
| Modifier and Type | Class and Description |
|---|---|
| private static class | Dispatcher.ImmediateDispatcher
Implementation of |
| private static class | Dispatcher.LegacyAsyncDispatcher
Implementation of a |
| private static class | Dispatcher.PerThreadQueuedDispatcher
Implementation of a |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv abstract void | dispatch(Object event, Iterator<Subscriber> subscribers)
Dispatches the given |
| pack-priv static Dispatcher | immediate()
Returns a dispatcher that dispatches events to subscribers immediately as they're posted without using an intermediate queue to change the dispatch order. |
| pack-priv static Dispatcher | |
| pack-priv static Dispatcher | perThreadDispatchQueue()
Returns a dispatcher that queues events that are posted reentrantly on a thread that is already dispatching an event, guaranteeing that all events posted on a single thread are dispatched to all subscribers in the order they are posted. |
| Dispatcher | back to summary |
|---|---|
| pack-priv Dispatcher() | |
| dispatch | back to summary |
|---|---|
| pack-priv abstract void dispatch(Object event, Iterator<Subscriber> subscribers) Dispatches the given | |
| immediate | back to summary |
|---|---|
| pack-priv static Dispatcher immediate() Returns a dispatcher that dispatches events to subscribers immediately as they're posted without using an intermediate queue to change the dispatch order. This is effectively a depth-first dispatch order, vs. breadth-first when using a queue. | |
| legacyAsync | back to summary |
|---|---|
| pack-priv static Dispatcher legacyAsync() Returns a dispatcher that queues events that are posted in a single global queue. This behavior matches the original behavior of AsyncEventBus exactly, but is otherwise not especially useful. For async dispatch, an immediate dispatcher should generally be preferable. | |
| perThreadDispatchQueue | back to summary |
|---|---|
| pack-priv static Dispatcher perThreadDispatchQueue() Returns a dispatcher that queues events that are posted reentrantly on a thread that is already dispatching an event, guaranteeing that all events posted on a single thread are dispatched to all subscribers in the order they are posted. When all subscribers are dispatched to using a direct executor (which dispatches on the same thread that posts the event), this yields a breadth-first dispatch order on each thread. That is, all subscribers to a single event A will be called before any subscribers to any events B and C that are posted to the event bus by the subscribers to A. | |
immediate().
| Modifier and Type | Field and Description |
|---|---|
| private static final Dispatcher. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv void | dispatch(Object event, Iterator<Subscriber> subscribers)
Implements abstract com. event to the given subscribers.
|
| INSTANCE | back to summary |
|---|---|
| private static final Dispatcher. | |
| ImmediateDispatcher | back to summary |
|---|---|
| private ImmediateDispatcher() | |
| dispatch | back to summary |
|---|---|
| pack-priv void dispatch(Object event, Iterator<Subscriber> subscribers) Implements abstract com. Doc from com. Dispatches the given
| |
legacyAsync() dispatcher.
| Modifier and Type | Class and Description |
|---|---|
| private static class |
| Modifier and Type | Field and Description |
|---|---|
| private final ConcurrentLinkedQueue | queue
Global event queue. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv void | dispatch(Object event, Iterator<Subscriber> subscribers)
Implements abstract com. event to the given subscribers.
|
| queue | back to summary |
|---|---|
| private final ConcurrentLinkedQueue<Dispatcher. Global event queue. | |
| LegacyAsyncDispatcher | back to summary |
|---|---|
| private LegacyAsyncDispatcher() | |
| dispatch | back to summary |
|---|---|
| pack-priv void dispatch(Object event, Iterator<Subscriber> subscribers) Implements abstract com. Doc from com. Dispatches the given
| |
| Modifier and Type | Field and Description |
|---|---|
| private final Object | |
| private final Subscriber |
| Access | Constructor and Description |
|---|---|
| private |
| event | back to summary |
|---|---|
| private final Object event | |
| subscriber | back to summary |
|---|---|
| private final Subscriber subscriber | |
| EventWithSubscriber | back to summary |
|---|---|
| private EventWithSubscriber(Object event, Subscriber subscriber) | |
perThreadDispatchQueue() dispatcher.
| Modifier and Type | Class and Description |
|---|---|
| private static class |
| Modifier and Type | Field and Description |
|---|---|
| private final ThreadLocal | dispatching
Per-thread dispatch state, used to avoid reentrant event dispatching. |
| private final ThreadLocal | queue
Per-thread queue of events to dispatch. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv void | dispatch(Object event, Iterator<Subscriber> subscribers)
Implements abstract com. event to the given subscribers.
|
| dispatching | back to summary |
|---|---|
| private final ThreadLocal<Boolean> dispatching Per-thread dispatch state, used to avoid reentrant event dispatching. | |
| queue | back to summary |
|---|---|
| private final ThreadLocal<Queue<Dispatcher. Per-thread queue of events to dispatch. | |
| PerThreadQueuedDispatcher | back to summary |
|---|---|
| private PerThreadQueuedDispatcher() | |
| dispatch | back to summary |
|---|---|
| pack-priv void dispatch(Object event, Iterator<Subscriber> subscribers) Implements abstract com. Doc from com. Dispatches the given
| |
| Modifier and Type | Field and Description |
|---|---|
| private final Object | |
| private final Iterator |
| Access | Constructor and Description |
|---|---|
| private |
| event | back to summary |
|---|---|
| private final Object event | |
| subscribers | back to summary |
|---|---|
| private final Iterator<Subscriber> subscribers | |
| Event | back to summary |
|---|---|
| private Event(Object event, Iterator<Subscriber> subscribers) | |