Package org.gephi.utils.longtask.api
Class LongTaskExecutor
- java.lang.Object
-
- org.gephi.utils.longtask.api.LongTaskExecutor
-
-
Constructor Summary
Constructors Constructor Description LongTaskExecutor(boolean doInBackground)Creates a new long task executor.LongTaskExecutor(boolean doInBackground, String name)Creates a new long task executor.LongTaskExecutor(boolean doInBackground, String name, int interruptDelay)Creates a new long task executor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcancel()Cancel the current task.voidexecute(LongTask task, Runnable runnable)Execute a long task with cancel and progress support.voidexecute(LongTask task, Runnable runnable, String taskName, LongTaskErrorHandler errorHandler)Execute a long task with cancel and progress support.<V> Future<V>execute(LongTask task, Callable<V> callable)Execute a long task with cancel and progress support.<V> Future<V>execute(LongTask task, Callable<V> callable, String taskName, LongTaskErrorHandler errorHandler)Execute a long task with cancel and progress support.booleanisRunning()Returnstrueif the executor is executing a task.voidsetDefaultErrorHandler(LongTaskErrorHandler errorHandler)Set the default error handler.voidsetLongTaskListener(LongTaskListener listener)Set the listener to this executor.
-
-
-
Constructor Detail
-
LongTaskExecutor
public LongTaskExecutor(boolean doInBackground, String name, int interruptDelay)Creates a new long task executor.- Parameters:
doInBackground- whentrue, the task will be executed in a separate threadname- the name of the executor, used to recognize threads by namesinterruptDelay- number of seconds to wait before * callingThread.interrupt()after a cancel request
-
LongTaskExecutor
public LongTaskExecutor(boolean doInBackground, String name)Creates a new long task executor.- Parameters:
doInBackground- doInBackground whentrue, the task will be executed in a separate threadname- the name of the executor, used to recognize threads by names
-
LongTaskExecutor
public LongTaskExecutor(boolean doInBackground)
Creates a new long task executor.- Parameters:
doInBackground- doInBackground whentrue, the task will be executed in a separate thread
-
-
Method Detail
-
execute
public void execute(LongTask task, Runnable runnable, String taskName, LongTaskErrorHandler errorHandler)
Execute a long task with cancel and progress support. Task can benull. In this caserunnablewill be executed normally, but without cancel and progress support.- Parameters:
task- the task to be executed, can benull.runnable- the runnable to be executedtaskName- the name of the task, is displayed in the status bar if availableerrorHandler- error handler for exception retrieval during execution- Throws:
NullPointerException- ifrunnable* ortaskNameis nullIllegalStateException- if a task is still executing at this time
-
execute
public <V> Future<V> execute(LongTask task, Callable<V> callable, String taskName, LongTaskErrorHandler errorHandler)
Execute a long task with cancel and progress support. Task can benull. In this casecallablewill be executed normally, but without cancel and progress support.- Parameters:
task- the task to be executed, can benull.callable- the callable to be executedtaskName- the name of the task, is displayed in the status bar if availableerrorHandler- error handler for exception retrieval during execution- Returns:
- a future that can be used to retrieve the result of the task
- Throws:
NullPointerException- ifcallable* ortaskNameis nullIllegalStateException- if a task is still executing at this time
-
execute
public void execute(LongTask task, Runnable runnable)
Execute a long task with cancel and progress support. Task can benull. In this caserunnablewill be executed normally, but without cancel and progress support.- Parameters:
task- the task to be executed, can benull.runnable- the runnable to be executed- Throws:
NullPointerException- ifrunnableis nullIllegalStateException- if a task is still executing at this time
-
execute
public <V> Future<V> execute(LongTask task, Callable<V> callable)
Execute a long task with cancel and progress support. Task can benull. In this casecallablewill be executed normally, but without cancel and progress support.- Parameters:
task- the task to be executed, can benull.callable- the callable to be executed- Throws:
NullPointerException- ifcallableis nullIllegalStateException- if a task is still executing at this time
-
cancel
public void cancel()
Cancel the current task. If the task fails to cancel itself and if aninterruptDelayhas been specified, the task will be interrupted afterinterruptDelay. UsingThread.interrupt()may cause hazardous behaviors and should be avoided. Therefore any task should be cancelable.
-
isRunning
public boolean isRunning()
Returnstrueif the executor is executing a task.- Returns:
trueif a task is running,falseotherwise
-
setLongTaskListener
public void setLongTaskListener(LongTaskListener listener)
Set the listener to this executor. Only a unique listener can be set to this executor. The listener is called when the task terminates normally.- Parameters:
listener- a listener for this executor
-
setDefaultErrorHandler
public void setDefaultErrorHandler(LongTaskErrorHandler errorHandler)
Set the default error handler. Use error handlers to get errors and exceptions thrown during tasks execution.- Parameters:
errorHandler- the default error handler
-
-