se.lth.cs.realtime.event
Interface RTEventSource

All Known Implementing Classes:
JThread, RTThread

public interface RTEventSource

Source of real-time events that are to be passed to RTEventListener objects that have subscribed on such events. In the simplest case, the listener register itself to receive all ordinary (not EceptionEvents or ActivityEvents), by calling addListener with the lister itself as a the subscriber argument. With a RTEventSource called producer the call will be


     producer.addListener(this);

 
This should be equivalent to

     producer.getDispatcher().addListener(this);

 
if the other method defined by this interface, getDispatcher, returns a non-null object.

The dispatcher object provides additionally functionality that could have been part of this interface. The reason for this simple two-method interface, instead of declaring all event subscription methods, is to simplify the implementation of event sources. That is, an event source can simply reuse an available dispatcher and add a two-line getter method returning it.

For simple statically defined one-to-one communication (one producer to one consumer), the listener (consumer) is typically created first (avoiding timing dependent problems during startup) and then given to the constructor of the event source (producer). Using an event dispatcher is good for more flexible situations with run-time changes or one-to-many communication.

Version:
1.0, LastEditDate 2002-04-17
Author:
Klas.Nilsson@cs.lth.se
See Also:
RTEventListener, RTEventDispatcher

Method Summary
 void addListener(RTEventListener subscriber)
          Subscribe on RTEvents from this source.
 RTEventDispatcher getDispatcher()
          Obtain object used for event subscription.
 

Method Detail

addListener

public void addListener(RTEventListener subscriber)
Subscribe on RTEvents from this source.

Parameters:
subscriber - the object interested in getting the events via its putEvent method.

getDispatcher

public RTEventDispatcher getDispatcher()
Obtain object used for event subscription. The same object, using other methods, is used by the issuing thread for dispatching the events by calling putEvent of the subscribing object.

Returns:
the object providing registration of RTEvent listeners. The returned dispatcher corresponds to the javax.swing.event.EventListenerList, but enhanced for real-time usage.