public abstract class AbstractEventRouter extends Object implements EventRouter
Modifier and Type | Class and Description |
---|---|
protected static class |
AbstractEventRouter.MethodCache |
protected static class |
AbstractEventRouter.MethodInfo |
Modifier and Type | Field and Description |
---|---|
protected static AtomicInteger |
EVENT_ROUTER_ID |
protected int |
eventRouterId |
protected ExecutorService |
executorService |
protected ExecutorServiceManager |
executorServiceManager |
protected Map<String,List<Object>> |
functionalListeners |
protected Map<String,List<Object>> |
instanceListeners |
protected static Object[] |
LOCK |
Constructor and Description |
---|
AbstractEventRouter() |
Modifier and Type | Method and Description |
---|---|
<E extends Event> |
addEventListener(Class<E> eventClass,
CallableWithArgs<?> listener)
Adds a callable as an event listener.
|
<E extends Event> |
addEventListener(Class<E> eventClass,
RunnableWithArgs listener)
Adds a callable as an event listener.
|
void |
addEventListener(Map<String,Object> listener)
Adds a Map containing event listeners.
|
void |
addEventListener(Object listener)
Adds an event listener.
|
void |
addEventListener(String eventName,
CallableWithArgs<?> listener)
Adds a callable as an event listener.
|
void |
addEventListener(String eventName,
RunnableWithArgs listener)
Adds a callable as an event listener.
|
protected Object[] |
asArray(List<?> list) |
protected Runnable |
buildPublisher(String event,
List<?> params,
String mode) |
protected abstract void |
doPublishAsync(Runnable publisher) |
protected abstract void |
doPublishOutsideUI(Runnable publisher) |
protected void |
fireEvent(CallableWithArgs<?> callable,
List<?> params) |
protected void |
fireEvent(Object instance,
String eventHandler,
List<?> params) |
protected void |
fireEvent(RunnableWithArgs runnable,
List<?> params) |
Collection<Object> |
getEventListeners()
Returns an immutable snapshot view of all event listeners registered.
|
Collection<Object> |
getEventListeners(String eventName)
Returns an immutable snapshot view of all event listeners registered for the target event name.
|
boolean |
isEventPublishingEnabled()
Returns whether events will be published by the event bus or not.
|
protected boolean |
isNestedListener(Object listener,
Object owner) |
void |
publishEvent(Event event)
Publishes an event.
|
void |
publishEvent(String eventName)
Publishes an event.
|
void |
publishEvent(String eventName,
List<?> params)
Publishes an event.
|
void |
publishEventAsync(Event event)
Publishes an event.
|
void |
publishEventAsync(String eventName)
Publishes an event.
|
void |
publishEventAsync(String eventName,
List<?> params)
Publishes an event.
|
void |
publishEventOutsideUI(Event event)
Publishes an event.
|
void |
publishEventOutsideUI(String eventName)
Publishes an event.
|
void |
publishEventOutsideUI(String eventName,
List<?> params)
Publishes an event.
|
<E extends Event> |
removeEventListener(Class<E> eventClass,
CallableWithArgs<?> listener)
Removes a callable as an event listener.
|
<E extends Event> |
removeEventListener(Class<E> eventClass,
RunnableWithArgs listener)
Removes a callable as an event listener.
|
void |
removeEventListener(Map<String,Object> listener)
Removes a Map containing event listeners.
|
void |
removeEventListener(Object listener)
Removes an event listener.
|
void |
removeEventListener(String eventName,
CallableWithArgs<?> listener)
Removes a callable as an event listener.
|
void |
removeEventListener(String eventName,
RunnableWithArgs listener)
Removes a callable as an event listener.
|
protected boolean |
removeNestedListeners(Object owner) |
protected void |
runInsideExecutorService(Runnable runnable) |
void |
setEventPublishingEnabled(boolean enabled)
Sets the enabled state for event publishing.
|
void |
setExecutorServiceManager(ExecutorServiceManager executorServiceManager) |
protected static final Object[] LOCK
protected static final AtomicInteger EVENT_ROUTER_ID
protected ExecutorServiceManager executorServiceManager
protected final ExecutorService executorService
protected final int eventRouterId
@Inject public void setExecutorServiceManager(@Nonnull ExecutorServiceManager executorServiceManager)
public boolean isEventPublishingEnabled()
EventPublisher
isEventPublishingEnabled
in interface EventPublisher
public void setEventPublishingEnabled(boolean enabled)
EventPublisher
setEventPublishingEnabled
in interface EventPublisher
enabled
- the value fot the enabled state.public void publishEvent(@Nonnull String eventName)
EventPublisher
Listeners will be notified in the same thread as the publisher.
publishEvent
in interface EventPublisher
eventName
- the name of the eventpublic void publishEvent(@Nonnull String eventName, @Nullable List<?> params)
EventPublisher
Listeners will be notified in the same thread as the publisher.
publishEvent
in interface EventPublisher
eventName
- the name of the eventparams
- event arguments sent to listenerspublic void publishEventOutsideUI(@Nonnull String eventName)
EventPublisher
Listeners will be notified outside of the UI thread.
publishEventOutsideUI
in interface EventPublisher
eventName
- the name of the eventpublic void publishEventOutsideUI(@Nonnull String eventName, @Nullable List<?> params)
EventPublisher
Listeners will be notified outside of the UI thread.
publishEventOutsideUI
in interface EventPublisher
eventName
- the name of the eventparams
- event arguments sent to listenerspublic void publishEventAsync(@Nonnull String eventName)
EventPublisher
Listeners will be notified in a different thread.
publishEventAsync
in interface EventPublisher
eventName
- the name of the eventpublic void publishEventAsync(@Nonnull String eventName, @Nullable List<?> params)
EventPublisher
Listeners will be notified in a different thread.
publishEventAsync
in interface EventPublisher
eventName
- the name of the eventparams
- event arguments sent to listenerspublic void publishEvent(@Nonnull Event event)
EventPublisher
Listeners will be notified in the same thread as the publisher.
publishEvent
in interface EventPublisher
event
- the event to be publishedpublic void publishEventOutsideUI(@Nonnull Event event)
EventPublisher
Listeners will be notified outside of the UI thread.
publishEventOutsideUI
in interface EventPublisher
event
- the event to be publishedpublic void publishEventAsync(@Nonnull Event event)
EventPublisher
Listeners will be notified in a different thread.
publishEventAsync
in interface EventPublisher
event
- the event to be publishedpublic <E extends Event> void removeEventListener(@Nonnull Class<E> eventClass, @Nonnull CallableWithArgs<?> listener)
EventPublisher
removeEventListener
in interface EventPublisher
eventClass
- the type of the eventlistener
- an event listenerpublic <E extends Event> void removeEventListener(@Nonnull Class<E> eventClass, @Nonnull RunnableWithArgs listener)
EventPublisher
removeEventListener
in interface EventPublisher
eventClass
- the type of the eventlistener
- an event listenerprotected void fireEvent(@Nonnull RunnableWithArgs runnable, @Nonnull List<?> params)
protected void fireEvent(@Nonnull CallableWithArgs<?> callable, @Nonnull List<?> params)
protected void fireEvent(@Nonnull Object instance, @Nonnull String eventHandler, @Nonnull List<?> params)
public <E extends Event> void addEventListener(@Nonnull Class<E> eventClass, @Nonnull CallableWithArgs<?> listener)
EventPublisher
addEventListener
in interface EventPublisher
eventClass
- the type of the eventlistener
- an event listenerpublic <E extends Event> void addEventListener(@Nonnull Class<E> eventClass, @Nonnull RunnableWithArgs listener)
EventPublisher
addEventListener
in interface EventPublisher
eventClass
- the type of the eventlistener
- an event listenerpublic void addEventListener(@Nonnull Object listener)
EventPublisher
Accepted types are: Script, Map and Object.
addEventListener
in interface EventPublisher
listener
- an event listenerpublic void addEventListener(@Nonnull Map<String,Object> listener)
EventPublisher
An event listener may be
Maps require handlers to be named as eventName only.
Some examples of eventHandler names are: StartupStart, MyCoolEvent. Event names must follow the camelCase naming convention.
addEventListener
in interface EventPublisher
listener
- an event listener of type Mappublic void removeEventListener(@Nonnull Object listener)
EventPublisher
Accepted types are: Script, Map and Object.
removeEventListener
in interface EventPublisher
listener
- an event listenerpublic void removeEventListener(@Nonnull Map<String,Object> listener)
EventPublisher
An event listener may be
Maps require handlers to be named as eventName only.
Some examples of eventHandler names are: StartupStart, MyCoolEvent. Event names must follow the camelCase naming convention.
removeEventListener
in interface EventPublisher
listener
- an event listener of type Mappublic void addEventListener(@Nonnull String eventName, @Nonnull CallableWithArgs<?> listener)
EventPublisher
addEventListener
in interface EventPublisher
eventName
- the name of the eventlistener
- an event listenerpublic void addEventListener(@Nonnull String eventName, @Nonnull RunnableWithArgs listener)
EventPublisher
addEventListener
in interface EventPublisher
eventName
- the name of the eventlistener
- an event listenerpublic void removeEventListener(@Nonnull String eventName, @Nonnull CallableWithArgs<?> listener)
EventPublisher
removeEventListener
in interface EventPublisher
eventName
- the name of the eventlistener
- an event listenerpublic void removeEventListener(@Nonnull String eventName, @Nonnull RunnableWithArgs listener)
EventPublisher
removeEventListener
in interface EventPublisher
eventName
- the name of the eventlistener
- an event listener@Nonnull public Collection<Object> getEventListeners()
EventPublisher
getEventListeners
in interface EventPublisher
@Nonnull public Collection<Object> getEventListeners(@Nonnull String eventName)
EventPublisher
getEventListeners
in interface EventPublisher
eventName
- the name of the eventprotected Runnable buildPublisher(@Nonnull String event, @Nonnull List<?> params, @Nonnull String mode)
protected boolean isNestedListener(@Nonnull Object listener, @Nonnull Object owner)