Class ProgressTask

  • All Implemented Interfaces:
    Runnable, Future<Map<String,​Object>>, Progress

    public class ProgressTask
    extends Object
    implements Runnable, Progress
    An implementation of the Progress interface.
    Author:
    gdavis, Jody
    • Constructor Summary

      Constructors 
      Constructor Description
      ProgressTask​(Process process, Map<String,​Object> input)
      Creates a ProgressTask that will execute the given Process when run.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean cancel​(boolean mayInterruptIfRunning)  
      protected void done()
      This protected method is invoked when this process transitions to state isDone (whether normally or via cancellation).
      Map<String,​Object> get()  
      Map<String,​Object> get​(long timeout, TimeUnit unit)  
      float getProgress()
      Amount of work completed.
      boolean isCancelled()  
      boolean isDone()  
      void run()
      Sets this ProgressTask to the result of the computation unless it has been canceled.
      protected boolean runAndReset()
      Executes the process without setting its result, and then resets this ProgressTask to its initial state, failing to do so if the computation encounters an exception or is canceled.
      protected void set​(Map<String,​Object> value)
      Sets the result of this ProgressTask to the given value unless this ProgressTask has already been set or has been canceled.
      protected void setException​(Throwable t)
      Causes this ProgressTask to report an ExecutionException with the given throwable as its cause, unless this ProgressTask has already been set or has been canceled.
      • Methods inherited from class Object

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

      • ProgressTask

        public ProgressTask​(Process process,
                            Map<String,​Object> input)
        Creates a ProgressTask that will execute the given Process when run.
        Parameters:
        process - the process to execute
        input - the inputs to use when executing the process
        Throws:
        NullPointerException - if process is null
    • Method Detail

      • getProgress

        public float getProgress()
        Description copied from interface: Progress
        Amount of work completed.
        Specified by:
        getProgress in interface Progress
        Returns:
        Percent completed, or WORKING if amount of work is unknown.
      • isCancelled

        public boolean isCancelled()
        Specified by:
        isCancelled in interface Future<Map<String,​Object>>
      • isDone

        public boolean isDone()
        Specified by:
        isDone in interface Future<Map<String,​Object>>
      • cancel

        public boolean cancel​(boolean mayInterruptIfRunning)
        Specified by:
        cancel in interface Future<Map<String,​Object>>
      • get

        public Map<String,​Object> get()
                                     throws InterruptedException,
                                            ExecutionException
        Specified by:
        get in interface Future<Map<String,​Object>>
        Throws:
        InterruptedException
        ExecutionException
      • get

        public Map<String,​Object> get​(long timeout,
                                            TimeUnit unit)
                                     throws InterruptedException,
                                            ExecutionException,
                                            TimeoutException
        Specified by:
        get in interface Future<Map<String,​Object>>
        Throws:
        InterruptedException
        ExecutionException
        TimeoutException
      • done

        protected void done()
        This protected method is invoked when this process transitions to state isDone (whether normally or via cancellation). The default implementation does nothing. Subclasses may override this method to invoke completion callbacks. You can query status inside the implementation of this method to determine whether this task has been canceled.
      • set

        protected void set​(Map<String,​Object> value)
        Sets the result of this ProgressTask to the given value unless this ProgressTask has already been set or has been canceled.
        Parameters:
        value - the value to set
      • setException

        protected void setException​(Throwable t)
        Causes this ProgressTask to report an ExecutionException with the given throwable as its cause, unless this ProgressTask has already been set or has been canceled.
        Parameters:
        t - the cause of failure.
      • run

        public void run()
        Sets this ProgressTask to the result of the computation unless it has been canceled.
        Specified by:
        run in interface Runnable
      • runAndReset

        protected boolean runAndReset()
        Executes the process without setting its result, and then resets this ProgressTask to its initial state, failing to do so if the computation encounters an exception or is canceled. This is designed for use with processes that execute more than once.
        Returns:
        true if successfully run and reset