TASK_ID
- The ID parameter type for the task.PARAM
- The parameter type for the task.RESULT
- The result type for the task.public abstract class WorkerTask<TASK_ID,PARAM,RESULT> extends Object implements Comparable<Object>
Modifier and Type | Class and Description |
---|---|
static class |
WorkerTask.State
Task states.
|
Modifier and Type | Field and Description |
---|---|
long |
createTime
The time when the task was created.
|
static int |
PRIORITY_DEFAULT
The priority level of the task: default (5).
|
static int |
PRIORITY_HIGHEST
The priority level of the task: highest (10).
|
static int |
PRIORITY_LOWEST
The priority level of the task: lowest (0).
|
Constructor and Description |
---|
WorkerTask()
Constructor for the task to perform, no task ID, no parameter, no callback, default priority.
|
WorkerTask(PARAM param)
Constructor for the task to perform, no task ID, no callback, default priority.
|
WorkerTask(TASK_ID id,
PARAM param)
Constructor for the task to perform, no callback, default priority.
|
WorkerTask(TASK_ID id,
PARAM param,
WorkerTaskEnded<TASK_ID,PARAM,RESULT> callback)
Constructor for the task to perform, default priority.
|
WorkerTask(TASK_ID id,
PARAM param,
WorkerTaskEnded<TASK_ID,PARAM,RESULT> callback,
int priority)
Constructor for the task to perform.
|
Modifier and Type | Method and Description |
---|---|
boolean |
cancel(boolean interruptTaskThread)
Cancels the task.
|
int |
compareTo(Object wt)
Compares the priority level of the specified task with this one.
|
void |
execute()
Starts execution of the task.
|
abstract RESULT |
execute(TASK_ID id,
PARAM param)
Start execution of the task with the implementation specific
task ID and parameter.
|
long |
getEndTime()
Gets the time in milliseconds (System.currentTimeMillis) when the task ended.
|
Throwable |
getException()
Gets the exception thrown by the task if it completed with an exception.
|
TASK_ID |
getID()
Gets the ID parameter.
|
int |
getModalID()
Gets the modal ID when the modality extends beyond this process,
e.g.
|
PARAM |
getParam()
Gets the
PARAM parameter. |
RESULT |
getResult()
Gets the result of the task if it has completed successfully.
|
long |
getStartTime()
Gets the time in milliseconds (System.currentTimeMillis) when the task was started.
|
WorkerTask.State |
getState()
Checks the current task state.
|
WorkerNIO |
getWorker()
Gets the worker associated with this task.
|
boolean |
isCancelled()
Checks if the task is cancelled.
|
void |
setCallback(WorkerTaskEnded<TASK_ID,PARAM,RESULT> callback)
Sets the callback function that is called upon end of the task, called regardless
if a result is set for normal completion, or an exception.
|
void |
waitForTaskEnded()
Waits for task to end.
|
public static final int PRIORITY_LOWEST
public static final int PRIORITY_DEFAULT
public static final int PRIORITY_HIGHEST
public final long createTime
public WorkerTask()
public WorkerTask(PARAM param)
param
- The implementation specific parameter, or null for none.public WorkerTask(TASK_ID id, PARAM param)
id
- The implementation specific task ID.param
- The implementation specific parameter, or null for none.public WorkerTask(TASK_ID id, PARAM param, WorkerTaskEnded<TASK_ID,PARAM,RESULT> callback)
id
- The implementation specific task ID.param
- The implementation specific parameter, or null for none.callback
- The callback function to call when task ends or is cancelled, null for none.public WorkerTask(TASK_ID id, PARAM param, WorkerTaskEnded<TASK_ID,PARAM,RESULT> callback, int priority)
id
- The implementation specific task ID.param
- The implementation specific parameter, or null for none.callback
- The callback function to call when task ends or is cancelled, null for none.priority
- The priority of the task.public final void setCallback(WorkerTaskEnded<TASK_ID,PARAM,RESULT> callback)
callback
- The callback function to call when task ends or is cancelled, null for none.public final void execute()
public abstract RESULT execute(TASK_ID id, PARAM param) throws Exception
id
- The implementation specific task ID.param
- The implementation specific parameter, or null for none.Exception
- If some error occurs during processing of the task.public final int getModalID()
public final WorkerTask.State getState()
public final TASK_ID getID()
public final PARAM getParam()
PARAM
parameter.public final RESULT getResult()
public final Throwable getException()
public final boolean isCancelled()
public boolean cancel(boolean interruptTaskThread)
interruptTaskThread
- Flag indicating if the task thread should be interrupted (if running) with
call to thread.interrupt();
.public void waitForTaskEnded() throws InterruptedException
InterruptedException
- If the current thread is interrupted during the waiting.public long getStartTime()
public long getEndTime()
public final WorkerNIO getWorker()
public final int compareTo(Object wt)
compareTo
in interface Comparable<Object>
wt
- The worker task to compare priority with.iizi® is a registered trademark of Mindus SARL. © Copyright 2019 Mindus SARL. All rights reserved.