Package com.google.common.eventbus
Class SubscriberRegistry
java.lang.Object
com.google.common.eventbus.SubscriberRegistry
Registry of subscribers to a single event bus.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final EventBus
The event bus this registry belongs to.private static final LoadingCache
<Class<?>, ImmutableSet<Class<?>>> Global cache of classes to their flattened hierarchy of supertypes.private static final LoadingCache
<Class<?>, ImmutableList<Method>> A thread-safe cache that contains the mapping from each class to all methods in that class and all super-classes, that are annotated with@Subscribe
.private final ConcurrentMap
<Class<?>, CopyOnWriteArraySet<Subscriber>> All registered subscribers, indexed by event type. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate Multimap
<Class<?>, Subscriber> findAllSubscribers
(Object listener) Returns all subscribers for the given listener grouped by the type of event they subscribe to.(package private) static ImmutableSet
<Class<?>> flattenHierarchy
(Class<?> concreteClass) Flattens a class's type hierarchy into a set ofClass
objects including all superclasses (transitively) and all interfaces implemented by these superclasses.private static ImmutableList
<Method> getAnnotatedMethods
(Class<?> clazz) private static ImmutableList
<Method> getAnnotatedMethodsNotCached
(Class<?> clazz) (package private) Iterator
<Subscriber> getSubscribers
(Object event) Gets an iterator representing an immutable snapshot of all subscribers to the given event at the time this method is called.(package private) Set
<Subscriber> getSubscribersForTesting
(Class<?> eventType) (package private) void
Registers all subscriber methods on the given listener object.(package private) void
unregister
(Object listener) Unregisters all subscribers on the given listener object.
-
Field Details
-
subscribers
All registered subscribers, indexed by event type.The
CopyOnWriteArraySet
values make it easy and relatively lightweight to get an immutable snapshot of all current subscribers to an event without any locking. -
bus
The event bus this registry belongs to. -
subscriberMethodsCache
A thread-safe cache that contains the mapping from each class to all methods in that class and all super-classes, that are annotated with@Subscribe
. The cache is shared across all instances of this class; this greatly improves performance if multiple EventBus instances are created and objects of the same class are registered on all of them. -
flattenHierarchyCache
Global cache of classes to their flattened hierarchy of supertypes.
-
-
Constructor Details
-
SubscriberRegistry
SubscriberRegistry(EventBus bus)
-
-
Method Details
-
register
Registers all subscriber methods on the given listener object. -
unregister
Unregisters all subscribers on the given listener object. -
getSubscribersForTesting
-
getSubscribers
Gets an iterator representing an immutable snapshot of all subscribers to the given event at the time this method is called. -
findAllSubscribers
Returns all subscribers for the given listener grouped by the type of event they subscribe to. -
getAnnotatedMethods
-
getAnnotatedMethodsNotCached
-
flattenHierarchy
Flattens a class's type hierarchy into a set ofClass
objects including all superclasses (transitively) and all interfaces implemented by these superclasses.
-