de.cesr.lara.components.eventbus.impl
Class LEventbus

java.lang.Object
  extended by de.cesr.lara.components.eventbus.impl.LEventbus

public class LEventbus
extends Object

The LEventbus serves as a communication system between different components, where the components do not necessarily know each other. Components can publish events to the LaraEventbus. All subscribers of this event will be notified on occurrence. The event bus is implemented as a singleton to ensure all components communicate over the same channel and to make use of the event bus easier. However, it also manages eventbuses by ID objects which enables specific eventbuses per agent. GOAL: Loose coupling of components, Event driven initialization.


Constructor Summary
protected LEventbus()
          This is a singleton.
 
Method Summary
static LEventbus getInstance()
          returns a reference to the global eventbus
static LEventbus getInstance(Object id)
          returns a reference to a special eventbus
 boolean isForceSequential()
           
protected  void notifySubscribers(LaraEvent event)
          TODO search for subscribers to super classes!
 boolean occured(LaraEvent event)
          Checks whether the given LaraEvent has occurred during the current tick.
 void publish(LaraEvent event)
          Publish / fire event - this will notify subscribers of this event about occurrence of this event
static void resetAll()
          Iterates over all instances and calls resetInstance().
 void resetInstance()
          Clears eventsThisTimestamp, event subscriber map, event-waiting counters, and statistics.
 void setForceSequential(boolean forceSequential)
           
 boolean subclassOccured(LaraEvent event)
          Checks whether the given LaraEvent or any sub class has occurred during the current tick.
 void subscribe(LaraAbstractEventSubscriber subscriber, Class<? extends LaraEvent> eventClass)
          Subscribe for an event - subscriber will be informed about occurrence of event (triggers onEvent() method of implemented interface LaraEventSubscriber)
 void unsubscribe(Class<? extends LaraEvent> eventClass)
          Unsubscribes all subscribers from the given event class.
 void unsubscribe(LaraAbstractEventSubscriber subscriber)
          Unsubscribe the given subscriber from all events.
 void unsubscribe(LaraAbstractEventSubscriber subscriber, Class<? extends LaraEvent> eventClass)
          Unsubscribe a subscriber from an event
 void unsubscribe(LaraEvent event)
          Unsubscribes all subscribers from the event class the given event belongs to.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LEventbus

protected LEventbus()
This is a singleton. Use of constructor is permitted. Use getInstance() to obtain a reference to the event bus.

Method Detail

getInstance

public static LEventbus getInstance()
returns a reference to the global eventbus


getInstance

public static LEventbus getInstance(Object id)
returns a reference to a special eventbus

Parameters:
id -
Returns:

resetAll

public static void resetAll()
Iterates over all instances and calls resetInstance(). Clears collection of instances.


occured

public boolean occured(LaraEvent event)
Checks whether the given LaraEvent has occurred during the current tick.

Parameters:
event - to check
Returns:
true if the given event has occurred

publish

public void publish(LaraEvent event)
Publish / fire event - this will notify subscribers of this event about occurrence of this event

Parameters:
event -

resetInstance

public void resetInstance()
Clears eventsThisTimestamp, event subscriber map, event-waiting counters, and statistics.


subclassOccured

public boolean subclassOccured(LaraEvent event)
Checks whether the given LaraEvent or any sub class has occurred during the current tick.

Parameters:
event - to check
Returns:
true if the given event or any sub class has occurred

subscribe

public void subscribe(LaraAbstractEventSubscriber subscriber,
                      Class<? extends LaraEvent> eventClass)
Subscribe for an event - subscriber will be informed about occurrence of event (triggers onEvent() method of implemented interface LaraEventSubscriber)

Parameters:
subscriber -
event -

unsubscribe

public void unsubscribe(Class<? extends LaraEvent> eventClass)
Unsubscribes all subscribers from the given event class. Note: This method is inefficient since it iterates over all registered events.

Parameters:
subscriber -

unsubscribe

public void unsubscribe(LaraAbstractEventSubscriber subscriber)
Unsubscribe the given subscriber from all events. NOTE: This method is inefficient since it iterates over all registered events!

Parameters:
subscriber -

unsubscribe

public void unsubscribe(LaraAbstractEventSubscriber subscriber,
                        Class<? extends LaraEvent> eventClass)
Unsubscribe a subscriber from an event

Parameters:
subscriber -
event -

unsubscribe

public void unsubscribe(LaraEvent event)
Unsubscribes all subscribers from the event class the given event belongs to.

Parameters:
subscriber -

notifySubscribers

protected void notifySubscribers(LaraEvent event)
TODO search for subscribers to super classes! (Custom PP component implementations could publish sub classes of PP-event that other components need to recognise)

Parameters:
event -

isForceSequential

public boolean isForceSequential()
Returns:
the forceSequential

setForceSequential

public void setForceSequential(boolean forceSequential)
Parameters:
forceSequential - the forceSequential to set