final class SubscriberRegistry extends 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 Map<Class<?>,Set<Class<?>>> |
flattenHierarchyCache
Global cache of classes to their flattened hierarchy of supertypes.
|
private ConcurrentMap<Class<?>,CopyOnWriteArraySet<Subscriber>> |
subscribers
All registered subscribers, indexed by event type.
|
| Constructor and Description |
|---|
SubscriberRegistry(EventBus bus)
Constructs a new
SubscriberRegistry. |
| Modifier and Type | Method and Description |
|---|---|
private 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 <T> T |
firstNonNull(T first,
T second)
Returns the first of two given parameters that is not
null, if either is, or otherwise
throws a NullPointerException. |
(package private) static Set<Class<?>> |
flattenHierarchy(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 List<Method> |
getAnnotatedMethods(Class<?> clazz) |
private static List<Method> |
getAnnotatedMethodsNotCached(Class<?> clazz) |
private static Set<Class<?>> |
getClassesAndInterfaces(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)
Returns subscribers for given
eventType. |
(package private) void |
register(Object listener)
Registers all subscriber methods on the given listener object.
|
(package private) void |
unregister(Object listener)
Unregisters all subscribers on the given listener object.
|
private final ConcurrentMap<Class<?>,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 static final Map<Class<?>,Set<Class<?>>> flattenHierarchyCache
SubscriberRegistry(EventBus bus)
SubscriberRegistry.bus - event busvoid register(Object listener)
listener - listenervoid unregister(Object listener)
listener - listenerSet<Subscriber> getSubscribersForTesting(Class<?> eventType)
eventType. Only used for unit tests.eventType - event typeeventType. Can be empty, but never nullIterator<Subscriber> getSubscribers(Object event)
event - eventprivate MultiMap<Class<?>,Subscriber> findAllSubscribers(Object listener)
listener - listenerprivate static List<Method> getAnnotatedMethods(Class<?> clazz)
private static List<Method> getAnnotatedMethodsNotCached(Class<?> clazz)
static Set<Class<?>> flattenHierarchy(Class<?> concreteClass)
Class objects including all
superclasses (transitively) and all interfaces implemented by these superclasses.concreteClass - concrete classClass objects including all superclasses and interfacesstatic <T> T firstNonNull(T first, T second)
null, if either is, or otherwise
throws a NullPointerException.
To find the first non-null element in an iterable, use Iterables.find(iterable,
Predicates.notNull()). For varargs, use Iterables.find(Arrays.asList(a, b, c, ...),
Predicates.notNull()), static importing as necessary.
T - object typefirst - first objectsecond - second objectfirst if it is non-null; otherwise second if it is non-nullNullPointerException - if both first and second are nullObjects.firstNonNull()).private static Set<Class<?>> getClassesAndInterfaces(Class<?> clazz)