-
- All Implemented Interfaces:
-
java.util.concurrent.Callable,kotlin.Comparable
public abstract class Task<Result extends Object> implements Callable<QueueResult>, Comparable<Task<?>>
Executable piece of work in the Queue; child classes can do any actual type of work, the Queue does not care. Defines the core principles: dependencies, priority, retry policy and id.
The generic
Resultis the value returned via result; use Void (or Unit) when nothing is returned. The type derives priority and the hard-dependency contract. The constructor'sinitialDependenciesseed the dependencies set — additional ones can be added with addDependency until the task is enqueued. The constructor'staskIdrestricts parallel execution of tasks of the same type: two tasks with the same type and id are considered equal and the Queue (set semantics) rejects duplicates. When the id isnulleach task is unique — the internal creation order is used.
-
-
Field Summary
Fields Modifier and Type Field Description private final Set<TaskType>dependenciesprivate final Set<TaskType>softDependenciesprivate final Integerorderprivate LongexecutionTimeprivate ThrowableexecutionErrorprivate volatile IntegerretryCountprivate final Resultresultprivate final TaskTypetype
-
Method Summary
Modifier and Type Method Description final Set<TaskType>getDependencies()final Set<TaskType>getSoftDependencies()final IntegergetOrder()Chronological order in which the task object was created. final LonggetExecutionTime()final UnitsetExecutionTime(Long executionTime)final ThrowablegetExecutionError()Error which happened during task execution, or nullif the task was successful.final UnitsetExecutionError(Throwable executionError)final IntegergetRetryCount()Number of times the task was executed, INCLUDING the initial try. final UnitsetRetryCount(Integer retryCount)abstract ResultgetResult()Task should store result of its execution if applicable and return it via this property. final TaskTypegetType()final UnitaddDependency(TaskType dependency)Adds a new hard dependency to this type; duplicates are ignored. final UnitaddSoftDependency(TaskType dependency)Adds a new soft dependency to this type; duplicates are ignored. final QueueResultexecutionResult()Result of execution of this task by Queue. final QueueResultcall()final IntegercompareTo(Task<?> other)final Booleanequals(Object other)final IntegerhashCode()StringtoString()-
-
Method Detail
-
getDependencies
final Set<TaskType> getDependencies()
-
getSoftDependencies
final Set<TaskType> getSoftDependencies()
-
getOrder
final Integer getOrder()
Chronological order in which the task object was created. Required to support natural ordering in the Queue SkipListSet: two tasks of the same type and priority — the first one has the smaller order.
-
getExecutionTime
final Long getExecutionTime()
-
setExecutionTime
final Unit setExecutionTime(Long executionTime)
-
getExecutionError
final Throwable getExecutionError()
Error which happened during task execution, or
nullif the task was successful.
-
setExecutionError
final Unit setExecutionError(Throwable executionError)
-
getRetryCount
final Integer getRetryCount()
Number of times the task was executed, INCLUDING the initial try. E.g. if the task succeeded on the first try this returns 1.
-
setRetryCount
final Unit setRetryCount(Integer retryCount)
-
getResult
abstract Result getResult()
Task should store result of its execution if applicable and return it via this property.
-
addDependency
final Unit addDependency(TaskType dependency)
Adds a new hard dependency to this type; duplicates are ignored.
N.B. This will only take effect before the task is added to the Queue.
-
addSoftDependency
final Unit addSoftDependency(TaskType dependency)
Adds a new soft dependency to this type; duplicates are ignored. Useful, for example, when waiting for conversion to complete while there is no internet.
N.B. This will only take effect before the task is added to the Queue.
-
executionResult
final QueueResult executionResult()
Result of execution of this task by Queue.
-
call
final QueueResult call()
-
-
-
-