Package com.yahoo.yolean.concurrent
Class Memoized<T,E extends Exception>
java.lang.Object
com.yahoo.yolean.concurrent.Memoized<T,E>
- All Implemented Interfaces:
AutoCloseable,Supplier<T>
Wraps a lazily initialised resource which needs to be shut down.
The wrapped supplier may not return
null, and should be retryable on failure.
If it throws, it will be retried if get() is retried. A supplier that fails to
clean up partial state on failure may cause a resource leak.- Author:
- jonmv
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceMemoized.Closer<T,E extends Exception> Provides a tighter bound on the thrown exception type. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()combine(Memoized<T, ? extends E> inner, Function<T, U> outer, Memoized.Closer<U, ? extends E> closer) Composes the given memoized with a function taking its output as an argument to produce a new Memoized, with the given closer.get()static <T extends AutoCloseable>
Memoized<T,?> Returns a generic AutoCloseable Memoized with the given AutoCloseable-supplier.
-
Constructor Details
-
Memoized
Returns a new Memoized which has no close method. -
Memoized
Returns a new Memoized with the given factory and closer.
-
-
Method Details
-
of
Returns a generic AutoCloseable Memoized with the given AutoCloseable-supplier. -
combine
public static <T,U, Memoized<U,E extends Exception> E> combine(Memoized<T, ? extends E> inner, Function<T, U> outer, Memoized.Closer<U, ? extends E> closer) Composes the given memoized with a function taking its output as an argument to produce a new Memoized, with the given closer. -
get
-
close
- Specified by:
closein interfaceAutoCloseable- Throws:
E extends Exception
-