Class SingletonLazyRef<T>

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

    public class SingletonLazyRef<T>
    extends Object
    implements java.util.function.Supplier<Ref<T>>, Serializable
    A wrapper that turns a supplier of references into a singleton such that at any given time (on a specific jvm) only a most a single reference will have been acquired from that supplier. The intended use case is to allow for sharing a supplier of a DataSource across a cluster. Each involved jvm may obtain its own singleton instnance from that supplier such that there is only one connection pool per jvm from where connections can be drawn.
    See Also:
    Serialized Form
    • Field Detail

      • instanceId

        protected String instanceId
      • refSupplier

        protected java.util.function.Supplier<? extends Ref<T>> refSupplier
    • Constructor Detail

      • SingletonLazyRef

        public SingletonLazyRef​(String instanceId,
                                java.util.function.Supplier<? extends Ref<T>> refSupplier)
    • Method Detail

      • create

        public static <T> SingletonLazyRef<T> create​(String id,
                                                     java.util.function.Supplier<? extends Ref<T>> refSupp)
      • create

        public static <T> SingletonLazyRef<T> create​(java.util.function.Supplier<? extends Ref<T>> refSupp)
      • get

        public Ref<T> get()
        Every call to .get() returns a fresh reference that must eventually be released!
        Specified by:
        get in interface java.util.function.Supplier<T>