Package net.jalbum.util
Class MonitoredWorkQueue<T>
java.lang.Object
net.jalbum.util.MonitoredWorkQueue<T>
Manage long running tasks that can be aborted by user. This class will pop up
a progress dialog if the invoked task takes more than 500ms to complete
(timing can be adjusted)
It's usually the responsibility of the task to check the isAborted() state
regularly and throw an OperationAbortedException to abort if user has clicked
the abort button on the dialog, but tasks that perform IO operations
sensitive to being interrupted should also respond, You can also submit a
series of, in themselves, short lived tasks to the queue and then call
awaitCompletion(). In such cases, there is no need for each submitted task to
check the isAborted() state or to respond to interruption. As soon as the
user aborts the dialog, then all not-yet executed tasks will be discarded.
- Since:
- 16.3
-
Field Summary
-
Constructor Summary
ConstructorDescriptionMonitoredWorkQueue
(Component parentComponent, String title) MonitoredWorkQueue
(Component parentComponent, String message, String title) -
Method Summary
Modifier and TypeMethodDescriptionvoid
abort()
void
Call preferably on AWT thread to await completion or termination of submitted tasks.protected void
Override to be informed when dialog is closedprotected void
Override to be informed when dialog is openingint
int
boolean
Should be checked periodically by tasks.boolean
onDialogOpening
(Consumer<Dialog> onDialogOpening) void
By default, the 1:st error (Exception thrown) generates an error dialog but this behavior can be overridden by this error handler In any case, errors also cause abortion of the queue.void
setAllowInterrupt
(boolean allowInterrupt) void
setMaximum
(Integer maximum) void
setMessage
(String message) void
setMillisToPopup
(int millisToPopup) void
setParallelism
(int parallelism) void
setValue
(int value) Submit possibly long running task for execution in the background.Submit possibly long running task for execution in the background.
-
Field Details
-
title
-
dialog
-
focusOwner
-
-
Constructor Details
-
MonitoredWorkQueue
-
MonitoredWorkQueue
-
-
Method Details
-
getMaximum
-
setMaximum
-
setValue
public void setValue(int value) -
getParallelism
public int getParallelism() -
setParallelism
public void setParallelism(int parallelism) -
submit
Submit possibly long running task for execution in the background. Task should periodically check isAborted() and throw an OperationAbortedException if it is true. This will terminate the current task and any pending tasks. -
submit
Submit possibly long running task for execution in the background. Task should periodically check isAborted() and throw an OperationAbortedException if it is true. This will terminate the current task and any pending tasks. -
onError
By default, the 1:st error (Exception thrown) generates an error dialog but this behavior can be overridden by this error handler In any case, errors also cause abortion of the queue. -
getMessage
-
setMessage
-
abort
public void abort() -
isAllowInterrupt
public boolean isAllowInterrupt()- Returns:
- true if abort interrupts. Defaults to true
- Since:
- 19
-
setAllowInterrupt
public void setAllowInterrupt(boolean allowInterrupt) - Parameters:
allowInterrupt
- whether abort() should interrupt or not- Since:
- 19
-
dialogOpening
protected void dialogOpening()Override to be informed when dialog is opening- Since:
- 19
-
onDialogOpening
-
dialogClosed
protected void dialogClosed()Override to be informed when dialog is closed- Since:
- 19
-
awaitCompletion
public void awaitCompletion()Call preferably on AWT thread to await completion or termination of submitted tasks. Pops up a progress dialogue after millisToPopup has passed, which allows user to cancel currently running and scheduled tasks -
getMillisToPopup
public int getMillisToPopup() -
setMillisToPopup
public void setMillisToPopup(int millisToPopup) -
isAborted
public boolean isAborted()Should be checked periodically by tasks. Runnable should return or preferably throw OperationAbortedException on cancellation- Returns:
- true if user or any task has cancelled execution
-