|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object de.fhg.igd.event.EventReflectorImpl
public class EventReflectorImpl
Reflects event notifications to registered listeners. The
listeners are referenced by means of soft references. Soft
references are eligible for garbage collection unless a
strong reference points to the listener. Depending on the
policy for this class, listeners are also wrapped into
either a AsyncListener
or a TrustedListener
. Both classes spawn a thread
that handles distribution of event notifications to the
wrapped listener. Therefor, a strong reference to the
wrapper as well as to the wrapped listener remains throughout
the lifetime of the wrapper thread.
Wrapper threads are started at the time of registering a listener, and they are started in the default thread group (the caller's thread group in general).
Hence, agents that register listeners may safely assume that listeners they register persist during the agent's lifetime. Wrapper threads can be terminated by interrupting them. In that case, the wrapper is removed and garbage collected as soon as there are no more references to it.
Field Summary | |
---|---|
private List |
targets_
The private list that is used to keep references to the listeners. |
Constructor Summary | |
---|---|
EventReflectorImpl()
Creates an instance. |
Method Summary | |
---|---|
TrustedListener |
addListener(Listener listener)
Adds a listener. |
void |
notifyListeners(Object trigger)
Notifies all registered listeners which are alive of the given trigger event. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private List targets_
Constructor Detail |
---|
public EventReflectorImpl()
Method Detail |
---|
public TrustedListener addListener(Listener listener)
TrustedListener
before it
is registered. The TrustedListener thread is started
immediately as a daemon thread, and the current thread
yields in order to give the VM a chance to set up the
new thread. References to TrustedListeners are kept
wrapped in WeakReferences. As long as the thread runs,
the listeners are safe from garbage collection even
if there are no external references to the listeners.
This ensures that listeners are cleared eventually
when agents terminate.
TrustedListeners can be terminated by interrupting them,
or by sending a null
notification.
addListener
in interface EventReflector
listener
- The listener to be registered.
NullPointerException
- if listener
is null
.public void notifyListeners(Object trigger)
notifyListeners
in interface EventReflector
trigger
- The object that is distributed to the
registered listeners.
NullPointerException
- if the trigger
is null
.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |