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.
|
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.
|
<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)<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)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.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)<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 © 2015. All rights reserved.