public class Task extends Object
A Task is some kind of long running action that should be done in the background. The task can update the progress based on the current position in the workload.
Basically what you have to do for your own Task is to override the run() method and frequently call one of the updateProgress methods.
Modifier and Type | Class and Description |
---|---|
static class |
Task.Message
Message is a value object for messages during task runtime.
|
Modifier and Type | Method and Description |
---|---|
void |
cancel() |
protected void |
doFinish()
Will be called after finishing the task
|
void |
error(String messageKey,
Object... arguments)
Add an error message
|
List<Task.Message> |
getMessages()
Get generated messages
|
int |
getProgress() |
void |
info(String messageKey,
Object... arguments)
Add an info message
|
boolean |
isCancelled() |
boolean |
isDone() |
void |
reset() |
protected void |
run()
Implement the actual calculation of the task here.
|
void |
updateProgress(int progressPercent)
Update progress with percentage value
|
void |
updateProgress(int current,
int total)
Update the current progress with current / total values (e.g.
|
void |
warn(String messageKey,
Object... arguments)
Add an warn message
|
public Task()
public Task(Runnable runnable)
protected void run()
Implement the actual calculation of the task here.
If iterating and cancelling should be supported you should check for a canceled task in every iteration:
if (isCancelled()) { return; }
protected void doFinish()
public boolean isCancelled()
public void reset()
public void cancel()
public void updateProgress(int current, int total)
current
- The current iteration (counted from zero!)total
- Total iterationspublic void updateProgress(int progressPercent)
progressPercent
- progress in percent in [0, 100]public boolean isDone()
public int getProgress()
public void info(String messageKey, Object... arguments)
messageKey
- arguments
- public void warn(String messageKey, Object... arguments)
messageKey
- arguments
- public void error(String messageKey, Object... arguments)
messageKey
- arguments
- public List<Task.Message> getMessages()
Copyright © 2015. All rights reserved.