Class WeakReferenceWrapper<T>

java.lang.Object
io.deephaven.base.reference.WeakReferenceWrapper<T>
All Implemented Interfaces:
SimpleReference<T>

public abstract class WeakReferenceWrapper<T> extends Object implements SimpleReference<T>

SimpleReference implementation created to interpose a strong/hard reference in place of a weak reference, with reachability subject to the continued reachability of the wrapped referent via the wrapped reference.

In general, this only makes sense for concrete subclasses that are simultaneously T's and SimpleReferences to T's. The intended use case is for callback/listener registration chains that maintain reachability for all but the final link in the chain. Classes that wish to enable this functionality must construct their listener references with maybeCreateWeakReference in order to avoid rendering a WeakReferenceWrapper weakly reachable and thereby breaking the chain.

  • Constructor Details

    • WeakReferenceWrapper

      protected WeakReferenceWrapper(T wrappedReferent)
  • Method Details

    • get

      public final T get()
      Description copied from interface: SimpleReference
      Retrieve the current referent.
      Specified by:
      get in interface SimpleReference<T>
      Returns:
      The current referent, which may be null.
    • clear

      public final void clear()
      Description copied from interface: SimpleReference
      Clear the referent.
      Specified by:
      clear in interface SimpleReference<T>
    • getWrapped

      protected final T getWrapped()
    • maybeCreateWeakReference

      public static <T> SimpleReference<T> maybeCreateWeakReference(T referent)