Class LazyRef<T>

java.lang.Object
org.aksw.commons.util.ref.LazyRef<T>
Type Parameters:
T -
All Implemented Interfaces:
Serializable, Supplier<Ref<T>>

public class LazyRef<T> extends Object implements Supplier<Ref<T>>, Serializable
A supplier for a ref backed by a root ref. Calling .get() creates the root ref lazily if it does not yet exist. Once the user ref is released, the release of the root ref is only scheduled. Another request to .get() cancels a pending release.
Author:
raven
See Also:
  • Field Details

    • label

      protected String label
    • backendRefSupplier

      protected Supplier<? extends Ref<T>> backendRefSupplier
    • closeDelayInMs

      protected long closeDelayInMs
    • backendRef

      protected transient volatile Ref<T> backendRef
    • rootRef

      protected transient volatile Ref<T> rootRef
    • timer

      protected transient volatile Timer timer
  • Constructor Details

    • LazyRef

      protected LazyRef()
    • LazyRef

      public LazyRef(String label, Supplier<? extends Ref<T>> backendRefSupplier, long closeDelayInMs)
  • Method Details

    • create

      public static <T> LazyRef<T> create(String label, Supplier<? extends Ref<T>> rootRefFactory, long delayInMs)
    • get

      public Ref<T> get()
      Specified by:
      get in interface Supplier<T>
    • actualClose

      protected void actualClose()