Class DefaultHub

java.lang.Object
org.gcube.common.events.impl.DefaultHub
All Implemented Interfaces:
Hub

public class DefaultHub extends Object implements Hub
Default Hub implementation.
Author:
Fabio Simeoni, Luca Frosini (ISTI-CNR)
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new DefaultHub with a cached thread pool executor service.
    Creates a new DefaultHub with the specified executor service.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    fire(Object event, String... qualifiers)
    Fires an event to all observers which have subscribed for them, blocking the client until all the critical observers have executed.
    void
    Signals that this hub is no longer needed and can release its resources.
    void
    subscribe(Object object)
    Subscribes an observer for notification of events of a given type.
    boolean
    unsubscribe(Object observer)
    Unsubscribes an observer.
    void
    waitFor(Class<?> eventType)
    Blocks the caller until an event of a given type occurs.
    void
    waitFor(Class<?> eventType, long duration, TimeUnit unit)
    Blocks the caller until an event of a given type occurs or a given length of time elapses.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • DefaultHub

      public DefaultHub()
      Creates a new DefaultHub with a cached thread pool executor service.
    • DefaultHub

      public DefaultHub(ExecutorService service)
      Creates a new DefaultHub with the specified executor service.
      Parameters:
      service - the executor service to use for asynchronous event processing
      Throws:
      IllegalArgumentException - if the service is null
  • Method Details

    • subscribe

      public void subscribe(Object object)
      Description copied from interface: Hub
      Subscribes an observer for notification of events of a given type.

      The single parameter of any method of the observer annotated with Observes identifies the type of the events observed by the observer.

      Specified by:
      subscribe in interface Hub
      Parameters:
      object - the observer
      See Also:
    • unsubscribe

      public boolean unsubscribe(Object observer)
      Description copied from interface: Hub
      Unsubscribes an observer.
      Specified by:
      unsubscribe in interface Hub
      Parameters:
      observer - the observer
      Returns:
      true if the observer is found and unsubscribed.
    • fire

      public void fire(Object event, String... qualifiers)
      Description copied from interface: Hub
      Fires an event to all observers which have subscribed for them, blocking the client until all the critical observers have executed.
      Specified by:
      fire in interface Hub
      Parameters:
      event - the event
      qualifiers - optional event qualifiers
    • waitFor

      public void waitFor(Class<?> eventType)
      Description copied from interface: Hub
      Blocks the caller until an event of a given type occurs.
      Specified by:
      waitFor in interface Hub
      Parameters:
      eventType - the event type
    • waitFor

      public void waitFor(Class<?> eventType, long duration, TimeUnit unit)
      Description copied from interface: Hub
      Blocks the caller until an event of a given type occurs or a given length of time elapses.
      Specified by:
      waitFor in interface Hub
      Parameters:
      eventType - the event type
      duration - the length of time to wait for
      unit - the time unit of the duration
    • stop

      public void stop()
      Description copied from interface: Hub
      Signals that this hub is no longer needed and can release its resources.
      Specified by:
      stop in interface Hub