public abstract class AbstractEventRouter extends java.lang.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 java.util.concurrent.atomic.AtomicInteger |
EVENT_ROUTER_ID |
protected int |
eventRouterId |
protected java.util.concurrent.ExecutorService |
executorService |
protected ExecutorServiceManager |
executorServiceManager |
protected java.util.Map<java.lang.String,java.util.List<java.lang.Object>> |
functionalListeners |
protected java.util.Map<java.lang.String,java.util.List<java.lang.Object>> |
instanceListeners |
protected static java.lang.Object[] |
LOCK |
Constructor and Description |
---|
AbstractEventRouter() |
Modifier and Type | Method and Description |
---|---|
<E extends Event> |
addEventListener(java.lang.Class<E> eventClass,
CallableWithArgs<?> listener)
Adds a callable as an event listener.
|
<E extends Event> |
addEventListener(java.lang.Class<E> eventClass,
RunnableWithArgs listener)
Adds a callable as an event listener.
|
void |
addEventListener(java.util.Map<java.lang.String,java.lang.Object> listener)
Adds a Map containing event listeners.
|
void |
addEventListener(java.lang.Object listener)
Adds an event listener.
|
void |
addEventListener(java.lang.String eventName,
CallableWithArgs<?> listener)
Adds a callable as an event listener.
|
void |
addEventListener(java.lang.String eventName,
RunnableWithArgs listener)
Adds a callable as an event listener.
|
protected java.lang.Object[] |
asArray(java.util.List<?> list) |
protected java.lang.Runnable |
buildPublisher(java.lang.String event,
java.util.List<?> params,
java.lang.String mode) |
protected abstract void |
doPublishAsync(java.lang.Runnable publisher) |
protected abstract void |
doPublishOutsideUI(java.lang.Runnable publisher) |
protected void |
fireEvent(CallableWithArgs<?> callable,
java.util.List<?> params) |
protected void |
fireEvent(java.lang.Object instance,
java.lang.String eventHandler,
java.util.List<?> params) |
protected void |
fireEvent(RunnableWithArgs runnable,
java.util.List<?> params) |
java.util.Collection<java.lang.Object> |
getEventListeners()
Returns an immutable snapshot view of all event listeners registered.
|
java.util.Collection<java.lang.Object> |
getEventListeners(java.lang.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(java.lang.Object listener,
java.lang.Object owner) |
void |
publishEvent(Event event)
Publishes an event.
|
void |
publishEvent(java.lang.String eventName)
Publishes an event.
|
void |
publishEvent(java.lang.String eventName,
java.util.List<?> params)
Publishes an event.
|
void |
publishEventAsync(Event event)
Publishes an event.
|
void |
publishEventAsync(java.lang.String eventName)
Publishes an event.
|
void |
publishEventAsync(java.lang.String eventName,
java.util.List<?> params)
Publishes an event.
|
void |
publishEventOutsideUI(Event event)
Publishes an event.
|
void |
publishEventOutsideUI(java.lang.String eventName)
Publishes an event.
|
void |
publishEventOutsideUI(java.lang.String eventName,
java.util.List<?> params)
Publishes an event.
|
<E extends Event> |
removeEventListener(java.lang.Class<E> eventClass,
CallableWithArgs<?> listener)
Removes a callable as an event listener.
|
<E extends Event> |
removeEventListener(java.lang.Class<E> eventClass,
RunnableWithArgs listener)
Removes a callable as an event listener.
|
void |
removeEventListener(java.util.Map<java.lang.String,java.lang.Object> listener)
Removes a Map containing event listeners.
|
void |
removeEventListener(java.lang.Object listener)
Removes an event listener.
|
void |
removeEventListener(java.lang.String eventName,
CallableWithArgs<?> listener)
Removes a callable as an event listener.
|
void |
removeEventListener(java.lang.String eventName,
RunnableWithArgs listener)
Removes a callable as an event listener.
|
protected boolean |
removeNestedListeners(java.lang.Object owner) |
protected void |
runInsideExecutorService(java.lang.Runnable runnable) |
void |
setEventPublishingEnabled(boolean enabled)
Sets the enabled state for event publishing.
|
void |
setExecutorServiceManager(ExecutorServiceManager executorServiceManager) |
protected static final java.lang.Object[] LOCK
protected final java.util.Map<java.lang.String,java.util.List<java.lang.Object>> instanceListeners
protected final java.util.Map<java.lang.String,java.util.List<java.lang.Object>> functionalListeners
protected static final java.util.concurrent.atomic.AtomicInteger EVENT_ROUTER_ID
protected ExecutorServiceManager executorServiceManager
protected final java.util.concurrent.ExecutorService executorService
protected final int eventRouterId
@Inject public void setExecutorServiceManager(@Nonnull ExecutorServiceManager executorServiceManager)
protected void runInsideExecutorService(@Nonnull java.lang.Runnable runnable)
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 java.lang.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 java.lang.String eventName, @Nullable java.util.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 java.lang.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 java.lang.String eventName, @Nullable java.util.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 listenersprotected abstract void doPublishOutsideUI(@Nonnull java.lang.Runnable publisher)
public void publishEventAsync(@Nonnull java.lang.String eventName)
EventPublisher
Listeners will be notified in a different thread.
publishEventAsync
in interface EventPublisher
eventName
- the name of the eventpublic void publishEventAsync(@Nonnull java.lang.String eventName, @Nullable java.util.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 listenersprotected abstract void doPublishAsync(@Nonnull java.lang.Runnable publisher)
public 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 java.lang.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 java.lang.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 java.util.List<?> params)
protected void fireEvent(@Nonnull CallableWithArgs<?> callable, @Nonnull java.util.List<?> params)
protected void fireEvent(@Nonnull java.lang.Object instance, @Nonnull java.lang.String eventHandler, @Nonnull java.util.List<?> params)
public <E extends Event> void addEventListener(@Nonnull java.lang.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 java.lang.Class<E> eventClass, @Nonnull RunnableWithArgs listener)
EventPublisher
addEventListener
in interface EventPublisher
eventClass
- the type of the eventlistener
- an event listenerpublic void addEventListener(@Nonnull java.lang.Object listener)
EventPublisher
Accepted types are: Script, Map and Object.
addEventListener
in interface EventPublisher
listener
- an event listenerpublic void addEventListener(@Nonnull java.util.Map<java.lang.String,java.lang.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 java.lang.Object listener)
EventPublisher
Accepted types are: Script, Map and Object.
removeEventListener
in interface EventPublisher
listener
- an event listenerpublic void removeEventListener(@Nonnull java.util.Map<java.lang.String,java.lang.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 java.lang.String eventName, @Nonnull CallableWithArgs<?> listener)
EventPublisher
addEventListener
in interface EventPublisher
eventName
- the name of the eventlistener
- an event listenerpublic void addEventListener(@Nonnull java.lang.String eventName, @Nonnull RunnableWithArgs listener)
EventPublisher
addEventListener
in interface EventPublisher
eventName
- the name of the eventlistener
- an event listenerpublic void removeEventListener(@Nonnull java.lang.String eventName, @Nonnull CallableWithArgs<?> listener)
EventPublisher
removeEventListener
in interface EventPublisher
eventName
- the name of the eventlistener
- an event listenerpublic void removeEventListener(@Nonnull java.lang.String eventName, @Nonnull RunnableWithArgs listener)
EventPublisher
removeEventListener
in interface EventPublisher
eventName
- the name of the eventlistener
- an event listener@Nonnull public java.util.Collection<java.lang.Object> getEventListeners()
EventPublisher
getEventListeners
in interface EventPublisher
@Nonnull public java.util.Collection<java.lang.Object> getEventListeners(@Nonnull java.lang.String eventName)
EventPublisher
getEventListeners
in interface EventPublisher
eventName
- the name of the eventprotected java.lang.Runnable buildPublisher(@Nonnull java.lang.String event, @Nonnull java.util.List<?> params, @Nonnull java.lang.String mode)
protected boolean removeNestedListeners(@Nonnull java.lang.Object owner)
protected boolean isNestedListener(@Nonnull java.lang.Object listener, @Nonnull java.lang.Object owner)
protected java.lang.Object[] asArray(@Nonnull java.util.List<?> list)