|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.activemath.events.impl.SimpleMulticaster
public class SimpleMulticaster
Simple implementation of the ActivemathEventMulticaster interface.
Doesn't permit multiple instances of the same listener, as it keeps listeners in a HashSet.
Note that this class doesn't try to do anything clever to ensure thread safety if listeners are added or removed at runtime. A technique such as Copy-on-Write (Lea:137) could be used to ensure this, but the assumption in this version of this framework is that listeners will be added at application configuration time and not added or removed as the application runs.
All listeners are invoked in the calling thread. This allows the danger of a rogue listener blocking the entire application, but adds minimal overhead.
An alternative implementation could be more sophisticated in both these respects. This class is based on a class from an early version of the Spring Framework (http://www.springframework.org/), by Rod Johnson and Juergen Hoeller.
| Constructor Summary | |
|---|---|
SimpleMulticaster()
|
|
| 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 |
|---|
public SimpleMulticaster()
| Method Detail |
|---|
public void addListener(ActivemathEventListener listener)
public void removeListener(ActivemathEventListener listener)
public void removeAllListeners()
public void publishEvent(ActivemathEvent event)
ActivemathEventPublisher
publishEvent in interface ActivemathEventPublisherpublic void onActivemathEvent(ActivemathEvent event)
ActivemathEventListenerThis method must return as quickly as possible and must not block the calling thread for long.
onActivemathEvent in interface ActivemathEventListenerevent - the event to respond topublic void stop()
ActivemathEventMulticaster
stop in interface ActivemathEventMulticaster
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||