Class Task


  • public class Task
    extends Object
    Keeps track of progress associated with an execution of progressible code. Tasks should not be updated by the code itself, but rather updated via Progress.update().
    Author:
    Gabriel Selzer
    • Constructor Detail

      • Task

        public Task​(Object progressible,
                    String description)
    • Method Detail

      • complete

        public void complete()
        Records the completion of this Task
      • defineTotal

        public void defineTotal​(long elements)
        Defines the total progress of this Task.

        This method must be called before update(long) or progress() are called, as otherwise total progress cannot be defined.

        Under the hood, this method calls defineTotal(long, long)

        Parameters:
        elements - the number of discrete packets of computation.
      • defineTotal

        public void defineTotal​(long elements,
                                long subTasks)
        Defines the total progress of this Task.

        This method must be called before update(long) or progress() are called, as otherwise total progress cannot be defined.

        Parameters:
        elements - the number of discrete packets of computation.
        subTasks - the number of times subtasks are called upon within the task. This is not the same as the number of subtasks used (as one subtask may run multiple times).
      • isComplete

        public boolean isComplete()
        Returns true iff this Task is complete.
        Returns:
        true iff this Task is complete.
      • progress

        public double progress()
        Calculates and returns the progress of the associated progressible Object. If the total progress is defined using defineTotal(long, long), then this method will return a double within the range [0, 1]. If the progress is not defined, then this task will return 0 until complete() is called; after that call this method will return 1..
        Returns:
        the progress
      • setStatus

        public void setStatus​(String status)
        Used by the progressible Object to set the status of its computation. This method should not used by any code not part of the progressible Object
        Parameters:
        status - the status of the progressible Object
      • status

        public String status()
        The status of the progressible Object
        Returns:
        the status
      • description

        public String description()
        The id of the progressible Object
        Returns:
        the id
      • progressible

        public Object progressible()
        Gets the progressible Object contributing to this Task's progress.
        Returns:
        the progressible Object
      • parent

        protected Task parent()
        Returns the parent Task of this Task.
        Returns:
        the parent Task, or null if this Task has no parent
      • isSubTask

        public boolean isSubTask()