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 Map<String,List<CallableWithArgs<?>>> |
callableListeners |
protected List<Object> |
listeners |
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.
|
void |
addEventListener(Map<String,CallableWithArgs<?>> 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.
|
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) |
boolean |
isEventPublishingEnabled()
Returns whether events will be published by the event bus or not.
|
protected boolean |
isNestedListener(CallableWithArgs<?> 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.
|
void |
removeEventListener(Map<String,CallableWithArgs<?>> 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.
|
protected void |
removeNestedListeners(Object owner) |
void |
setEventPublishingEnabled(boolean enabled)
Sets the enabled state for event publishing.
|
protected static final Object[] LOCK
protected final Map<String,List<CallableWithArgs<?>>> callableListeners
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 listenerprotected 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 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,CallableWithArgs<?>> listener)
EventPublisher
An event listener may be a
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,CallableWithArgs<?>> listener)
EventPublisher
An event listener may be a
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 removeEventListener(@Nonnull String eventName, @Nonnull CallableWithArgs<?> listener)
EventPublisher
removeEventListener
in interface EventPublisher
eventName
- the name of the eventlistener
- an event listenerprotected Runnable buildPublisher(@Nonnull String event, @Nonnull List<?> params, @Nonnull String mode)
protected boolean isNestedListener(@Nonnull CallableWithArgs<?> listener, @Nonnull Object owner)