Package snap.util
Class TaskRunner<T>
java.lang.Object
snap.util.TaskRunner<T>
A class for running operations in the background.
-
Nested Class Summary
-
Field Summary
-
Constructor Summary
ConstructorDescriptionConstructor.TaskRunner
(Callable<T> aSupplier) Constructor for given task function. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add listener.Waits for this task runner to finish and return the result.void
cancel()
Cancels the runner.protected void
This method is called when cancelled.protected void
This method is called on failure.protected void
finished()
This method is called when finished (after success()/failure() call).protected void
firePropChange
(String aProp, Object oldVal, Object newVal) Fires a property change for given property name, old value, new value and index.Returns the exception.Returns the monitor.getName()
Returns the name of runner (and thread).getOnFailure
(Consumer<Exception> aHandler) Returns the failure handler.Returns the success handler.Returns the result.Returns the status.Returns the task supplier function.Returns the thread.protected void
Runs the success method.protected void
Runs the run method.boolean
isActive()
Returns whether thread is still active.boolean
Whether runner has been cancelled.join()
Joins the runner.join
(int aTimeout) Joins the runner.void
Remove listener.run()
The method to run.void
setMonitor
(TaskMonitor aMonitor) Sets the monitor.void
Sets the name of runner (and thread).void
setOnCancelled
(Runnable aRun) Sets the cancelled handler.void
setOnFailure
(Consumer<Exception> aHandler) Sets the failure handler.void
setOnFinished
(Runnable aRun) Sets the finished handler.void
setOnSuccess
(Consumer<T> aHandler) Sets the success handler.protected void
setStatus
(TaskRunner.Status aStatus) Sets the status.void
setTaskFunction
(Callable<T> aSupplier) Sets the task callable function.start()
Starts the runner.protected void
This method is called on success.void
Terminates this runner (clients should try cancel first).
-
Field Details
-
Status_Prop
- See Also:
-
-
Constructor Details
-
TaskRunner
public TaskRunner()Constructor. -
TaskRunner
Constructor for given task function.
-
-
Method Details
-
getName
Returns the name of runner (and thread). -
setName
Sets the name of runner (and thread). -
getTaskFunction
Returns the task supplier function. -
setTaskFunction
Sets the task callable function. -
getStatus
Returns the status. -
setStatus
Sets the status. -
getMonitor
Returns the monitor. -
setMonitor
Sets the monitor. -
getThread
Returns the thread. -
isActive
public boolean isActive()Returns whether thread is still active. -
isCancelled
public boolean isCancelled()Whether runner has been cancelled. -
start
Starts the runner. -
cancel
public void cancel()Cancels the runner. -
terminate
public void terminate()Terminates this runner (clients should try cancel first). -
run
The method to run.- Throws:
Exception
-
success
This method is called on success. -
cancelled
This method is called when cancelled. -
failure
This method is called on failure. -
finished
protected void finished()This method is called when finished (after success()/failure() call). -
getResult
Returns the result. -
awaitResult
Waits for this task runner to finish and return the result. -
join
Joins the runner. -
join
Joins the runner. -
getException
Returns the exception. -
getOnSuccess
Returns the success handler. -
setOnSuccess
Sets the success handler. -
getOnFailure
Returns the failure handler. -
setOnFailure
Sets the failure handler. -
setOnCancelled
Sets the cancelled handler. -
setOnFinished
Sets the finished handler. -
invokeRun
protected void invokeRun()Runs the run method. -
invokeFinished
protected void invokeFinished()Runs the success method. -
addPropChangeListener
Add listener. -
removePropChangeListener
Remove listener. -
firePropChange
Fires a property change for given property name, old value, new value and index.
-