Package org.aksw.commons.util.ref
Class SingletonLazyRef<T>
- java.lang.Object
-
- org.aksw.commons.util.ref.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 aDataSourceacross 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 Summary
Fields Modifier and Type Field Description protected StringinstanceIdprotected java.util.function.Supplier<? extends Ref<T>>refSupplier
-
Constructor Summary
Constructors Constructor Description SingletonLazyRef(String instanceId, java.util.function.Supplier<? extends Ref<T>> refSupplier)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <T> SingletonLazyRef<T>create(String id, java.util.function.Supplier<? extends Ref<T>> refSupp)static <T> SingletonLazyRef<T>create(java.util.function.Supplier<? extends Ref<T>> refSupp)Ref<T>get()Every call to .get() returns a fresh reference that must eventually be released!
-
-
-
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)
-
-