Class ALcdWeakLayeredListener<T>
- Type Parameters:
T
- The type of the short-lived object
- All Implemented Interfaces:
ILcdLayeredListener
,Serializable
,EventListener
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.
- Since:
- 2015.1
- See Also:
-
Constructor Summary
ModifierConstructorDescriptionprotected
ALcdWeakLayeredListener
(T aObjectToModify) Creates a newALcdWeakLayeredListener
instance which can updateaObjectToModify
when it receives events. -
Method Summary
Modifier and TypeMethodDescriptionfinal void
layeredStateChanged
(TLcdLayeredEvent aLayeredEvent) Notify thisILcdLayeredListener
that the state of anILcdLayered
has changed.protected abstract void
layeredStateChangeImpl
(T aToModify, TLcdLayeredEvent aLayeredEvent) This method is called each time aTLcdLayeredEvent
is received by this listener, and the short-living object to modify passed in the constructor of this listener is not yet GC-ed.
-
Constructor Details
-
ALcdWeakLayeredListener
Creates a new
ALcdWeakLayeredListener
instance which can updateaObjectToModify
when it receives events.- Parameters:
aObjectToModify
- The object you want to modify when aTLcdLayeredEvent
is received. This is a short-lived object, while the listener will be attached to a long-livingILcdLayered
object.
-
-
Method Details
-
layeredStateChanged
Notify thisILcdLayeredListener
that the state of anILcdLayered
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.- Specified by:
layeredStateChanged
in interfaceILcdLayeredListener
- See Also:
-
layeredStateChangeImpl
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.- Parameters:
aToModify
- The object to modify, as passed in the constructor of this class.aLayeredEvent
- The received event
-