T
- The type of the short-lived objectpublic abstract class ALcdWeakLayeredListener<T> extends Object implements ILcdLayeredListener
An ILcdLayeredListener
implementation which only keeps a WeakReference
to the object it
wants to update when layered events are received. This avoids memory leaks, even without removing the
listener.
The class javadoc of ALcdWeakModelListener
contains an example of a weak listener,
and some rules on the usage of weak listeners.
Modifier | Constructor and Description |
---|---|
protected |
ALcdWeakLayeredListener(T aObjectToModify)
Creates a new
ALcdWeakLayeredListener instance which can update aObjectToModify
when it receives events. |
Modifier and Type | Method and Description |
---|---|
void |
layeredStateChanged(TLcdLayeredEvent aLayeredEvent)
Notify this
ILcdLayeredListener that the state of
an ILcdLayered has changed. |
protected abstract void |
layeredStateChangeImpl(T aToModify,
TLcdLayeredEvent aLayeredEvent)
This method is called each time a
TLcdLayeredEvent is received by this listener,
and the short-living object to modify passed in the constructor of this listener is not yet GC-ed. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
onLayerAdded, onLayerRemoved
protected ALcdWeakLayeredListener(T aObjectToModify)
Creates a new ALcdWeakLayeredListener
instance which can update aObjectToModify
when it receives events.
aObjectToModify
- The object you want to modify when a TLcdLayeredEvent
is received.
This is a short-lived object, while the listener will be attached to a
long-living ILcdLayered
object.public final void layeredStateChanged(TLcdLayeredEvent aLayeredEvent)
ILcdLayeredListener
that the state of
an ILcdLayered
has changed.
This method will check whether the short-living object is still available.
If it is, this method will pass the short-living object and the event to the layeredStateChangeImpl(Object, TLcdLayeredEvent)
method.
If the short-living object is already garbage collected, this method will de-register the listener from the source.
layeredStateChanged
in interface ILcdLayeredListener
layeredStateChangeImpl(Object, TLcdLayeredEvent)
protected abstract void layeredStateChangeImpl(T aToModify, TLcdLayeredEvent aLayeredEvent)
This method is called each time a TLcdLayeredEvent
is received by this listener,
and the short-living object to modify passed in the constructor of this listener is not yet GC-ed.
aToModify
- The object to modify, as passed in the constructor of this class.aLayeredEvent
- The received event