org.wicketstuff.progressbar.spring
Class Task

java.lang.Object
  extended by org.wicketstuff.progressbar.spring.Task

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.

Author:
Christopher Hlubek (hlubek)

Nested Class Summary
static class Task.Message
           Message is a value object for messages during task runtime.
 
Constructor Summary
Task()
           
Task(Runnable runnable)
           
 
Method Summary
 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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Task

public Task()

Task

public Task(Runnable runnable)
Method Detail

run

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;
 }
 


doFinish

protected void doFinish()
Will be called after finishing the task


isCancelled

public boolean isCancelled()

reset

public void reset()

cancel

public void cancel()

updateProgress

public void updateProgress(int current,
                           int total)
Update the current progress with current / total values (e.g. 1st of 5). This should be called from the run method for every iteration.

Parameters:
current - The current iteration (counted from zero!)
total - Total iterations

updateProgress

public void updateProgress(int progressPercent)
Update progress with percentage value

Parameters:
progressPercent - progress in percent in [0, 100]

isDone

public boolean isDone()

getProgress

public int getProgress()

info

public void info(String messageKey,
                 Object... arguments)
Add an info message

Parameters:
messageKey -
arguments -

warn

public void warn(String messageKey,
                 Object... arguments)
Add an warn message

Parameters:
messageKey -
arguments -

error

public void error(String messageKey,
                  Object... arguments)
Add an error message

Parameters:
messageKey -
arguments -

getMessages

public List<Task.Message> getMessages()
Get generated messages

Returns:
generated messages


Copyright © 2007–2016. All rights reserved.