public class Tasks
extends java.lang.Object
Constructor and Description |
---|
Tasks() |
Modifier and Type | Method and Description |
---|---|
static void |
addTagDynamically(java.lang.Object tag)
as
TaskTags.addTagDynamically(TaskAdaptable, Object) but for current task, skipping if no current task |
static boolean |
blockUntilInternalTasksEnded(Task<?> t,
Duration timeout)
Workaround for limitation described at
Task.cancel(boolean) ;
internal method used to allow callers to wait for underlying tasks to finished in the case of cancellation. |
static <T> TaskBuilder<T> |
builder() |
static java.lang.Iterable<Task<?>> |
children(Task<?> task)
return all children tasks of the given tasks, if it has children, else empty list
|
static Task |
current()
the
Task where the current thread is executing, if executing in a Task, otherwise null;
if the current task is a proxy, this returns the target of that proxy |
static java.lang.Iterable<Task<?>> |
descendants(Task<?> root,
boolean parentFirst)
returns the task, its children, and all its children, and so on;
|
static Task<java.lang.Void> |
fail(java.lang.String name,
java.lang.Throwable optionalError) |
static java.lang.Iterable<Task<?>> |
failed(java.lang.Iterable<Task<?>> subtasks)
returns failed tasks
|
static java.lang.Throwable |
getError(Task<?> t)
returns the error thrown by the task if
Task.isError() , or null if no error or not done |
static Task<?> |
getFinalProxyTarget(Task<?> task) |
static boolean |
isAncestorCancelled(Task<?> t) |
static boolean |
isInterrupted()
returns true if either the current thread or the current task is interrupted/cancelled
|
static boolean |
isQueued(TaskAdaptable<?> task) |
static boolean |
isQueuedOrSubmitted(TaskAdaptable<?> task) |
static boolean |
isSubmitted(TaskAdaptable<?> task) |
static void |
markInessential()
marks the current task inessential; this mainly matters if the task is running in a parent
TaskQueueingContext and we don't want the parent to fail if this task fails |
static Task<java.util.List<?>> |
parallel(java.lang.Iterable<? extends TaskAdaptable<?>> tasks) |
static Task<java.util.List<?>> |
parallel(java.lang.String name,
java.lang.Iterable<? extends TaskAdaptable<?>> tasks) |
static Task<java.util.List<?>> |
parallel(java.lang.String name,
TaskAdaptable<?>... tasks) |
static Task<java.util.List<?>> |
parallel(TaskAdaptable<?>... tasks) |
static TaskBuilder<?> |
requiring(Repeater repeater) |
static void |
resetBlockingDetails() |
static void |
resetBlockingTask() |
static java.lang.Object |
resolveDeepValue(java.lang.Object v,
java.lang.Class<?> type,
ExecutionContext exec) |
static <T> T |
resolveDeepValue(java.lang.Object v,
java.lang.Class<T> type,
ExecutionContext exec,
java.lang.String contextMessage)
Resolves the given object, blocking on futures and coercing it to the given type.
|
static <T> T |
resolveValue(java.lang.Object v,
java.lang.Class<T> type,
ExecutionContext exec) |
static <T> T |
resolveValue(java.lang.Object v,
java.lang.Class<T> type,
ExecutionContext exec,
java.lang.String contextMessage)
attempt to resolve the given value as the given type, waiting on futures, submitting if necessary,
and coercing as allowed by TypeCoercions;
contextMessage (optional) will be displayed in status reports while it waits (e.g.
|
static ValueResolver.ResolverBuilderPretype |
resolving(java.lang.Object v) |
static <T> ValueResolver<T> |
resolving(java.lang.Object v,
java.lang.Class<T> type)
creates a
ValueResolver instance which allows significantly more customization than
the various resolveValue(Object, Class, ExecutionContext) methods here |
static Task<java.util.List<?>> |
sequential(java.util.List<? extends TaskAdaptable<?>> tasks) |
static Task<java.util.List<?>> |
sequential(java.lang.String name,
java.util.List<? extends TaskAdaptable<?>> tasks) |
static Task<java.util.List<?>> |
sequential(java.lang.String name,
TaskAdaptable<?>... tasks) |
static TaskFactory<?> |
sequential(java.lang.String name,
TaskFactory<?>... taskFactories) |
static Task<java.util.List<?>> |
sequential(TaskAdaptable<?>... tasks) |
static TaskFactory<?> |
sequential(TaskFactory<?>... taskFactories) |
static java.lang.String |
setBlockingDetails(java.lang.String description)
convenience for setting "blocking details" on any task where the current thread is running;
typically invoked prior to a wait, for transparency to a user;
then invoked with 'null' just after the wait
|
static Task<?> |
setBlockingTask(Task<?> blocker) |
static void |
setExtraStatusDetails(java.lang.String notes)
sets extra status details on the current task, if possible (otherwise does nothing).
|
static <T> com.google.common.base.Supplier<T> |
supplier(TaskAdaptable<T> task)
see also
resolving(Object) which gives much more control about submission, timeout, etc |
static void |
swallowChildrenFailures()
causes failures in subtasks of the current task not to fail the parent;
no-op if not in a
TaskQueueingContext . |
static <T> T |
tag(Task<?> task,
java.lang.Class<T> type,
boolean recurseHierarchy)
returns the first tag found on the given task which matches the given type, looking up the submission hierarachy if necessary
|
static TaskBuilder<java.lang.Boolean> |
testing(Repeater repeater) |
static boolean |
tryQueueing(TaskQueueingContext adder,
TaskAdaptable<?> task)
Adds the given task to the given context.
|
static Task<java.lang.Void> |
warning(java.lang.String message,
java.lang.Throwable optionalError) |
static <T> T |
withBlockingDetails(java.lang.String description,
java.util.concurrent.Callable<T> code)
convenience for setting "blocking details" on any task where the current thread is running,
while the passed code is executed; often used from groovy as
|
public static java.lang.String setBlockingDetails(java.lang.String description)
public static void resetBlockingDetails()
public static void resetBlockingTask()
public static <T> T withBlockingDetails(java.lang.String description, java.util.concurrent.Callable<T> code) throws java.lang.Exception
withBlockingDetails("sleeping 5s") { Thread.sleep(5000); }
If code block is null, the description is set until further notice (not cleareed).java.lang.Exception
public static Task current()
Task
where the current thread is executing, if executing in a Task, otherwise null;
if the current task is a proxy, this returns the target of that proxypublic static <T> ValueResolver<T> resolving(java.lang.Object v, java.lang.Class<T> type)
ValueResolver
instance which allows significantly more customization than
the various resolveValue(Object, Class, ExecutionContext)
methods herepublic static ValueResolver.ResolverBuilderPretype resolving(java.lang.Object v)
public static <T> T resolveValue(java.lang.Object v, java.lang.Class<T> type, @Nullable ExecutionContext exec) throws java.util.concurrent.ExecutionException, java.lang.InterruptedException
java.util.concurrent.ExecutionException
java.lang.InterruptedException
resolveValue(Object, Class, ExecutionContext, String)
public static <T> T resolveValue(java.lang.Object v, java.lang.Class<T> type, @Nullable ExecutionContext exec, java.lang.String contextMessage) throws java.util.concurrent.ExecutionException, java.lang.InterruptedException
java.util.concurrent.ExecutionException
java.lang.InterruptedException
public static java.lang.Object resolveDeepValue(java.lang.Object v, java.lang.Class<?> type, ExecutionContext exec) throws java.util.concurrent.ExecutionException, java.lang.InterruptedException
java.util.concurrent.ExecutionException
java.lang.InterruptedException
resolveDeepValue(Object, Class, ExecutionContext, String)
public static <T> T resolveDeepValue(java.lang.Object v, java.lang.Class<T> type, ExecutionContext exec, java.lang.String contextMessage) throws java.util.concurrent.ExecutionException, java.lang.InterruptedException
Object result = resolveDeepValue(ImmutableList.of(ImmutableMap.of(1, true)), String.class, exec)
To perform a deep conversion of futures contained within Iterables or Maps without coercion of each element,
the type should normally be Object, not the type of the collection. This differs from
resolveValue(Object, Class, ExecutionContext, String)
which will accept Map and Iterable
as the required type.java.util.concurrent.ExecutionException
java.lang.InterruptedException
public static void setExtraStatusDetails(java.lang.String notes)
public static <T> TaskBuilder<T> builder()
public static Task<java.util.List<?>> parallel(TaskAdaptable<?>... tasks)
public static Task<java.util.List<?>> parallel(java.lang.String name, TaskAdaptable<?>... tasks)
public static Task<java.util.List<?>> parallel(java.lang.Iterable<? extends TaskAdaptable<?>> tasks)
public static Task<java.util.List<?>> parallel(java.lang.String name, java.lang.Iterable<? extends TaskAdaptable<?>> tasks)
public static Task<java.util.List<?>> sequential(TaskAdaptable<?>... tasks)
public static Task<java.util.List<?>> sequential(java.lang.String name, TaskAdaptable<?>... tasks)
public static TaskFactory<?> sequential(TaskFactory<?>... taskFactories)
public static TaskFactory<?> sequential(java.lang.String name, TaskFactory<?>... taskFactories)
public static Task<java.util.List<?>> sequential(java.util.List<? extends TaskAdaptable<?>> tasks)
public static Task<java.util.List<?>> sequential(java.lang.String name, java.util.List<? extends TaskAdaptable<?>> tasks)
public static <T> T tag(@Nullable Task<?> task, java.lang.Class<T> type, boolean recurseHierarchy)
public static boolean isAncestorCancelled(Task<?> t)
public static boolean isQueued(TaskAdaptable<?> task)
public static boolean isSubmitted(TaskAdaptable<?> task)
public static boolean isQueuedOrSubmitted(TaskAdaptable<?> task)
public static boolean tryQueueing(TaskQueueingContext adder, TaskAdaptable<?> task)
public static <T> com.google.common.base.Supplier<T> supplier(TaskAdaptable<T> task)
resolving(Object)
which gives much more control about submission, timeout, etcpublic static java.lang.Iterable<Task<?>> children(Task<?> task)
public static java.lang.Iterable<Task<?>> failed(java.lang.Iterable<Task<?>> subtasks)
public static java.lang.Iterable<Task<?>> descendants(Task<?> root, boolean parentFirst)
root
- task whose descendants should be iteratedparentFirst
- whether to put parents before children or afterpublic static java.lang.Throwable getError(Task<?> t)
Task.isError()
, or null if no error or not donepublic static Task<java.lang.Void> fail(java.lang.String name, java.lang.Throwable optionalError)
public static Task<java.lang.Void> warning(java.lang.String message, java.lang.Throwable optionalError)
public static void markInessential()
TaskQueueingContext
and we don't want the parent to fail if this task fails
no-op (silently ignored) if not in a task
@Beta public static void swallowChildrenFailures()
TaskQueueingContext
.
essentially like a markInessential()
on all tasks in the current
TaskQueueingContext
, including tasks queued subsequently
public static void addTagDynamically(java.lang.Object tag)
TaskTags.addTagDynamically(TaskAdaptable, Object)
but for current task, skipping if no current task@Beta public static boolean blockUntilInternalTasksEnded(Task<?> t, Duration timeout)
Task.cancel(boolean)
;
internal method used to allow callers to wait for underlying tasks to finished in the case of cancellation.
It is irritating that FutureTask
sync's object clears the runner thread,
so even if BasicTask.getInternalFuture()
is used, there is no means of determining if the underlying object is done.
The Task.getEndTimeUtc()
seems the only way.
public static boolean isInterrupted()
public static TaskBuilder<java.lang.Boolean> testing(Repeater repeater)
TaskBuilder
which tests whether the repeater terminates with success in its configured timeframe,
returning true or false depending on whether repeater succeedpublic static TaskBuilder<?> requiring(Repeater repeater)
TaskBuilder
which requires that the repeater terminate with success in its configured timeframe,
throwing if it does not