Class SubscriberRegistry

java.lang.Object
com.google.common.eventbus.SubscriberRegistry

final class SubscriberRegistry extends Object
Registry of subscribers to a single event bus.
  • Field Details

    • subscribers

      private final ConcurrentMap<Class<?>,CopyOnWriteArraySet<Subscriber>> 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

      private final EventBus bus
      The event bus this registry belongs to.
    • subscriberMethodsCache

      private static final LoadingCache<Class<?>,ImmutableList<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. 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

      private static final LoadingCache<Class<?>,ImmutableSet<Class<?>>> flattenHierarchyCache
      Global cache of classes to their flattened hierarchy of supertypes.
  • Constructor Details

    • SubscriberRegistry

      SubscriberRegistry(EventBus bus)
  • Method Details

    • register

      void register(Object listener)
      Registers all subscriber methods on the given listener object.
    • unregister

      void unregister(Object listener)
      Unregisters all subscribers on the given listener object.
    • getSubscribersForTesting

      Set<Subscriber> getSubscribersForTesting(Class<?> eventType)
    • getSubscribers

      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.
    • findAllSubscribers

      private Multimap<Class<?>,Subscriber> findAllSubscribers(Object listener)
      Returns all subscribers for the given listener grouped by the type of event they subscribe to.
    • getAnnotatedMethods

      private static ImmutableList<Method> getAnnotatedMethods(Class<?> clazz)
    • getAnnotatedMethodsNotCached

      private static ImmutableList<Method> getAnnotatedMethodsNotCached(Class<?> clazz)
    • flattenHierarchy

      static ImmutableSet<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.