Gephi Toolkit Javadoc

org.gephi.utils.longtask.api
Class LongTaskExecutor

java.lang.Object
  extended by org.gephi.utils.longtask.api.LongTaskExecutor

public final class LongTaskExecutor
extends java.lang.Object

Portable long-task executor, that supports synchronous and asynchronous execution, progress, cancellation and error management.

Note that only one task can be executed by the executor at one time.

Author:
Mathieu Bastian
See Also:
LongTask

Constructor Summary
LongTaskExecutor(boolean doInBackground)
          Creates a new long task executor.
LongTaskExecutor(boolean doInBackground, java.lang.String name)
          Creates a new long task executor.
LongTaskExecutor(boolean doInBackground, java.lang.String name, int interruptDelay)
          Creates a new long task executor.
 
Method Summary
 void cancel()
          Cancel the current task.
 void execute(LongTask task, java.lang.Runnable runnable)
          Execute a long task with cancel and progress support.
 void execute(LongTask task, java.lang.Runnable runnable, java.lang.String taskName, LongTaskErrorHandler errorHandler)
          Execute a long task with cancel and progress support.
 boolean isRunning()
          Returns true if the executor is executing a task.
 void setDefaultErrorHandler(LongTaskErrorHandler errorHandler)
          Set the default error handler.
 void setLongTaskListener(LongTaskListener listener)
          Set the listener to this executor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LongTaskExecutor

public LongTaskExecutor(boolean doInBackground,
                        java.lang.String name,
                        int interruptDelay)
Creates a new long task executor.

Parameters:
doInBackground - when true, the task will be executed in a separate thread
name - the name of the executor, used to recognize threads by names
interruptDelay - number of seconds to wait before calling Thread.interrupt() after a cancel request

LongTaskExecutor

public LongTaskExecutor(boolean doInBackground,
                        java.lang.String name)
Creates a new long task executor.

Parameters:
doInBackground - doInBackground when true, the task will be executed in a separate thread
name - 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 when true, the task will be executed in a separate thread
Method Detail

execute

public void execute(LongTask task,
                    java.lang.Runnable runnable,
                    java.lang.String taskName,
                    LongTaskErrorHandler errorHandler)
Execute a long task with cancel and progress support. Task can be null. In this case runnable will be executed normally, but without cancel and progress support.

Parameters:
task - the task to be executed, can be null.
runnable - the runnable to be executed
taskName - the name of the task, is displayed in the status bar if available
errorHandler - error handler for exception retrieval during execution
Throws:
java.lang.NullPointerException - if runnable or taskName is null
java.lang.IllegalStateException - if a task is still executing at this time

execute

public void execute(LongTask task,
                    java.lang.Runnable runnable)
Execute a long task with cancel and progress support. Task can be null. In this case runnable will be executed normally, but without cancel and progress support.

Parameters:
task - the task to be executed, can be null.
runnable - the runnable to be executed
Throws:
java.lang.NullPointerException - if runnable is null
java.lang.IllegalStateException - 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 an interruptDelay has been specified, the task will be interrupted after interruptDelay. Using Thread.interrupt() may cause hazardous behaviours and should be avoided. Therefore any task should be cancellable.


isRunning

public boolean isRunning()
Returns true if the executor is executing a task.

Returns:
true if a task is running, false otherwise

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

Gephi Toolkit Javadoc