Class LazyAtomicReference<T>
java.lang.Object
org.apache.hadoop.util.functional.LazyAtomicReference<T>
- Type Parameters:
T- type of reference
- All Implemented Interfaces:
Supplier<T>,CallableRaisingIOE<T>
- Direct Known Subclasses:
LazyAutoCloseableReference
A lazily constructed reference, whose reference
constructor is a
CallableRaisingIOE so
may raise IOExceptions.
This constructor is only invoked on demand
when the reference is first needed,
after which the same value is returned.
This value MUST NOT be null.
Implements CallableRaisingIOE and java.util.function.Supplier.
An instance of this can therefore be used in a functional IO chain.
As such, it can act as a delayed and caching invocator of a function:
the supplier passed in is only ever invoked once, and only when requested.
-
Constructor Summary
ConstructorsConstructorDescriptionLazyAtomicReference(CallableRaisingIOE<? extends T> constructor) Constructor for this instance. -
Method Summary
Modifier and TypeMethodDescriptionfinal Tapply()Implementation ofCallableRaisingIOE.apply().eval()Get the value, constructing it if needed.final Tget()Implementation ofSupplier.get().protected CallableRaisingIOE<? extends T>Getter for the constructor.protected AtomicReference<T>Get the reference.final booleanisSet()Is the reference set?static <T> LazyAtomicReference<T>lazyAtomicReferenceFromSupplier(Supplier<T> supplier) Create from a supplier.toString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.hadoop.util.functional.CallableRaisingIOE
unchecked
-
Constructor Details
-
LazyAtomicReference
Constructor for this instance.- Parameters:
constructor- method to invoke to actually construct the inner object.
-
-
Method Details
-
getConstructor
Getter for the constructor.- Returns:
- the constructor class
-
getReference
Get the reference. Subclasses working with this need to be careful working with this.- Returns:
- the reference.
-
eval
Get the value, constructing it if needed.- Returns:
- the value
- Throws:
IOException- on any evaluation failureNullPointerException- if the evaluated function returned null.
-
apply
Implementation ofCallableRaisingIOE.apply(). Invokeeval().- Specified by:
applyin interfaceCallableRaisingIOE<T>- Returns:
- the value
- Throws:
IOException- on any evaluation failure
-
get
Implementation ofSupplier.get().Invoke
eval()and convert IOEs to UncheckedIOException.This is the
Supplier.get()implementation, which allows this class to passed into anything taking a supplier.- Specified by:
getin interfaceSupplier<T>- Returns:
- the value
- Throws:
UncheckedIOException- if the constructor raised an IOException.
-
isSet
public final boolean isSet()Is the reference set?- Returns:
- true if the reference has been set.
-
toString
-
lazyAtomicReferenceFromSupplier
Create from a supplier. This is not a constructor to avoid ambiguity when a lambda-expression is passed in.- Type Parameters:
T- type of reference- Parameters:
supplier- supplier implementation.- Returns:
- a lazy reference.
-