Class BackgroundTask<T>
- java.lang.Object
-
- org.opends.guitools.controlpanel.util.BackgroundTask<T>
-
- Type Parameters:
T- type of object returned by this process
- Direct Known Subclasses:
LDAPEntryReader
public abstract class BackgroundTask<T> extends Object
This class provides a mechanism for running a task in the background using a separate thread and providing the caller with notification when it has completed.
-
-
Constructor Summary
Constructors Constructor Description BackgroundTask()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract voidbackgroundTaskCompleted(T returnValue, Throwable throwable)This method will be invoked to indicate that the background task has completed.voidinterrupt()Interrupts the thread that is running background.booleanisInterrupted()Returnstrueif the thread running in the background is interrupted andfalseotherwise.abstract TprocessBackgroundTask()Performs all processing associated with the task.voidstartBackgroundTask()Creates a new thread and begins running the task in the background.
-
-
-
Method Detail
-
startBackgroundTask
public final void startBackgroundTask()
Creates a new thread and begins running the task in the background. When the task has completed, thebackgroundTaskCompletedmethod will be invoked.
-
interrupt
public final void interrupt()
Interrupts the thread that is running background.
-
isInterrupted
public boolean isInterrupted()
Returnstrueif the thread running in the background is interrupted andfalseotherwise.- Returns:
trueif the thread running in the background is interrupted andfalseotherwise.
-
processBackgroundTask
public abstract T processBackgroundTask() throws Throwable
Performs all processing associated with the task.- Returns:
- An
Objectwith information about the processing performed for this task, ornullif no return value is needed. - Throws:
Throwable- throwable that will be passed through the method backgroundTaskCompleted.
-
backgroundTaskCompleted
public abstract void backgroundTaskCompleted(T returnValue, Throwable throwable)
This method will be invoked to indicate that the background task has completed. If processing completed successfully, then theThrowableargument will benulland thereturnValueargument will contain the value returned by theprocessBackgroundTaskmethod. If an exception or error was thrown, then thethrowableargument will not benull.- Parameters:
returnValue- The value returned by theprocessBackgroundTaskmethod when processing completed, ornullif no value was returned or an exception was encountered during processing.throwable- AThrowableinstance (e.g., an exception) that was raised during processing, ornullif all processing completed successfully.
-
-