public interface EventBus
ApplicationEventPublisher in the following ways:
There are four event scopes, and therefore four event bus types (each with their own sub interface):
EventScope.APPLICATION events are published to the entire application.EventScope.SESSION events are published to the current session.EventScope.UI events are published to the current UI.EventScope.VIEW events are published to the current view.The event buses are chained in the following way:
ApplicationEventPublisher events can be propagated to any event bus
by using ApplicationContextEventBroker.
You select which EventBus implementation to inject by using the corresponding interface. For example, to
inject the UI-scoped event bus, you would use:
@Autowired UIEventBus myUIScopedEventBus;
With this implementation, you can subscribe to and publish events of the application, session and UI scopes (see
publish(EventScope, Object, Object)).
| Modifier and Type | Interface and Description |
|---|---|
static interface |
EventBus.ApplicationEventBus
Interface implemented by the application scoped event bus.
|
static interface |
EventBus.SessionEventBus
Interface implemented by the session scoped event bus.
|
static interface |
EventBus.UIEventBus
Interface implemented by the UI scoped event bus.
|
static interface |
EventBus.ViewEventBus
Interface implemented by the view scoped event bus.
|
| Modifier and Type | Method and Description |
|---|---|
EventScope |
getScope()
Gets the scope of the events published on this event bus.
|
<T> void |
publish(EventScope scope,
Object sender,
T payload)
Publishes the specified payload on the event bus, or any of its parent buses, depending on the event scope.
|
<T> void |
publish(EventScope scope,
String topic,
Object sender,
T payload)
Publishes the specified payload on the event bus, or any of its parent buses, depending on the event scope.
|
<T> void |
publish(Object sender,
T payload)
Publishes the specified payload on the event bus, using the scope of this particular event bus.
|
<T> void |
publish(String topic,
Object sender,
T payload)
Publishes the specified payload on the event bus, using the scope of this particular event bus.
|
<T> void |
subscribe(EventBusListener<T> listener)
Subscribes the specified listener to the event bus, including propagated events from parent event buses.
|
<T> void |
subscribe(EventBusListener<T> listener,
boolean includingPropagatingEvents)
Subscribes the specified listener to the event bus.
|
<T> void |
subscribe(EventBusListener<T> listener,
String topic)
Subscribes the topic interested listener to the event bus, including propagated events from parent event buses.
|
void |
subscribe(Object listener)
Subscribes the specified listener to the event bus.
|
void |
subscribe(Object listener,
boolean includingPropagatingEvents)
Subscribes the specified listener to the event bus.
|
void |
subscribe(Object listener,
String topic)
Subscribes the topic interested listener to the event bus.
|
<T> void |
subscribeWithWeakReference(EventBusListener<T> listener)
Same as
subscribe(EventBusListener), but uses a weak reference to store the listener internally. |
<T> void |
subscribeWithWeakReference(EventBusListener<T> listener,
boolean includingPropagatingEvents)
Same as
subscribe(EventBusListener, boolean), but uses a weak reference to store the listener
internally. |
<T> void |
subscribeWithWeakReference(EventBusListener<T> listener,
String topic)
Same as
subscribe(EventBusListener, String), but uses a weak reference to store the listener
internally. |
void |
subscribeWithWeakReference(Object listener)
Same as
subscribe(Object), but uses a weak reference to store the listener internally. |
void |
subscribeWithWeakReference(Object listener,
boolean includingPropagatingEvents)
Same as
subscribe(Object, boolean), but uses a weak reference to store the listener internally. |
void |
subscribeWithWeakReference(Object listener,
String topic)
Same as
subscribe(Object, String), but uses a weak reference to store the listener internally. |
<T> void |
unsubscribe(EventBusListener<T> listener)
Unsubscribes the specified listener from the event bus.
|
void |
unsubscribe(Object listener)
Unsubscribes the specified listener (and all its listener methods) from the event bus.
|
<T> void publish(Object sender, T payload)
T - the type of the payload.sender - the object that published the event, never null.payload - the payload of the event to publish, never null.getScope()<T> void publish(String topic, Object sender, T payload)
T - the type of the payload.topic - the topic of the event to publish, never null.sender - the object that published the event, never null.payload - the payload of the event to publish, never null.getScope()<T> void publish(EventScope scope, Object sender, T payload) throws UnsupportedOperationException
T - the type of the payload;scope - the scope of the event, never null.sender - the object that published the event, never null.payload - the payload of the event to publish, never null.UnsupportedOperationException - if the payload could not be published with the specified scope.publish(Object, Object)<T> void publish(EventScope scope, String topic, Object sender, T payload) throws UnsupportedOperationException
T - the type of the payload;scope - the scope of the event, never null.topic - the topic of the event to publish, never null.sender - the object that published the event, never null.payload - the payload of the event to publish, never null.UnsupportedOperationException - if the payload could not be published with the specified scope.publish(Object, Object)EventScope getScope()
null.Event.getScope()<T> void subscribe(EventBusListener<T> listener)
subscribe(listener, true).T - the type of payload the listener is interested in.listener - the listener to subscribe, never null.unsubscribe(EventBusListener),
subscribeWithWeakReference(EventBusListener)<T> void subscribeWithWeakReference(EventBusListener<T> listener)
subscribe(EventBusListener), but uses a weak reference to store the listener internally.<T> void subscribe(EventBusListener<T> listener, String topic)
T - the type of payload the listener is interested inlistener - the listener to subscribe, never nulltopic - the topic of listener interest<T> void subscribeWithWeakReference(EventBusListener<T> listener, String topic)
subscribe(EventBusListener, String), but uses a weak reference to store the listener
internally.<T> void subscribe(EventBusListener<T> listener, boolean includingPropagatingEvents)
T - the type of payload the listener is interested in.listener - the listener to subscribe, never null.includingPropagatingEvents - true to notify the listener of events that have propagated from the chain of
parent event buses, false to only notify the listeners of events that are directly published on this event
bus.unsubscribe(EventBusListener),
subscribeWithWeakReference(EventBusListener, boolean)<T> void subscribeWithWeakReference(EventBusListener<T> listener, boolean includingPropagatingEvents)
subscribe(EventBusListener, boolean), but uses a weak reference to store the listener
internally.void subscribe(Object listener)
EventBusListener interface,
but must contain one or more methods that are annotated with the
EventBusListenerMethod interface and conform to one of these method
signatures: myMethodName(Event<MyPayloadType>) or myMethodName(MyPayloadType).
The event bus will analyse the payload type of the listener methods to determine
which events the different methods are interested in receiving. This is the same as calling
subscribe(listener, true).listener - the listener to subscribe, never null.subscribeWithWeakReference(Object)void subscribeWithWeakReference(Object listener)
subscribe(Object), but uses a weak reference to store the listener internally.void subscribe(Object listener, String topic)
EventBusListener interface,
but must contain one or more methods that are annotated with the
EventBusListenerMethod interface and conform to one of these method
signatures: myMethodName(Event<MyPayloadType>) or myMethodName(MyPayloadType).
The event bus will analyse the payload type of the listener methods to determine
which events the different methods are interested in receiving.
subscribe(Listener.this, "/news");listener - the listener to subscribe, never null.topic - the topic of listener interestsubscribeWithWeakReference(Object, String)void subscribeWithWeakReference(Object listener, String topic)
subscribe(Object, String), but uses a weak reference to store the listener internally.void subscribe(Object listener, boolean includingPropagatingEvents)
EventBusListener interface,
but must contain one or more methods that are annotated with the
EventBusListenerMethod interface and conform to one of these method
signatures: myMethodName(Event<MyPayloadType>) or myMethodName(MyPayloadType).
The event bus will analyse the payload type of the listener methods to determine
which events the different methods are interested in receiving.listener - the listener to subscribe, never null.includingPropagatingEvents - true to notify the listener of events that have propagated from the chain of
parent event buses, false to only notify the listeners of events that are directly published on this event
bus.unsubscribe(Object),
subscribeWithWeakReference(Object, boolean)void subscribeWithWeakReference(Object listener, boolean includingPropagatingEvents)
subscribe(Object, boolean), but uses a weak reference to store the listener internally.<T> void unsubscribe(EventBusListener<T> listener)
T - the type of the payload.listener - the listener to unsubscribe, never null.subscribe(EventBusListener),
subscribe(EventBusListener, boolean)void unsubscribe(Object listener)
listener - the listener to unsubscribe, never null.subscribe(Object),
subscribe(Object, boolean)Copyright © 2017. All rights reserved.