-
- All Implemented Interfaces:
-
java.lang.Comparable,java.util.concurrent.Callable
public abstract class Task<Result> implements Callable<QueueResult>, Comparable<Task<out Object>>
Executable piece of work in the Queue, child classes can do any actual type of work, Queue doesn't care. This class defines core principles, like dependencies, priority, retry policy, id, etc.
-
-
Field Summary
Fields Modifier and Type Field Description private final TaskTypetypeprivate final Set<TaskType>dependenciesprivate final Set<TaskType>softDependenciesprivate longexecutionTimeprivate final intorderprivate ThrowableexecutionErrorprivate volatile intretryCount
-
Constructor Summary
Constructors Constructor Description Task(TaskType type, Array<TaskType> dependencies, String id)Constructs new task, this constructor allows the most customisationsPay attention to the id parameter, it's used to restrict parallel execution of tasks of the same type.That means if two tasks of equal type have equal id - they considered equal.Queue behaves like a set, so equal tasks cannot be added to the queue at the same time. Task(TaskType type, Array<TaskType> dependencies)Constructor which uses unique id for each task (allows parallel execution of tasks of the same type)
-
Method Summary
Modifier and Type Method Description TaskTypegetType()Set<TaskType>getDependencies()Set<TaskType>getSoftDependencies()Return set of "soft" dependencies for this task.That means task will wait for these dependencies only in case we havepending or running tasks of such types in the queue.If no such tasks are in the queue when you add this task - these dependencies are ignored. longgetExecutionTime()final intgetOrder()ThrowablegetExecutionError()final intgetRetryCount()Indicates number of times task was executed, INCLUDING the initial try.E.g. final voidaddDependency(TaskType dependency)Adds new dependency to this type, duplicated types are ignored. final voidaddSoftDependency(TaskType dependency)Adds new soft dependency to this type, duplicated types are ignored. abstract ResultgetResult()Task should store result of it's execution if applicable and return with this method final QueueResultcall()QueueResultexecutionResult()final intcompareTo(Task<out Object> o)final booleanequals(Object o)final inthashCode()StringtoString()-
-
Constructor Detail
-
Task
Task(TaskType type, Array<TaskType> dependencies, String id)
Constructs new task, this constructor allows the most customisationsPay attention to the id parameter, it's used to restrict parallel execution of tasks of the same type.That means if two tasks of equal type have equal id - they considered equal.Queue behaves like a set, so equal tasks cannot be added to the queue at the same time.- Parameters:
type- Type of the task, used to calculate dependencies and prioritydependencies- types of tasks, which this task should wait for being executed before itid- unique identifier of the task, allows to distinguish it from othersIf null is passed - each task as unique, order is used.
-
-
Method Detail
-
getDependencies
@NonNull() Set<TaskType> getDependencies()
-
getSoftDependencies
@NonNull() Set<TaskType> getSoftDependencies()
Return set of "soft" dependencies for this task.That means task will wait for these dependencies only in case we havepending or running tasks of such types in the queue.If no such tasks are in the queue when you add this task - these dependencies are ignored.
As example all events must wait for conversion if we have that in the queue(e.g. we have long list of tasks in result of no internet).However, events with counter 0 must wait for conversion even if it's not yet started(SDK start() not called but init() called)
-
getExecutionTime
long getExecutionTime()
-
getOrder
final int getOrder()
-
getExecutionError
@Nullable() Throwable getExecutionError()
-
getRetryCount
final int getRetryCount()
Indicates number of times task was executed, INCLUDING the initial try.E.g. if task succeed from the first try - this will return 1.
-
addDependency
final void addDependency(TaskType dependency)
Adds new dependency to this type, duplicated types are ignored.
N.B. This will take effect only before task is added to the Queue
-
addSoftDependency
final void addSoftDependency(TaskType dependency)
Adds new soft dependency to this type, duplicated types are ignored.
E.g. Useful for waiting for conversion to be done if have no internet.
-
getResult
@Nullable() abstract Result getResult()
Task should store result of it's execution if applicable and return with this method
-
call
final QueueResult call()
-
executionResult
@Nullable() QueueResult executionResult()
-
compareTo
final int compareTo(Task<out Object> o)
- Parameters:
o- task that given task is compared to
-
hashCode
final int hashCode()
-
-
-
-