Class MonitoredWorkQueue<T>

java.lang.Object
net.jalbum.util.MonitoredWorkQueue<T>

public class MonitoredWorkQueue<T> extends Object
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 Details

    • title

      protected String title
    • dialog

      protected JDialog dialog
    • focusOwner

      protected Component focusOwner
  • Constructor Details

    • MonitoredWorkQueue

      public MonitoredWorkQueue(Component parentComponent, String title)
    • MonitoredWorkQueue

      public MonitoredWorkQueue(Component parentComponent, String message, String title)
  • Method Details

    • getMaximum

      public Integer getMaximum()
    • setMaximum

      public void setMaximum(Integer maximum)
    • setValue

      public void setValue(int value)
    • getParallelism

      public int getParallelism()
    • setParallelism

      public void setParallelism(int parallelism)
    • submit

      public Future<T> submit(Task task)
      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

      public Future<T> submit(Callable<T> task)
      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

      public void onError(Consumer<Exception> errorHandler)
      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

      public String getMessage()
    • setMessage

      public void setMessage(String message)
    • 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

      public MonitoredWorkQueue onDialogOpening(Consumer<Dialog> 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