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.Object
A 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 class
Subscriber.SynchronizedSubscriber
Subscriber 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 EventBus
bus
The event bus this subscriber belongs to.private java.util.concurrent.Executor
executor
Executor to use for dispatching events to this subscriber.private java.lang.reflect.Method
method
Subscriber method.(package private) java.lang.Object
target
The object with the subscriber method.
-
Constructor Summary
Constructors Modifier Constructor Description private
Subscriber(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 SubscriberExceptionContext
context(java.lang.Object event)
Gets the context for the given event.(package private) static Subscriber
create(EventBus bus, java.lang.Object listener, java.lang.reflect.Method method)
Creates aSubscriber
formethod
onlistener
.(package private) void
dispatchEvent(java.lang.Object event)
Dispatchesevent
to this subscriber using the proper executor.boolean
equals(java.lang.Object obj)
int
hashCode()
(package private) void
invokeSubscriberMethod(java.lang.Object event)
Invokes the subscriber method.private static boolean
isDeclaredThreadSafe(java.lang.reflect.Method method)
Checks whethermethod
is thread-safe, as indicated by the presence of theAllowConcurrentEvents
annotation.
-
-
-
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 aSubscriber
formethod
onlistener
.
-
dispatchEvent
final void dispatchEvent(java.lang.Object event)
Dispatchesevent
to this subscriber using the proper executor.
-
invokeSubscriberMethod
void invokeSubscriberMethod(java.lang.Object event) throws java.lang.reflect.InvocationTargetException
Invokes 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:
hashCode
in classjava.lang.Object
-
equals
public final boolean equals(@Nullable java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
isDeclaredThreadSafe
private static boolean isDeclaredThreadSafe(java.lang.reflect.Method method)
Checks whethermethod
is thread-safe, as indicated by the presence of theAllowConcurrentEvents
annotation.
-
-