Package com.google.common.eventbus
Class Subscriber
- java.lang.Object
-
- com.google.common.eventbus.Subscriber
-
- Direct Known Subclasses:
Subscriber.SynchronizedSubscriber
class Subscriber extends java.lang.ObjectA subscriber method on a specific object, plus the executor that should be used for dispatching events to it.Two subscribers are equivalent when they refer to the same method on the same object (not class). This property is used to ensure that no subscriber method is registered more than once.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classSubscriber.SynchronizedSubscriberSubscriber that synchronizes invocations of a method to ensure that only one thread may enter the method at a time.
-
Field Summary
Fields Modifier and Type Field Description private EventBusbusThe event bus this subscriber belongs to.private java.util.concurrent.ExecutorexecutorExecutor to use for dispatching events to this subscriber.private java.lang.reflect.MethodmethodSubscriber method.(package private) java.lang.ObjecttargetThe object with the subscriber method.
-
Constructor Summary
Constructors Modifier Constructor Description privateSubscriber(EventBus bus, java.lang.Object target, java.lang.reflect.Method method)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private SubscriberExceptionContextcontext(java.lang.Object event)Gets the context for the given event.(package private) static Subscribercreate(EventBus bus, java.lang.Object listener, java.lang.reflect.Method method)Creates aSubscriberformethodonlistener.(package private) voiddispatchEvent(java.lang.Object event)Dispatcheseventto this subscriber using the proper executor.booleanequals(java.lang.Object obj)inthashCode()(package private) voidinvokeSubscriberMethod(java.lang.Object event)Invokes the subscriber method.private static booleanisDeclaredThreadSafe(java.lang.reflect.Method method)Checks whethermethodis thread-safe, as indicated by the presence of theAllowConcurrentEventsannotation.
-
-
-
Field Detail
-
bus
private EventBus bus
The event bus this subscriber belongs to.
-
target
final java.lang.Object target
The object with the subscriber method.
-
method
private final java.lang.reflect.Method method
Subscriber method.
-
executor
private final java.util.concurrent.Executor executor
Executor to use for dispatching events to this subscriber.
-
-
Constructor Detail
-
Subscriber
private Subscriber(EventBus bus, java.lang.Object target, java.lang.reflect.Method method)
-
-
Method Detail
-
create
static Subscriber create(EventBus bus, java.lang.Object listener, java.lang.reflect.Method method)
Creates aSubscriberformethodonlistener.
-
dispatchEvent
final void dispatchEvent(java.lang.Object event)
Dispatcheseventto this subscriber using the proper executor.
-
invokeSubscriberMethod
void invokeSubscriberMethod(java.lang.Object event) throws java.lang.reflect.InvocationTargetExceptionInvokes the subscriber method. This method can be overridden to make the invocation synchronized.- Throws:
java.lang.reflect.InvocationTargetException
-
context
private SubscriberExceptionContext context(java.lang.Object event)
Gets the context for the given event.
-
hashCode
public final int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public final boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
isDeclaredThreadSafe
private static boolean isDeclaredThreadSafe(java.lang.reflect.Method method)
Checks whethermethodis thread-safe, as indicated by the presence of theAllowConcurrentEventsannotation.
-
-