Class MonitoredWorkQueue<T>


  • public class MonitoredWorkQueue<T>
    extends java.lang.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
    • Constructor Summary

      Constructors 
      Constructor Description
      MonitoredWorkQueue​(java.awt.Component parentComponent, java.lang.String title)  
      MonitoredWorkQueue​(java.awt.Component parentComponent, java.lang.String message, java.lang.String title)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void abort()  
      void awaitCompletion()
      Call preferably on AWT thread to await completion or termination of submitted tasks.
      java.lang.String getMessage()  
      int getMillisToPopup()  
      boolean isAborted()
      Should be checked periodically by tasks.
      void onError​(java.lang.Runnable 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.
      void setMessage​(java.lang.String message)  
      void setMillisToPopup​(int millisToPopup)  
      java.util.concurrent.Future<T> submit​(java.util.concurrent.Callable<T> task)
      Submit possibly long running task for execution in the background.
      java.util.concurrent.Future<T> submit​(Task task)
      Submit possibly long running task for execution in the background.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • MonitoredWorkQueue

        public MonitoredWorkQueue​(java.awt.Component parentComponent,
                                  java.lang.String title)
      • MonitoredWorkQueue

        public MonitoredWorkQueue​(java.awt.Component parentComponent,
                                  java.lang.String message,
                                  java.lang.String title)
    • Method Detail

      • submit

        public java.util.concurrent.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.
        Parameters:
        task -
        Returns:
      • submit

        public java.util.concurrent.Future<T> submit​(java.util.concurrent.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.
        Parameters:
        task -
        Returns:
      • onError

        public void onError​(java.lang.Runnable 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.
        Parameters:
        errorHandler -
      • getMessage

        public java.lang.String getMessage()
      • setMessage

        public void setMessage​(java.lang.String message)
      • abort

        public void abort()
      • 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 preferrably throw OperationAbortedException on cancellation
        Returns:
        true if user or any task has cancelled execution