org.activemath.events.impl
Class AsyncMulticaster

java.lang.Object
  extended by org.activemath.events.impl.AsyncMulticaster
All Implemented Interfaces:
EventListener, ActivemathEventListener, ActivemathEventMulticaster, ActivemathEventPublisher

public class AsyncMulticaster
extends Object
implements ActivemathEventMulticaster

Async implementation of the ActivemathEventMulticaster interface. This multicaster decouples event recievement and propagation. The event is enqueued and the calling thread is free to go. A single delivery thread handles event propagation to the listeners.


Constructor Summary
AsyncMulticaster(ActivemathEventListener listener)
          Create an AsyncEventQueue and an AsyncEventPropagator thread.
 
Method Summary
 void addListener(ActivemathEventListener listener)
           
 void onActivemathEvent(ActivemathEvent event)
          Handle an Activemath event.
 void publishEvent(ActivemathEvent event)
          Publish an event.
 void removeAllListeners()
           
 void removeListener(ActivemathEventListener listener)
           
 void stop()
          signal thread to stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AsyncMulticaster

public AsyncMulticaster(ActivemathEventListener listener)
Create an AsyncEventQueue and an AsyncEventPropagator thread. If listener is of type ActivemathEventListenerBatched, an ActivemathEventListenerBatched thread is created instead. The propagator thread is then started.

Method Detail

stop

public void stop()
Description copied from interface: ActivemathEventMulticaster
signal thread to stop

Specified by:
stop in interface ActivemathEventMulticaster

addListener

public void addListener(ActivemathEventListener listener)

removeListener

public void removeListener(ActivemathEventListener listener)

removeAllListeners

public void removeAllListeners()

publishEvent

public void publishEvent(ActivemathEvent event)
Description copied from interface: ActivemathEventPublisher
Publish an event.

Specified by:
publishEvent in interface ActivemathEventPublisher

onActivemathEvent

public void onActivemathEvent(ActivemathEvent event)
Description copied from interface: ActivemathEventListener
Handle an Activemath event.

This method must return as quickly as possible and must not block the calling thread for long.

Specified by:
onActivemathEvent in interface ActivemathEventListener
Parameters:
event - the event to respond to