final class SubscriberRegistry
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
private static class |
SubscriberRegistry.MethodIdentifier |
Modifier and Type | Field and Description |
---|---|
private EventBus |
bus
The event bus this registry belongs to.
|
private static LoadingCache<java.lang.Class<?>,ImmutableSet<java.lang.Class<?>>> |
flattenHierarchyCache
Global cache of classes to their flattened hierarchy of supertypes.
|
private static LoadingCache<java.lang.Class<?>,ImmutableList<java.lang.reflect.Method>> |
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 . |
private java.util.concurrent.ConcurrentMap<java.lang.Class<?>,java.util.concurrent.CopyOnWriteArraySet<Subscriber>> |
subscribers
All registered subscribers, indexed by event type.
|
Constructor and Description |
---|
SubscriberRegistry(EventBus bus) |
Modifier and Type | Method and Description |
---|---|
private Multimap<java.lang.Class<?>,Subscriber> |
findAllSubscribers(java.lang.Object listener)
Returns all subscribers for the given listener grouped by the type of event they subscribe to.
|
(package private) static ImmutableSet<java.lang.Class<?>> |
flattenHierarchy(java.lang.Class<?> concreteClass)
Flattens a class's type hierarchy into a set of
Class objects including all
superclasses (transitively) and all interfaces implemented by these superclasses. |
private static ImmutableList<java.lang.reflect.Method> |
getAnnotatedMethods(java.lang.Class<?> clazz) |
private static ImmutableList<java.lang.reflect.Method> |
getAnnotatedMethodsNotCached(java.lang.Class<?> clazz) |
(package private) java.util.Iterator<Subscriber> |
getSubscribers(java.lang.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) java.util.Set<Subscriber> |
getSubscribersForTesting(java.lang.Class<?> eventType) |
(package private) void |
register(java.lang.Object listener)
Registers all subscriber methods on the given listener object.
|
(package private) void |
unregister(java.lang.Object listener)
Unregisters all subscribers on the given listener object.
|
private final java.util.concurrent.ConcurrentMap<java.lang.Class<?>,java.util.concurrent.CopyOnWriteArraySet<Subscriber>> subscribers
The CopyOnWriteArraySet
values make it easy and relatively lightweight to get an
immutable snapshot of all current subscribers to an event without any locking.
private final EventBus bus
private static final LoadingCache<java.lang.Class<?>,ImmutableList<java.lang.reflect.Method>> subscriberMethodsCache
@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.private static final LoadingCache<java.lang.Class<?>,ImmutableSet<java.lang.Class<?>>> flattenHierarchyCache
SubscriberRegistry(EventBus bus)
void register(java.lang.Object listener)
void unregister(java.lang.Object listener)
java.util.Set<Subscriber> getSubscribersForTesting(java.lang.Class<?> eventType)
java.util.Iterator<Subscriber> getSubscribers(java.lang.Object event)
private Multimap<java.lang.Class<?>,Subscriber> findAllSubscribers(java.lang.Object listener)
private static ImmutableList<java.lang.reflect.Method> getAnnotatedMethods(java.lang.Class<?> clazz)
private static ImmutableList<java.lang.reflect.Method> getAnnotatedMethodsNotCached(java.lang.Class<?> clazz)
static ImmutableSet<java.lang.Class<?>> flattenHierarchy(java.lang.Class<?> concreteClass)
Class
objects including all
superclasses (transitively) and all interfaces implemented by these superclasses.