Class ALcdWeakChangeListener<T>

java.lang.Object
com.luciad.util.ALcdWeakChangeListener<T>
Type Parameters:
T - The type of the short-lived object
All Implemented Interfaces:
ILcdChangeListener, EventListener

public abstract class ALcdWeakChangeListener<T> extends Object implements ILcdChangeListener

An ILcdChangeListener implementation which only keeps a WeakReference to the object it wants to update when change 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.

This particular listener has one extra rule compared to the general rules of weak listeners:

  • The object to listen to must implement ILcdChangeSource.

Since:
2015.1
See Also:
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    ALcdWeakChangeListener(T aObjectToModify)
    Creates a new ALcdWeakChangeListener instance which can update aObjectToModify when it receives events.
  • Method Summary

    Modifier and Type
    Method
    Description
    final void
    Invoked when the target of the listener has changed its state.
    protected abstract void
    stateChangedImpl(T aToModify, TLcdChangeEvent aChangeEvent)
    This method is called each time a TLcdChangeEvent is received by this listener, and the short-living object to modify passed in the constructor of this listener is not yet GC-ed.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ALcdWeakChangeListener

      protected ALcdWeakChangeListener(T aObjectToModify)

      Creates a new ALcdWeakChangeListener instance which can update aObjectToModify when it receives events.

      Warning: this listener can only be registered to a ILcdChangeSource. The listener will throw exceptions when it receives TLcdChangeEvent instances where the source is not an ILcdChangeSource instance.

      Parameters:
      aObjectToModify - The object you want to modify when a TLcdChangeEvent is received. This is a short-lived object, while the listener will be attached to a long-living ILcdChangeSource object
  • Method Details

    • stateChanged

      public final void stateChanged(TLcdChangeEvent aChangeEvent)
      Invoked when the target of the listener has changed its state.

      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 stateChangedImpl(Object, TLcdChangeEvent) method. If the short-living object is already garbage collected, this method will de-register the listener from the source.

      Specified by:
      stateChanged in interface ILcdChangeListener
      Parameters:
      aChangeEvent - The event describing the change.
    • stateChangedImpl

      protected abstract void stateChangedImpl(T aToModify, TLcdChangeEvent aChangeEvent)

      This method is called each time a TLcdChangeEvent 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.
      aChangeEvent - The received event