class AnnotatedSubscriberFinder extends java.lang.Object implements SubscriberFindingStrategy
SubscriberFindingStrategy for collecting all event subscriber methods that are marked
with the Subscribe annotation.| Modifier and Type | Class and Description |
|---|---|
private static class |
AnnotatedSubscriberFinder.MethodIdentifier |
| Modifier and Type | Field and Description |
|---|---|
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. |
| Constructor and Description |
|---|
AnnotatedSubscriberFinder() |
| Modifier and Type | Method and Description |
|---|---|
Multimap<java.lang.Class<?>,EventSubscriber> |
findAllSubscribers(java.lang.Object listener)
Finds all suitable event subscriber methods in
source, organizes them
by the type of event they handle, and wraps them in EventSubscriber instances. |
private static ImmutableList<java.lang.reflect.Method> |
getAnnotatedMethods(java.lang.Class<?> clazz) |
private static ImmutableList<java.lang.reflect.Method> |
getAnnotatedMethodsInternal(java.lang.Class<?> clazz) |
private static EventSubscriber |
makeSubscriber(java.lang.Object listener,
java.lang.reflect.Method method)
Creates an
EventSubscriber for subsequently calling method on
listener. |
private static boolean |
methodIsDeclaredThreadSafe(java.lang.reflect.Method method)
Checks whether
method is thread-safe, as indicated by the
AllowConcurrentEvents annotation. |
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.public Multimap<java.lang.Class<?>,EventSubscriber> findAllSubscribers(java.lang.Object listener)
source, organizes them
by the type of event they handle, and wraps them in EventSubscriber instances.
This implementation finds all methods marked with a Subscribe annotation.findAllSubscribers in interface SubscriberFindingStrategylistener - object whose subscribers are desired.private static ImmutableList<java.lang.reflect.Method> getAnnotatedMethods(java.lang.Class<?> clazz)
private static ImmutableList<java.lang.reflect.Method> getAnnotatedMethodsInternal(java.lang.Class<?> clazz)
private static EventSubscriber makeSubscriber(java.lang.Object listener, java.lang.reflect.Method method)
EventSubscriber for subsequently calling method on
listener.
Selects an EventSubscriber implementation based on the annotations on
method.listener - object bearing the event subscriber method.method - the event subscriber method to wrap in an EventSubscriber.method on listener
when invoked.private static boolean methodIsDeclaredThreadSafe(java.lang.reflect.Method method)
method is thread-safe, as indicated by the
AllowConcurrentEvents annotation.method - subscriber method to check.true if subscriber is marked as thread-safe,
false otherwise.