Class ScopedEventBus

java.lang.Object
org.vaadin.spring.events.internal.ScopedEventBus
All Implemented Interfaces:
Serializable, EventBus
Direct Known Subclasses:
ScopedEventBus.DefaultApplicationEventBus, ScopedEventBus.DefaultSessionEventBus, ScopedEventBus.DefaultUIEventBus, ScopedEventBus.DefualtViewEventBus

public abstract class ScopedEventBus extends Object implements EventBus, Serializable
Implementation of EventBus that publishes events with one specific EventScope. A scoped event bus can also have a parent event bus, in which case all events published on the parent bus will propagate to the scoped event bus as well.
Author:
Petter Holmström (petter@vaadin.com)
See Also:
  • Constructor Details

    • ScopedEventBus

      public ScopedEventBus(EventScope scope)
      Parameters:
      scope - the scope of the events that this event bus handles.
    • ScopedEventBus

      public ScopedEventBus(EventScope scope, EventBus parentEventBus)
      Parameters:
      scope - the scope of the events that this event bus handles.
      parentEventBus - the parent event bus to use, may be null;
  • Method Details

    • getScope

      public EventScope getScope()
      Description copied from interface: EventBus
      Gets the scope of the events published on this event bus.
      Specified by:
      getScope in interface EventBus
      Returns:
      the event scope, never null.
      See Also:
    • publish

      public <T> void publish(Object sender, T payload)
      Description copied from interface: EventBus
      Publishes the specified payload on the event bus, using the scope of this particular event bus.
      Specified by:
      publish in interface EventBus
      Type Parameters:
      T - the type of the payload.
      Parameters:
      sender - the object that published the event, never null.
      payload - the payload of the event to publish, never null.
      See Also:
    • publish

      public <T> void publish(String topic, Object sender, T payload)
      Description copied from interface: EventBus
      Publishes the specified payload on the event bus, using the scope of this particular event bus. The topic specifies which listeners will be notified.
      Specified by:
      publish in interface EventBus
      Type Parameters:
      T - the type of the payload.
      Parameters:
      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.
      See Also:
    • publish

      public <T> void publish(EventScope scope, Object sender, T payload) throws UnsupportedOperationException
      Description copied from interface: EventBus
      Publishes the specified payload on the event bus, or any of its parent buses, depending on the event scope.
      Specified by:
      publish in interface EventBus
      Type Parameters:
      T - the type of the payload;
      Parameters:
      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.
      Throws:
      UnsupportedOperationException - if the payload could not be published with the specified scope.
      See Also:
    • publish

      public <T> void publish(EventScope scope, String topic, Object sender, T payload) throws UnsupportedOperationException
      Description copied from interface: EventBus
      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.
      Specified by:
      publish in interface EventBus
      Type Parameters:
      T - the type of the payload;
      Parameters:
      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.
      Throws:
      UnsupportedOperationException - if the payload could not be published with the specified scope.
      See Also:
    • subscribe

      public <T> void subscribe(EventBusListener<T> listener)
      Description copied from interface: EventBus
      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 calling subscribe(listener, true).
      Specified by:
      subscribe in interface EventBus
      Type Parameters:
      T - the type of payload the listener is interested in.
      Parameters:
      listener - the listener to subscribe, never null.
      See Also:
    • subscribeWithWeakReference

      public <T> void subscribeWithWeakReference(EventBusListener<T> listener)
      Description copied from interface: EventBus
      Same as EventBus.subscribe(EventBusListener), but uses a weak reference to store the listener internally.
      Specified by:
      subscribeWithWeakReference in interface EventBus
    • subscribe

      public <T> void subscribe(EventBusListener<T> listener, String topic)
      Description copied from interface: EventBus
      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.
      Specified by:
      subscribe in interface EventBus
      Type Parameters:
      T - the type of payload the listener is interested in
      Parameters:
      listener - the listener to subscribe, never null
      topic - the topic of listener interest
    • subscribe

      public <T> void subscribe(EventBusListener<T> listener, boolean includingPropagatingEvents)
      Description copied from interface: EventBus
      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.
      Specified by:
      subscribe in interface EventBus
      Type Parameters:
      T - the type of payload the listener is interested in.
      Parameters:
      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.
      See Also:
    • subscribeWithWeakReference

      public <T> void subscribeWithWeakReference(EventBusListener<T> listener, String topic)
      Description copied from interface: EventBus
      Same as EventBus.subscribe(EventBusListener, String), but uses a weak reference to store the listener internally.
      Specified by:
      subscribeWithWeakReference in interface EventBus
    • subscribeWithWeakReference

      public <T> void subscribeWithWeakReference(EventBusListener<T> listener, boolean includingPropagatingEvents)
      Description copied from interface: EventBus
      Same as EventBus.subscribe(EventBusListener, boolean), but uses a weak reference to store the listener internally.
      Specified by:
      subscribeWithWeakReference in interface EventBus
    • subscribe

      public void subscribe(Object listener)
      Description copied from interface: EventBus
      Subscribes the specified listener to the event bus. The listener need not implement the 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).
      Specified by:
      subscribe in interface EventBus
      Parameters:
      listener - the listener to subscribe, never null.
      See Also:
    • subscribe

      public void subscribe(Object listener, String topic)
      Description copied from interface: EventBus
      Subscribes the topic interested listener to the event bus. The listener need not implement the 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.



      Example: subscribe(Listener.this, "/news");
      Specified by:
      subscribe in interface EventBus
      Parameters:
      listener - the listener to subscribe, never null.
      topic - the topic of listener interest
      See Also:
    • subscribeWithWeakReference

      public void subscribeWithWeakReference(Object listener, String topic)
      Description copied from interface: EventBus
      Same as EventBus.subscribe(Object, String), but uses a weak reference to store the listener internally.
      Specified by:
      subscribeWithWeakReference in interface EventBus
    • subscribeWithWeakReference

      public void subscribeWithWeakReference(Object listener)
      Description copied from interface: EventBus
      Same as EventBus.subscribe(Object), but uses a weak reference to store the listener internally.
      Specified by:
      subscribeWithWeakReference in interface EventBus
    • subscribe

      public void subscribe(Object listener, boolean includingPropagatingEvents)
      Description copied from interface: EventBus
      Subscribes the specified listener to the event bus. The listener need not implement the 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.
      Specified by:
      subscribe in interface EventBus
      Parameters:
      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.
      See Also:
    • subscribeWithWeakReference

      public void subscribeWithWeakReference(Object listener, boolean includingPropagatingEvents)
      Description copied from interface: EventBus
      Same as EventBus.subscribe(Object, boolean), but uses a weak reference to store the listener internally.
      Specified by:
      subscribeWithWeakReference in interface EventBus
    • unsubscribe

      public <T> void unsubscribe(EventBusListener<T> listener)
      Description copied from interface: EventBus
      Unsubscribes the specified listener from the event bus. Also works for listeners stored with weak references.
      Specified by:
      unsubscribe in interface EventBus
      Type Parameters:
      T - the type of the payload.
      Parameters:
      listener - the listener to unsubscribe, never null.
      See Also:
    • unsubscribe

      public void unsubscribe(Object listener)
      Description copied from interface: EventBus
      Unsubscribes the specified listener (and all its listener methods) from the event bus. Also works for listeners stored with weak references.
      Specified by:
      unsubscribe in interface EventBus
      Parameters:
      listener - the listener to unsubscribe, never null.
      See Also:
    • getParentEventBus

      protected EventBus getParentEventBus()
      Gets the parent of this event bus. Events published on the parent bus will also propagate to the listeners of this event bus.
      Returns:
      the parent event bus, or null if this event bus has no parent.
    • toString

      public String toString()
      Overrides:
      toString in class Object