Package org.vaadin.spring.events
Interface EventBus
- All Known Subinterfaces:
EventBus.ApplicationEventBus,EventBus.SessionEventBus,EventBus.UIEventBus,EventBus.ViewEventBus
- All Known Implementing Classes:
ScopedEventBus,ScopedEventBus.DefaultApplicationEventBus,ScopedEventBus.DefaultSessionEventBus,ScopedEventBus.DefaultUIEventBus,ScopedEventBus.DefualtViewEventBus
public interface EventBus
Interface defining an event bus. This event bus infrastructure complements the
ApplicationEventPublisher in the following ways:
- Events propagate from parent buses to children
- Events are scoped
There are four event scopes, and therefore four event bus types (each with their own sub interface):
EventScope.APPLICATIONevents are published to the entire application.EventScope.SESSIONevents are published to the current session.EventScope.UIevents are published to the current UI.EventScope.VIEWevents are published to the current view.
The event buses are chained in the following way:
- Application events are propagated to the session event bus.
- Session events are propagated to the UI event bus.
- UI events are propagated to the view event bus.
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)).
- Author:
- Petter Holmström (petter@vaadin.com)
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceInterface implemented by the application scoped event bus.static interfaceInterface implemented by the session scoped event bus.static interfaceInterface implemented by the UI scoped event bus.static interfaceInterface implemented by the view scoped event bus. -
Method Summary
Modifier and TypeMethodDescriptiongetScope()Gets the scope of the events published on this event bus.<T> voidPublishes the specified payload on the event bus, using the scope of this particular event bus.<T> voidPublishes the specified payload on the event bus, using the scope of this particular event bus.<T> voidpublish(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> voidpublish(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.voidSubscribes the specified listener to the event bus.voidSubscribes the specified listener to the event bus.voidSubscribes the topic interested listener to the event bus.<T> voidsubscribe(EventBusListener<T> listener) Subscribes the specified listener to the event bus, including propagated events from parent event buses.<T> voidsubscribe(EventBusListener<T> listener, boolean includingPropagatingEvents) Subscribes the specified listener to the event bus.<T> voidsubscribe(EventBusListener<T> listener, String topic) Subscribes the topic interested listener to the event bus, including propagated events from parent event buses.voidsubscribeWithWeakReference(Object listener) Same assubscribe(Object), but uses a weak reference to store the listener internally.voidsubscribeWithWeakReference(Object listener, boolean includingPropagatingEvents) Same assubscribe(Object, boolean), but uses a weak reference to store the listener internally.voidsubscribeWithWeakReference(Object listener, String topic) Same assubscribe(Object, String), but uses a weak reference to store the listener internally.<T> voidsubscribeWithWeakReference(EventBusListener<T> listener) Same assubscribe(EventBusListener), but uses a weak reference to store the listener internally.<T> voidsubscribeWithWeakReference(EventBusListener<T> listener, boolean includingPropagatingEvents) Same assubscribe(EventBusListener, boolean), but uses a weak reference to store the listener internally.<T> voidsubscribeWithWeakReference(EventBusListener<T> listener, String topic) Same assubscribe(EventBusListener, String), but uses a weak reference to store the listener internally.voidunsubscribe(Object listener) Unsubscribes the specified listener (and all its listener methods) from the event bus.<T> voidunsubscribe(EventBusListener<T> listener) Unsubscribes the specified listener from the event bus.
-
Method Details
-
publish
Publishes the specified payload on the event bus, using the scope of this particular event bus.- Type Parameters:
T- the type of the payload.- Parameters:
sender- the object that published the event, nevernull.payload- the payload of the event to publish, nevernull.- See Also:
-
publish
Publishes the specified payload on the event bus, using the scope of this particular event bus. The topic specifies which listeners will be notified.- Type Parameters:
T- the type of the payload.- Parameters:
topic- the topic of the event to publish, nevernull.sender- the object that published the event, nevernull.payload- the payload of the event to publish, nevernull.- See Also:
-
publish
Publishes the specified payload on the event bus, or any of its parent buses, depending on the event scope.- Type Parameters:
T- the type of the payload;- Parameters:
scope- the scope of the event, nevernull.sender- the object that published the event, nevernull.payload- the payload of the event to publish, nevernull.- Throws:
UnsupportedOperationException- if the payload could not be published with the specified scope.- See Also:
-
publish
<T> void publish(EventScope scope, String topic, Object sender, T payload) throws UnsupportedOperationException Publishes the specified payload on the event bus, or any of its parent buses, depending on the event scope. The topic specifies which listeners will be notified.- Type Parameters:
T- the type of the payload;- Parameters:
scope- the scope of the event, nevernull.topic- the topic of the event to publish, nevernull.sender- the object that published the event, nevernull.payload- the payload of the event to publish, nevernull.- Throws:
UnsupportedOperationException- if the payload could not be published with the specified scope.- See Also:
-
getScope
EventScope getScope()Gets the scope of the events published on this event bus.- Returns:
- the event scope, never
null. - See Also:
-
subscribe
Subscribes the specified listener to the event bus, including propagated events from parent event buses. The event bus will analyse the payload type of the listener to determine which events it is interested in receiving. This is the same as callingsubscribe(listener, true).- Type Parameters:
T- the type of payload the listener is interested in.- Parameters:
listener- the listener to subscribe, nevernull.- See Also:
-
subscribeWithWeakReference
Same assubscribe(EventBusListener), but uses a weak reference to store the listener internally. -
subscribe
Subscribes the topic interested listener to the event bus, including propagated events from parent event buses. The event bus will analyse the payload type and topic of the listener to determine which events it is interested in receiving.- Type Parameters:
T- the type of payload the listener is interested in- Parameters:
listener- the listener to subscribe, nevernulltopic- the topic of listener interest
-
subscribeWithWeakReference
Same assubscribe(EventBusListener, String), but uses a weak reference to store the listener internally. -
subscribe
Subscribes the specified listener to the event bus. The event bus will analyse the payload type of the listener to determine which events it is interested in receiving.- Type Parameters:
T- the type of payload the listener is interested in.- Parameters:
listener- the listener to subscribe, nevernull.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.- See Also:
-
subscribeWithWeakReference
<T> void subscribeWithWeakReference(EventBusListener<T> listener, boolean includingPropagatingEvents) Same assubscribe(EventBusListener, boolean), but uses a weak reference to store the listener internally. -
subscribe
Subscribes the specified listener to the event bus. The listener need not implement theEventBusListenerinterface, but must contain one or more methods that are annotated with theEventBusListenerMethodinterface and conform to one of these method signatures:myMethodName(Event<MyPayloadType>)ormyMethodName(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 callingsubscribe(listener, true).- Parameters:
listener- the listener to subscribe, nevernull.- See Also:
-
subscribeWithWeakReference
Same assubscribe(Object), but uses a weak reference to store the listener internally. -
subscribe
Subscribes the topic interested listener to the event bus. The listener need not implement theEventBusListenerinterface, but must contain one or more methods that are annotated with theEventBusListenerMethodinterface and conform to one of these method signatures:myMethodName(Event<MyPayloadType>)ormyMethodName(MyPayloadType). The event bus will analyse the payload type of the listener methods to determine which events the different methods are interested in receiving.
Example:subscribe(Listener.this, "/news");- Parameters:
listener- the listener to subscribe, nevernull.topic- the topic of listener interest- See Also:
-
subscribeWithWeakReference
Same assubscribe(Object, String), but uses a weak reference to store the listener internally. -
subscribe
Subscribes the specified listener to the event bus. The listener need not implement theEventBusListenerinterface, but must contain one or more methods that are annotated with theEventBusListenerMethodinterface and conform to one of these method signatures:myMethodName(Event<MyPayloadType>)ormyMethodName(MyPayloadType). The event bus will analyse the payload type of the listener methods to determine which events the different methods are interested in receiving.- Parameters:
listener- the listener to subscribe, nevernull.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.- See Also:
-
subscribeWithWeakReference
Same assubscribe(Object, boolean), but uses a weak reference to store the listener internally. -
unsubscribe
Unsubscribes the specified listener from the event bus. Also works for listeners stored with weak references.- Type Parameters:
T- the type of the payload.- Parameters:
listener- the listener to unsubscribe, nevernull.- See Also:
-
unsubscribe
Unsubscribes the specified listener (and all its listener methods) from the event bus. Also works for listeners stored with weak references.- Parameters:
listener- the listener to unsubscribe, nevernull.- See Also:
-