org.placelab.eventsystem
Interface EventSystem

All Known Implementing Classes:
SimpleEventSystem, SWTEventSystem

public interface EventSystem

EventSystem implements a basic system for sending messages between threads.


Method Summary
 java.lang.Object addEventListener(java.lang.Object eventType, EventListener listener)
          Add an EventListener to be notified whenever user defined events of eventType are posted to the EventSystem with notifyEvent(java.lang.Object, java.lang.Object).
 java.lang.Object addTimer(long timeoutMillis, EventListener listener, java.lang.Object data)
          Add an event to the system to be sent after the specified delay
 void notifyEvent(java.lang.Object eventType, java.lang.Object data)
          Notify all listeners registered through addEventListener(Object, EventListener) for eventType that the event has occured
 void notifyTransientEvent(EventListener listener, java.lang.Object data)
          Notify a single event listener with the given data.
 void removeEventListener(java.lang.Object token)
          Remove an EventListener that was registered with addEventListener.
 void removeTimer(java.lang.Object token)
          Remove an event from the EventSystem so that the callback to the EventListener for the event won't be called.
 void run()
          Starts the EventSystem running in the current thread.
 void stop()
          Stops the EventSystem.
 

Method Detail

run

public void run()
Starts the EventSystem running in the current thread. All callbacks to EventListeners will be delivered in the this thread


stop

public void stop()
Stops the EventSystem. No more events will be delivered after this is called.


addTimer

public java.lang.Object addTimer(long timeoutMillis,
                                 EventListener listener,
                                 java.lang.Object data)
Add an event to the system to be sent after the specified delay

Parameters:
timeoutMillis - amount of time to wait before invoking the callback on the EventListener
listener - the EventListener to be called back
data - data to pass to the callback of the listener
Returns:
a token for the timer that can be used to remove this event from the EventSystem
See Also:
removeTimer(Object)

removeTimer

public void removeTimer(java.lang.Object token)
Remove an event from the EventSystem so that the callback to the EventListener for the event won't be called. Has no effect if the callback has already been delivered.

Parameters:
token - a token returned from addTimer(long, EventListener, Object)

addEventListener

public java.lang.Object addEventListener(java.lang.Object eventType,
                                         EventListener listener)
Add an EventListener to be notified whenever user defined events of eventType are posted to the EventSystem with notifyEvent(java.lang.Object, java.lang.Object).

Note that eventTypes are distinguished from one another by their hashCode() methods.

Parameters:
eventType - the type of event to register to listen for
listener - an EventListener to be called back whenever events of eventType are posted to the EventSystem
Returns:
a token for the event which can be used to remove the listener
See Also:
removeEventListener(Object)

removeEventListener

public void removeEventListener(java.lang.Object token)
Remove an EventListener that was registered with addEventListener. Only removes a single EventListener, other EventListeners registered for the same event are unaffected.

Parameters:
token - a token returned from addEventListener(Object, EventListener)

notifyEvent

public void notifyEvent(java.lang.Object eventType,
                        java.lang.Object data)
Notify all listeners registered through addEventListener(Object, EventListener) for eventType that the event has occured

Parameters:
eventType - the user defined event that has occured
data - the data to give to the listener's callback

notifyTransientEvent

public void notifyTransientEvent(EventListener listener,
                                 java.lang.Object data)
Notify a single event listener with the given data. Typically this is used to send a single message, and an optional object between threads