public class ValueResolver<T> extends java.lang.Object implements DeferredSupplier<T>, java.lang.Iterable<Maybe<java.lang.Object>>
Tasks
or a DeferredSupplier
then get its contents
deep(boolean, Boolean)
is requested, it applies resolution to contents
Fluent-style API exposes a number of other options.
Modifier and Type | Class and Description |
---|---|
static class |
ValueResolver.ResolverBuilderPretype |
Modifier and Type | Field and Description |
---|---|
static Duration |
NON_BLOCKING_WAIT
Period to wait if we're expecting the operation to be non-blocking, so want to abort if the
invoked task/supplier is taking too long (likely because its value is not yet ready, and
the invoked task is blocked waiting for it).
|
static Duration |
PRETTY_QUICK_WAIT
Period to wait if we're expected to return quickly
but we want to be a bit more generous for things to finish,
without letting a caller get annoyed.
|
static Duration |
REAL_QUICK_PERIOD
Period to wait when we have to poll but want to give the illusion of no wait.
|
static Duration |
REAL_QUICK_WAIT
Period to wait if we're expected to return real quick
but we want fast things to have time to finish.
|
static Duration |
REAL_REAL_QUICK_WAIT
Like
REAL_QUICK_WAIT but even smaller, for use when potentially
resolving multiple items in sequence. |
Modifier and Type | Method and Description |
---|---|
ValueResolver<T> |
clone()
returns a copy of this resolver which can be queried, even if the original (single-use instance) has already been copied
|
ValueResolver<T> |
context(Entity entity)
as
context(ExecutionContext) for use from an entity |
ValueResolver<T> |
context(ExecutionContext exec)
execution context to use when resolving; required if resolving unsubmitted tasks or running with a time limit
|
ValueResolver<T> |
deep(boolean forceDeep)
Deprecated.
use
#deep(boolean, boolean) |
ValueResolver<T> |
deep(boolean forceDeep,
java.lang.Boolean deepTraversalUsesRootType)
causes nested structures (maps, lists) to be descended and nested unresolved values resolved.
|
ValueResolver<T> |
defaultValue(T defaultValue)
sets a default value which will be returned on a call to
get() if the task does not complete
or completes with an error |
ValueResolver<T> |
description(java.lang.String description)
sets a message which will be displayed in status reports while it waits (e.g.
|
ValueResolver<T> |
embedResolutionInTask(java.lang.Boolean embedResolutionInTask)
if true, forces execution of a deferred supplier to be run in a task;
if false, it prevents it (meaning time limits may not be applied);
if null, the default, it runs in a task if a time limit is applied.
|
T |
get() |
Maybe<T> |
getDefault() |
Maybe<T> |
getMaybe() |
ValueResolver<T> |
immediately(boolean val)
Whether the value should be resolved immediately
(following
ImmediateSupplier.getImmediately() semantics with regards to when errors may be thrown,
except some cases where ImmediateSupplier.ImmediateUnsupportedException is thrown may be re-run with a NON_BLOCKING_WAIT
after which the more definitive ImmediateSupplier.ImmediateValueNotAvailableException will be thrown/wrapped. |
ValueResolverIterator<T> |
iterator() |
ValueResolver<T> |
noDefaultValue()
indicates that no default value should be returned on a call to
get() , and instead it should throw
(this is the default; this method is provided to undo a call to defaultValue(Object) ) |
ValueResolver<T> |
recursive(boolean val)
Whether the value should be resolved recursively.
|
static boolean |
supportsDeepResolution(java.lang.Object v) |
ValueResolver<T> |
swallowExceptions()
indicates that exceptions in resolution should not be thrown on a call to
getMaybe() ,
but rather used as part of the Maybe.get() if it's absent,
and swallowed altogether on a call to get() in the presence of a defaultValue(Object) |
ValueResolver<T> |
timeout(Duration timeout)
sets a time limit on executions
|
java.lang.String |
toString() |
ValueResolver<T> |
transientTask(boolean isTransientTask)
whether the task should be marked as transient; defaults true
|
public static Duration REAL_QUICK_WAIT
Timings are always somewhat arbitrary but this at least allows some intention to be captured in code rather than arbitrary values.
public static Duration REAL_REAL_QUICK_WAIT
REAL_QUICK_WAIT
but even smaller, for use when potentially
resolving multiple items in sequence.public static Duration PRETTY_QUICK_WAIT
See REAL_QUICK_WAIT
.
public static final Duration NON_BLOCKING_WAIT
See REAL_QUICK_WAIT
and BROOKLYN-356.
public static Duration REAL_QUICK_PERIOD
Repeater.DEFAULT_REAL_QUICK_PERIOD
public ValueResolver<T> clone()
clone
in class java.lang.Object
public ValueResolver<T> context(ExecutionContext exec)
public ValueResolver<T> context(Entity entity)
context(ExecutionContext)
for use from an entitypublic ValueResolver<T> description(java.lang.String description)
public ValueResolver<T> defaultValue(T defaultValue)
get()
if the task does not complete
or completes with an error
note that getMaybe()
returns an absent object even in the presence of
a default, so that any error can still be accessed
public ValueResolver<T> noDefaultValue()
get()
, and instead it should throw
(this is the default; this method is provided to undo a call to defaultValue(Object)
)public ValueResolver<T> swallowExceptions()
getMaybe()
,
but rather used as part of the Maybe.get()
if it's absent,
and swallowed altogether on a call to get()
in the presence of a defaultValue(Object)
public ValueResolver<T> transientTask(boolean isTransientTask)
public ValueResolver<T> deep(boolean forceDeep)
#deep(boolean, boolean)
public ValueResolver<T> deep(boolean forceDeep, java.lang.Boolean deepTraversalUsesRootType)
Tasks.resolveDeepValue(Object, Class, ExecutionContext, String)
and
Tasks#resolveDeepValueExactly(Object, TypeToken, ExecutionContext, String)
.public ValueResolver<T> embedResolutionInTask(java.lang.Boolean embedResolutionInTask)
running inside a task is required for some DeferredSupplier
instances which look up a task ExecutionContext
.
public ValueResolver<T> timeout(Duration timeout)
used for Task
and DeferredSupplier
instances.
may require an execution context at runtime.
public ValueResolver<T> immediately(boolean val)
ImmediateSupplier.getImmediately()
semantics with regards to when errors may be thrown,
except some cases where ImmediateSupplier.ImmediateUnsupportedException
is thrown may be re-run with a NON_BLOCKING_WAIT
after which the more definitive ImmediateSupplier.ImmediateValueNotAvailableException
will be thrown/wrapped.public ValueResolver<T> recursive(boolean val)
public ValueResolverIterator<T> iterator()
iterator
in interface java.lang.Iterable<Maybe<java.lang.Object>>
public T get()
get
in interface DeferredSupplier<T>
public static boolean supportsDeepResolution(java.lang.Object v)
public java.lang.String toString()
toString
in class java.lang.Object