Interface EventStudio

All Known Implementing Classes:
DefaultEventStudio

public interface EventStudio
An EventStudio is a thread-safe central place allowing broadcast of events to Listeners to registered on a Station. Stations are created internally as soon as a listener is added but it's up to the user to clear a station when it's not needed anymore. Listeners can be added multiple times either to different or the same station and they will be called as many times as they have been added.

As a general rule null parameters are not allowed (either station names, listeners, supervisors.. )

Author:
Andrea Vacondio
  • Field Details

  • Method Details

    • add

      <T> void add(Listener<T> listener, String station)
      Adds the given Listener to the given station using default priority(0) ad default strength ReferenceStrength.STRONG.
    • add

      <T> void add(Listener<T> listener, String station, int priority, ReferenceStrength strength)
      Adds the given Listener to the given station using the given priority (low values mean higher priority) and strength.
    • add

      <T> void add(Class<T> eventClass, Listener<T> listener, String station)
      Adds the given Listener, listening for the given event class, to the given station using default priority(0) ad default strength ReferenceStrength.STRONG. This adds method is useful when a listener can listen for a hierarchy of events.
      See Also:
    • add

      <T> void add(Class<T> eventClass, Listener<T> listener, String station, int priority, ReferenceStrength strength)
      Adds the given Listener, listening for the given event class, to the given station using the given priority (low values mean higher priority) and strength. This adds method is useful when a listener can listen for a hierarchy of events:
       
       class BroadListener{@code <T extends ParentEvent> implements Listener<T>} { 
           void onEvent(ParentEvent e){
                 LOG.debug(e);
           }
       }
       
       class X {
         public void init() {
           EventStudio studio = ....
           studio.add(ChildEvent.class, new BroadListener{@code <ChildEvent>}(), "mystation");
           studio.add(AnotherChildEvent.class, new BroadListener{@code <AnotherChildEvent>()}, "mystation");
           ...
         }
       }
       
       
       
    • addAnnotatedListeners

      void addAnnotatedListeners(Object bean)
      Discovers annotated method on the given bean and adds them as Listeners
      See Also:
    • supervisor

      <T> void supervisor(Supervisor supervisor, String station)
      Sets a Supervisor for the given station. It will be notified of every event broadcasted to the station prior its delivery to the proper Listeners allowing event inspection.

      Supervisors cannot be removed but they can be replaces. See Supervisor.SLACKER

    • remove

      <T> boolean remove(Listener<T> listener, String station)
      Removes the first occurrence of the given Listener from the given station.
      Returns:
      true if the listener was successfully removed
    • remove

      <T> boolean remove(Class<T> eventClass, Listener<T> listener, String station)
      Removes the first occurrence of the given Listener listening for the given event, from the given station
      Returns:
      true if the listener was successfully removed
    • clear

      void clear(String station)
      Clear the given station removing the whole station from the EventStudio which means that Listeners and Supervisor will not be notified anymore. A station with the same name can be recreated.
    • broadcast

      void broadcast(Object event, String station)
      Broadcasts the given event to the given station. Listeners listening the given station and bound to the event class will be notified.
    • broadcastToEveryStation

      void broadcastToEveryStation(Object event)
      Broadcasts the given event to every station. Listeners bound to the event class (no matter the station they are listening) will be notified.