Class ALcdWeakStatusListener<T,R extends ILcdStatusSource>

java.lang.Object
com.luciad.util.ALcdWeakStatusListener<T,R>
Type Parameters:
T - The type of the short-lived object
R - The type of the long-lived object, which is also the source of the status events this listener will receive
All Implemented Interfaces:
ILcdStatusListener<R>, EventListener

public abstract class ALcdWeakStatusListener<T,R extends ILcdStatusSource> extends Object implements ILcdStatusListener<R>

An ILcdStatusListener 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 ILcdStatusSource.

Since:
2015.1
  • Constructor Summary

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

    Modifier and Type
    Method
    Description
    final void
    This method will be called when the status of an Object to which this ILcdStatusListener has been registered has changed.
    protected abstract void
    statusChangedImpl(T aToModify, TLcdStatusEvent<R> aStatusEvent)
    This method is called each time a TLcdStatusEvent 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

    • ALcdWeakStatusListener

      protected ALcdWeakStatusListener(T aObjectToModify)

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

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

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

    • statusChanged

      public final void statusChanged(TLcdStatusEvent<R> aStatusEvent)
      This method will be called when the status of an Object to which this ILcdStatusListener has been registered 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 statusChangedImpl(Object, TLcdStatusEvent) method. If the short-living object is already garbage collected, this method will de-register the listener from the source.

      Specified by:
      statusChanged in interface ILcdStatusListener<T>
      Parameters:
      aStatusEvent - a TLcdStatusEvent detailing the status changes.
    • statusChangedImpl

      protected abstract void statusChangedImpl(T aToModify, TLcdStatusEvent<R> aStatusEvent)

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