Class LazyRef<T>

  • Type Parameters:
    T -
    All Implemented Interfaces:
    Serializable, java.util.function.Supplier<Ref<T>>

    public class LazyRef<T>
    extends Object
    implements java.util.function.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:
    Serialized Form
    • Field Detail

      • label

        protected String label
      • backendRefSupplier

        protected java.util.function.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 Detail

      • LazyRef

        protected LazyRef()
      • LazyRef

        public LazyRef​(String label,
                       java.util.function.Supplier<? extends Ref<T>> backendRefSupplier,
                       long closeDelayInMs)
    • Method Detail

      • create

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

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

        protected void actualClose()