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
ConstructorsModifierConstructorDescriptionprotectedALcdWeakLayeredListener(T aObjectToModify) Creates a newALcdWeakLayeredListenerinstance which can updateaObjectToModifywhen it receives events. -
Method Summary
Modifier and TypeMethodDescriptionfinal voidlayeredStateChanged(TLcdLayeredEvent aLayeredEvent) Notify thisILcdLayeredListenerthat the state of anILcdLayeredhas changed.protected abstract voidlayeredStateChangeImpl(T aToModify, TLcdLayeredEvent aLayeredEvent) This method is called each time aTLcdLayeredEventis 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
ALcdWeakLayeredListenerinstance which can updateaObjectToModifywhen it receives events.- Parameters:
aObjectToModify- The object you want to modify when aTLcdLayeredEventis received. This is a short-lived object, while the listener will be attached to a long-livingILcdLayeredobject.
-
-
Method Details
-
layeredStateChanged
Notify thisILcdLayeredListenerthat the state of anILcdLayeredhas 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:
layeredStateChangedin interfaceILcdLayeredListener- See Also:
-
layeredStateChangeImpl
This method is called each time a
TLcdLayeredEventis 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
-