Package snap.util
Class TaskRunner<T>
java.lang.Object
snap.util.TaskRunner<T>
- All Implemented Interfaces:
TaskMonitor
- Direct Known Subclasses:
TaskRunnerPanel
A class for running operations in the background.
-
Nested Class Summary
Nested classes/interfaces inherited from interface snap.util.TaskMonitor
TaskMonitor.Text
-
Field Summary
Fields inherited from interface snap.util.TaskMonitor
NULL
-
Constructor Summary
ConstructorDescriptionConstructor.TaskRunner
(TaskMonitor aMonitor) Constructor for given monitor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add listener.void
Begin processing a single task.void
cancel()
Cancels the runner.void
The method to run when cancelled.void
endTask()
Finish the current task, so the next can begin.void
The method to run on failure.void
finished()
The method to run 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.long
Returns the elapsed time.long
Returns the end time.Returns the exception.Returns the monitor.getName()
Returns the name of runner (and thread).Returns the result.long
Returns the start time.Returns the status.protected long
Returns the system time.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.abstract T
run()
The method to run.void
setMonitor
(TaskMonitor aMonitor) Sets the monitor.void
Sets the name of runner (and thread).protected void
setStatus
(TaskRunner.Status aStatus) Sets the status.start()
Starts the runner.void
startTasks
(int aTaskCount) Advise the monitor of the total number of subtasks (invoke only once).void
The method run on success.void
updateTask
(int theWorkDone) Denote that some work units have been completed.
-
Field Details
-
Progress_Prop
- See Also:
-
ActivityText_Prop
- See Also:
-
Status_Prop
- See Also:
-
-
Constructor Details
-
TaskRunner
public TaskRunner()Constructor. -
TaskRunner
Constructor for given monitor.
-
-
Method Details
-
getName
Returns the name of runner (and thread). -
setName
Sets the name of runner (and thread). -
getMonitor
Returns the monitor. -
setMonitor
Sets the monitor. -
startTasks
public void startTasks(int aTaskCount) Advise the monitor of the total number of subtasks (invoke only once).- Specified by:
startTasks
in interfaceTaskMonitor
-
beginTask
Begin processing a single task.- Specified by:
beginTask
in interfaceTaskMonitor
-
updateTask
public void updateTask(int theWorkDone) Denote that some work units have been completed.- Specified by:
updateTask
in interfaceTaskMonitor
-
endTask
public void endTask()Finish the current task, so the next can begin.- Specified by:
endTask
in interfaceTaskMonitor
-
getStatus
Returns the status. -
setStatus
Sets the status. -
getThread
Returns the thread. -
join
Joins the runner. -
join
Joins the runner. -
isActive
public boolean isActive()Returns whether thread is still active. -
isCancelled
public boolean isCancelled()Whether runner has been cancelled.- Specified by:
isCancelled
in interfaceTaskMonitor
- Returns:
- true if the user asked the process to stop working.
-
getStartTime
public long getStartTime()Returns the start time. -
getEndTime
public long getEndTime()Returns the end time. -
getElapsedTime
public long getElapsedTime()Returns the elapsed time. -
getSystemTime
protected long getSystemTime()Returns the system time. -
start
Starts the runner. -
cancel
public void cancel()Cancels the runner. -
run
The method to run.- Throws:
Exception
-
success
The method run on success. -
cancelled
The method to run when cancelled. -
failure
The method to run on failure. -
finished
public void finished()The method to run when finished (after success()/failure() call). -
getResult
Returns the result. -
getException
Returns the exception. -
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.
-