org.gcube.common.events.impl
Class DefaultHub

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

public class DefaultHub
extends Object
implements Hub

Default Hub implementation.

Author:
Fabio Simeoni

Constructor Summary
DefaultHub()
           
DefaultHub(ExecutorService service)
           
 
Method Summary
 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 stop()
          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 Detail

DefaultHub

public DefaultHub()

DefaultHub

public DefaultHub(ExecutorService service)
Method Detail

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:
Observes

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


Copyright © 2013. All Rights Reserved.