public abstract class AbstractEventBus
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
protected static java.lang.Class<Event> |
EVENT_CLASS |
protected java.util.Map<java.lang.Class<? extends Event>,java.util.List<EventRegistration>> |
eventRegistry |
protected ExceptionHandler |
exceptionHandler |
protected java.util.concurrent.locks.Lock |
readLock |
protected java.util.concurrent.locks.ReentrantReadWriteLock |
reentrantLock |
protected EventRegistrationListFactory |
registryListFactory |
protected java.util.concurrent.locks.Lock |
writeLock |
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractEventBus() |
protected |
AbstractEventBus(java.util.Map<java.lang.Class<? extends Event>,java.util.List<EventRegistration>> map,
EventRegistrationListFactory listFactory) |
| Modifier and Type | Method and Description |
|---|---|
protected static EventListener |
checkIsListenerValid(java.lang.reflect.Method method,
java.lang.Object instance) |
protected java.util.List<EventRegistration> |
getListenerRegistrations(java.lang.Class eventType) |
protected void |
handleException(java.lang.Throwable throwable) |
<T extends Event> |
post(T event)
Posts an event and returns it.
|
boolean |
postIsCancelled(Event event)
Posts an event and returns whether event has been cancelled or not.
|
<T extends Event> |
register(java.lang.Class<T> type,
EventDelegate<T> delegate)
Registers event listener.
|
<T extends Event> |
register(java.lang.Class<T> type,
EventDelegate<T> delegate,
boolean ignoreCancellation)
Registers event listener.
|
<T extends Event> |
register(java.lang.Class<T> type,
EventDelegate<T> delegate,
int priority)
Registers event listener.
|
<T extends Event> |
register(java.lang.Class<T> type,
EventDelegate<T> delegate,
int priority,
boolean ignoreCancellation)
Registers event listener.
|
void |
register(java.lang.Object eventHandler)
Looks for plain(non-static) annotated methods and registers them as an event
listeners.
|
java.util.List<EventRegistration> |
register(java.lang.Object eventHandler,
java.util.List<EventRegistration> out)
Looks for plain(non-static) annotated methods and registers them as an event
listeners.
|
protected void |
registerAnnotated(java.lang.Class<?> type,
java.lang.Object instance,
boolean registerStatic,
java.util.List<EventRegistration> registrationsOut) |
void |
registerStatic(java.lang.Class<?> eventHandler)
Looks for static annotated methods and registers them as an event listeners.
|
java.util.List<EventRegistration> |
registerStatic(java.lang.Class<?> eventHandler,
java.util.List<EventRegistration> out)
Looks for static annotated methods and registers them as an event listeners.
|
void |
setExceptionHandler(ExceptionHandler exceptionHandler)
Sets an exception handler for the event bus.
|
boolean |
unregister(EventRegistration registration)
Unregisters event listener.
|
protected static final java.lang.Class<Event> EVENT_CLASS
protected final java.util.concurrent.locks.ReentrantReadWriteLock reentrantLock
protected final java.util.concurrent.locks.Lock readLock
protected final java.util.concurrent.locks.Lock writeLock
protected final java.util.Map<java.lang.Class<? extends Event>,java.util.List<EventRegistration>> eventRegistry
protected EventRegistrationListFactory registryListFactory
protected ExceptionHandler exceptionHandler
protected AbstractEventBus()
protected AbstractEventBus(java.util.Map<java.lang.Class<? extends Event>,java.util.List<EventRegistration>> map, EventRegistrationListFactory listFactory)
public void setExceptionHandler(ExceptionHandler exceptionHandler)
exceptionHandler - The exception handlerpublic <T extends Event> EventRegistration<T> register(java.lang.Class<T> type, EventDelegate<T> delegate)
T - Event typetype - Event class objectdelegate - Listener delegatenull otherwise.public <T extends Event> EventRegistration<T> register(java.lang.Class<T> type, EventDelegate<T> delegate, int priority)
T - Event typetype - Event class objectdelegate - Listener delegatepriority - Listener prioritynull otherwise.public <T extends Event> EventRegistration<T> register(java.lang.Class<T> type, EventDelegate<T> delegate, boolean ignoreCancellation)
T - Event typetype - Event class objectdelegate - Listener delegateignoreCancellation - The flag that indicates whether listener will
ignore cancelled methods or not.null otherwise.public <T extends Event> EventRegistration<T> register(java.lang.Class<T> type, EventDelegate<T> delegate, int priority, boolean ignoreCancellation)
T - Event typetype - Event class objectdelegate - Listener delegatepriority - Listener priorityignoreCancellation - The flag that indicates whether listener will
ignore cancelled methods or not.null otherwise.public void register(java.lang.Object eventHandler)
eventHandler - The object with annotated methods.public java.util.List<EventRegistration> register(java.lang.Object eventHandler, java.util.List<EventRegistration> out)
eventHandler - The object with annotated methodsout - The list to which listener registrations will be addedout parameter with event registrations added.public void registerStatic(java.lang.Class<?> eventHandler)
eventHandler - The class object with annotated methodspublic java.util.List<EventRegistration> registerStatic(java.lang.Class<?> eventHandler, java.util.List<EventRegistration> out)
eventHandler - The class object with annotated methodsout - The list to which listener registrations will be addedout parameter with event registrations added.public boolean unregister(EventRegistration registration)
registration - The listener registrationtrue if succeed, false otherwise.public <T extends Event> T post(T event)
T - An event type.event - An event to be posted.event parameter.public boolean postIsCancelled(Event event)
event - An event to be posted.true if event has not been cancelled,
false otherwise.protected void handleException(java.lang.Throwable throwable)
protected java.util.List<EventRegistration> getListenerRegistrations(java.lang.Class eventType)
protected final void registerAnnotated(java.lang.Class<?> type,
java.lang.Object instance,
boolean registerStatic,
java.util.List<EventRegistration> registrationsOut)
protected static final EventListener checkIsListenerValid(java.lang.reflect.Method method, java.lang.Object instance)