org.placelab.eventsystem
Class SimpleEventSystem

java.lang.Object
  extended byorg.placelab.eventsystem.SimpleEventSystem
All Implemented Interfaces:
EventSystem

public class SimpleEventSystem
extends java.lang.Object
implements EventSystem


Constructor Summary
SimpleEventSystem()
           
 
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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleEventSystem

public SimpleEventSystem()
Method Detail

run

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

Specified by:
run in interface EventSystem

stop

public void stop()
Description copied from interface: EventSystem
Stops the EventSystem. No more events will be delivered after this is called.

Specified by:
stop in interface EventSystem

addTimer

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

Specified by:
addTimer in interface EventSystem
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:
EventSystem.removeTimer(Object)

removeTimer

public void removeTimer(java.lang.Object token)
Description copied from interface: EventSystem
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.

Specified by:
removeTimer in interface EventSystem
Parameters:
token - a token returned from EventSystem.addTimer(long, EventListener, Object)

addEventListener

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

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

Specified by:
addEventListener in interface EventSystem
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:
EventSystem.removeEventListener(Object)

removeEventListener

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

Specified by:
removeEventListener in interface EventSystem
Parameters:
token - a token returned from EventSystem.addEventListener(Object, EventListener)

notifyEvent

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

Specified by:
notifyEvent in interface EventSystem
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)
Description copied from interface: EventSystem
Notify a single event listener with the given data. Typically this is used to send a single message, and an optional object between threads

Specified by:
notifyTransientEvent in interface EventSystem