public class Tasks extends Object
| Constructor and Description |
|---|
Tasks() |
| Modifier and Type | Method and Description |
|---|---|
static ConfigurableTask |
closeAfterEachRun(Task task)
Returns task that behaves the same as a Task passed
but performes cleanup as the last action performed by run method.
|
static ConfigurableTask |
closingTaskFor(Task task)
Returns task that performs cleanup for the original task when run.
|
static ConfigurableTask |
configure(Task task)
Wrapps task.
|
static ConfigurableTask |
doNothing() |
static ConfigurableTask |
factory(TaskFactory factory)
Creates task for given factory
When Task#run method of created task is called
TaskFactory#createWorkTask method of factory is called
and resulting task is runned.
|
static ConfigurableTask |
log(Task task,
Logger logger,
String name)
Create task that logs invocation of it's methods
|
static ConfigurableTask |
parallel(List<? extends Task> tasks) |
static ConfigurableTask |
parallel(Task... tasks) |
static ConfigurableTask |
repeat(Task task)
Repeat given task
|
static ConfigurableTask |
repeat(Task task,
long pause,
TimeUnit unit)
Repeat given task with pauses between task invocation
|
static ConfigurableTask |
runnable(Runnable runnable)
Creates task from Runnable object
When Task#run method of created task is called Runnable#run method is called in response
Task#close and Task#stop methods of created task does nothong
|
static ConfigurableTask |
sequence(List<? extends Task> tasks) |
static ConfigurableTask |
sequence(Task... tasks) |
static Thread |
spawn(Task task)
Runs given task in a new thread
|
static ConfigurableTask |
swallowExceptions(Task task,
Logger logger,
long pause,
TimeUnit unit)
Creates new task that catches all exceptions of it's subtask.
|
static ConfigurableTask |
unstoppable(Task task)
Returns task that can't be stopped externally.
|
static ConfigurableTask |
withAdditinalClosingAction(Task task,
Runnable closingAction)
Returns task that behaves like the original task but performs additinal cleanup action
Resulting task's Task#close method calls original task's Task#close method and
given closingAction
|
static ConfigurableTask |
withoutClose(Task task)
Returns task that doesn't perfom cleanup.
|
public static Thread spawn(Task task)
task - task to run in new threadpublic static ConfigurableTask runnable(Runnable runnable)
When Task#run method of created task is called Runnable#run method is called in response
Task#close and Task#stop methods of created task does nothong
runnable - runnable to base task onpublic static ConfigurableTask factory(TaskFactory factory)
When Task#run method of created task is called TaskFactory#createWorkTask method of factory is called and resulting task is runned. Cleanup for resulting task is performed after.
When Task#close method of created task is called TaskFactory#createClosingTask method of factory is called and resulting task is runned. Cleanup for resulting task is performed after.
factory - to create "main" and "cleanup" taskspublic static ConfigurableTask repeat(Task task, long pause, TimeUnit unit)
task - task to repeatpause - pause between invocations of argument taskunit - time unit of pausepublic static ConfigurableTask repeat(Task task)
task - task to repeatpublic static ConfigurableTask log(Task task, Logger logger, String name)
task - task to perform actual worklogger - logger to log method invocation byname - name to use in log messagespublic static ConfigurableTask swallowExceptions(Task task, Logger logger, long pause, TimeUnit unit)
task - subtask to perform action worklogger - logger to log messages withpause - time to sleep after caught exceptionunit - time unit of pausepublic static ConfigurableTask doNothing()
public static ConfigurableTask sequence(Task... tasks)
tasks - array of subtaskspublic static ConfigurableTask sequence(List<? extends Task> tasks)
tasks - list of subtaskspublic static ConfigurableTask parallel(Task... tasks)
tasks - array of subtaskspublic static ConfigurableTask parallel(List<? extends Task> tasks)
tasks - list of subtaskspublic static ConfigurableTask closeAfterEachRun(Task task)
#close method does nothing. When #run method is called, #run method of the original task is called at first and than #close method of the original task is called
task - to base resulting task onpublic static ConfigurableTask configure(Task task)
task - task to wrappublic static ConfigurableTask unstoppable(Task task)
task - to base behaviour onpublic static ConfigurableTask withoutClose(Task task)
task - to base behaviour onpublic static ConfigurableTask closingTaskFor(Task task)
task - to base behaviour onpublic static ConfigurableTask withAdditinalClosingAction(Task task, Runnable closingAction)
task - to base behaviour onclosingAction - action to close on cleanupCopyright © 2013. All Rights Reserved.