Class RunManager
1) Only allow one runnable at any given time. In this model, a new runnable will cause any running
runnable to be cancelled and the new runnable will begin running. Because of this, there will
never be any runnables waiting in the queue. Use the runNow(MonitoredRunnable, String)
method to get this behavior.
2) Allow one running runnable and one pending runnable. In this mode, any running runnable will be
allowed to complete, but any currently pending runnable will be replaced by the new runnable. Use
the runNext(MonitoredRunnable, String)
method to get this behavior.
3) Run all scheduled runnables in the order they are scheduled. Use the
runLater(MonitoredRunnable, String, int)
for this behavior.
If the given runnable has Swing work to perform after the main Runnable.run() method completes
(e.g., updating Swing components),
the runnable should implement the SwingRunnable
interface and perform this work in
SwingRunnable.swingRun(boolean)
.
The progress monitor component, retrieved via getMonitorComponent()
, can be placed
into a Swing widget. This RunManager will show and hide this progress component as necessary
when runnables are being run.
- See Also:
-
Constructor Summary
ConstructorDescriptionRunManager
(TaskListener listener) RunManager
(String name, Component defaultComponent) RunManager
(String name, Component defaultComponent, TaskListener listener) -
Method Summary
Modifier and TypeMethodDescriptionvoid
A convenience method to cancel the any currently running job and any scheduled jobs.void
dispose()
boolean
void
runLater
(MonitoredRunnable runnable, String taskName, int showProgressDelay) Schedules this runnable to be run after all runnables currently queued.void
runNext
(MonitoredRunnable runnable, String taskName) Allows any currently running runnable to finish, clears any queued runnables, and then queues the given runnable to be run after the current runnable finishes.void
runNext
(MonitoredRunnable runnable, String taskName, int showProgressDelay) Allows any currently running runnable to finish, clears any queued runnables, and then queues the given runnable to be run after the current runnable finishes.void
runNow
(MonitoredRunnable runnable, String taskName) Cancels any currently running runnable, clears any queued runnables, and then runs the given runnable.void
runNow
(MonitoredRunnable runnable, String taskName, int showProgressDelay) Cancels any currently running runnable, clears any queued runnables, and then runs the given runnable.void
showCancelButton
(boolean showCancel) Show the cancel button according to the showCancel parameter.void
showProgressBar
(boolean showProgress) Show the progress bar according to the showProgress parameter.void
showProgressIcon
(boolean showIcon) Show the progress icon according to the showIcon parameter.void
waitForNotBusy
(int maxWaitMillis)
-
Constructor Details
-
RunManager
public RunManager() -
RunManager
-
RunManager
-
RunManager
-
-
Method Details
-
getMonitorComponent
-
dispose
public void dispose() -
cancelAllRunnables
public void cancelAllRunnables()A convenience method to cancel the any currently running job and any scheduled jobs. Note: this method does not block or wait for the currently running job to finish. -
waitForNotBusy
public void waitForNotBusy(int maxWaitMillis) -
runNow
Cancels any currently running runnable, clears any queued runnables, and then runs the given runnable.See the class header for more info.
- Parameters:
runnable
- Runnable to executetaskName
- name of runnable; may be null (this will appear in the progress panel)
-
runNow
Cancels any currently running runnable, clears any queued runnables, and then runs the given runnable.See the class header for more info.
- Parameters:
runnable
- Runnable to executetaskName
- name of runnable; may be null (this will appear in the progress panel)showProgressDelay
- the amount of time (in milliseconds) before showing the progress panel
-
runNext
Allows any currently running runnable to finish, clears any queued runnables, and then queues the given runnable to be run after the current runnable finishes.This call will use the default
delay
of 500.See the class header for more info.
- Parameters:
runnable
- Runnable to executetaskName
- name of runnable; may be null (this will appear in the progress panel)
-
runNext
Allows any currently running runnable to finish, clears any queued runnables, and then queues the given runnable to be run after the current runnable finishes.See the class header for more info.
- Parameters:
runnable
- Runnable to executetaskName
- name of runnable; may be null (this will appear in the progress panel)showProgressDelay
- the amount of time (in milliseconds) before showing the progress panel
-
runLater
Schedules this runnable to be run after all runnables currently queued.This method differs from the
runNow(MonitoredRunnable, String, int)
methods in that it will not cancel any currently running jobs. This allows you to add new jobs to this run manager, which lets them queue up. See header docs for details.- Parameters:
runnable
- The runnable to runtaskName
- The name of the task to runshowProgressDelay
- The amount of time to wait before showing a progress monitor.
-
isInProgress
public boolean isInProgress() -
showCancelButton
public void showCancelButton(boolean showCancel) Show the cancel button according to the showCancel parameter.- Parameters:
showCancel
- true means to show the cancel button
-
showProgressBar
public void showProgressBar(boolean showProgress) Show the progress bar according to the showProgress parameter.- Parameters:
showProgress
- true means to show the progress bar
-
showProgressIcon
public void showProgressIcon(boolean showIcon) Show the progress icon according to the showIcon parameter.- Parameters:
showIcon
- true means to show the progress icon
-