Top Description Inners Constructors Methods
com.google.common.eventbus

pack-priv abstract Class Dispatcher

extends Object
Class Inheritance
Known Direct Subclasses
com.google.common.eventbus.Dispatcher.PerThreadQueuedDispatcher, com.google.common.eventbus.Dispatcher.LegacyAsyncDispatcher, com.google.common.eventbus.Dispatcher.ImmediateDispatcher
Annotations
@ElementTypesAreNonnullByDefault
Static Imports
com.google.common.base.Preconditions.checkNotNull

Handler for dispatching events to subscribers, providing different event ordering guarantees that make sense for different situations.

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.

Author
Colin Decker

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class
Dispatcher.LegacyAsyncDispatcher

Implementation of a legacyAsync() dispatcher.

private static class

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv abstract void
dispatch(Object event, Iterator<Subscriber> subscribers)

Dispatches the given event to the given subscribers.

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
legacyAsync()

Returns a dispatcher that queues events that are posted in a single global queue.

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.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Dispatcherback to summary
pack-priv Dispatcher()

Method Detail

dispatchback to summary
pack-priv abstract void dispatch(Object event, Iterator<Subscriber> subscribers)

Dispatches the given event to the given subscribers.

immediateback 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.

legacyAsyncback 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.

perThreadDispatchQueueback 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.

com.google.common.eventbus back to summary

private final Class Dispatcher.ImmediateDispatcher

extends Dispatcher
Class Inheritance

Implementation of immediate().

Field Summary

Modifier and TypeField and Description
private static final Dispatcher.ImmediateDispatcher

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv void
dispatch(Object event, Iterator<Subscriber> subscribers)

Implements abstract com.google.common.eventbus.Dispatcher.dispatch.

Dispatches the given event to the given subscribers.
Inherited from com.google.common.eventbus.Dispatcher:
immediatelegacyAsyncperThreadDispatchQueue

Field Detail

INSTANCEback to summary
private static final Dispatcher.ImmediateDispatcher INSTANCE

Constructor Detail

ImmediateDispatcherback to summary
private ImmediateDispatcher()

Method Detail

dispatchback to summary
pack-priv void dispatch(Object event, Iterator<Subscriber> subscribers)

Implements abstract com.google.common.eventbus.Dispatcher.dispatch.

Doc from com.google.common.eventbus.Dispatcher.dispatch.

Dispatches the given event to the given subscribers.

Annotations
@Override
com.google.common.eventbus back to summary

private final Class Dispatcher.LegacyAsyncDispatcher

extends Dispatcher
Class Inheritance

Implementation of a legacyAsync() dispatcher.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private final ConcurrentLinkedQueue<Dispatcher.LegacyAsyncDispatcher.EventWithSubscriber>
queue

Global event queue.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv void
dispatch(Object event, Iterator<Subscriber> subscribers)

Implements abstract com.google.common.eventbus.Dispatcher.dispatch.

Dispatches the given event to the given subscribers.
Inherited from com.google.common.eventbus.Dispatcher:
immediatelegacyAsyncperThreadDispatchQueue

Field Detail

queueback to summary
private final ConcurrentLinkedQueue<Dispatcher.LegacyAsyncDispatcher.EventWithSubscriber> queue

Global event queue.

Constructor Detail

LegacyAsyncDispatcherback to summary
private LegacyAsyncDispatcher()

Method Detail

dispatchback to summary
pack-priv void dispatch(Object event, Iterator<Subscriber> subscribers)

Implements abstract com.google.common.eventbus.Dispatcher.dispatch.

Doc from com.google.common.eventbus.Dispatcher.dispatch.

Dispatches the given event to the given subscribers.

Annotations
@Override
com.google.common.eventbus back to summary

private final Class Dispatcher.LegacyAsyncDispatcher.EventWithSubscriber

extends Object
Class Inheritance
  • java.lang.Object
  • com.google.common.eventbus.Dispatcher.LegacyAsyncDispatcher.EventWithSubscriber

Field Summary

Modifier and TypeField and Description
private final Object
private final Subscriber

Constructor Summary

AccessConstructor and Description
private

Field Detail

eventback to summary
private final Object event
subscriberback to summary
private final Subscriber subscriber

Constructor Detail

EventWithSubscriberback to summary
private EventWithSubscriber(Object event, Subscriber subscriber)
com.google.common.eventbus back to summary

private final Class Dispatcher.PerThreadQueuedDispatcher

extends Dispatcher
Class Inheritance

Implementation of a perThreadDispatchQueue() dispatcher.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private final ThreadLocal<Boolean>
dispatching

Per-thread dispatch state, used to avoid reentrant event dispatching.

private final ThreadLocal<Queue<Dispatcher.PerThreadQueuedDispatcher.Event>>
queue

Per-thread queue of events to dispatch.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv void
dispatch(Object event, Iterator<Subscriber> subscribers)

Implements abstract com.google.common.eventbus.Dispatcher.dispatch.

Dispatches the given event to the given subscribers.
Inherited from com.google.common.eventbus.Dispatcher:
immediatelegacyAsyncperThreadDispatchQueue

Field Detail

dispatchingback to summary
private final ThreadLocal<Boolean> dispatching

Per-thread dispatch state, used to avoid reentrant event dispatching.

queueback to summary
private final ThreadLocal<Queue<Dispatcher.PerThreadQueuedDispatcher.Event>> queue

Per-thread queue of events to dispatch.

Constructor Detail

PerThreadQueuedDispatcherback to summary
private PerThreadQueuedDispatcher()

Method Detail

dispatchback to summary
pack-priv void dispatch(Object event, Iterator<Subscriber> subscribers)

Implements abstract com.google.common.eventbus.Dispatcher.dispatch.

Doc from com.google.common.eventbus.Dispatcher.dispatch.

Dispatches the given event to the given subscribers.

Annotations
@Override
com.google.common.eventbus back to summary

private final Class Dispatcher.PerThreadQueuedDispatcher.Event

extends Object
Class Inheritance
  • java.lang.Object
  • com.google.common.eventbus.Dispatcher.PerThreadQueuedDispatcher.Event

Field Summary

Modifier and TypeField and Description
private final Object
private final Iterator<Subscriber>

Constructor Summary

AccessConstructor and Description
private
Event(Object event, Iterator<Subscriber> subscribers)

Field Detail

eventback to summary
private final Object event
subscribersback to summary
private final Iterator<Subscriber> subscribers

Constructor Detail

Eventback to summary
private Event(Object event, Iterator<Subscriber> subscribers)