Class MultiProgressMonitor


  • public class MultiProgressMonitor
    extends Object
    Progress reporting interface that multiplexes multiple sub-tasks.

    Output is of the format:

       Task: subA: 1, subB: 75% (3/4) (-)\r
       Task: subA: 2, subB: 75% (3/4), subC: 1 (\)\r
       Task: subA: 2, subB: 100% (4/4), subC: 1 (|)\r
       Task: subA: 4, subB: 100% (4/4), subC: 4, done    \n
     

    Callers should try to keep task and sub-task descriptions short, since the output should fit on one terminal line. (Note that git clients do not accept terminal control characters, so true multi-line progress messages would be impossible.)

    • Field Detail

      • UNKNOWN

        public static final int UNKNOWN
        Constant indicating the total work units cannot be predicted.
        See Also:
        Constant Field Values
    • Constructor Detail

      • MultiProgressMonitor

        public MultiProgressMonitor​(OutputStream out,
                                    String taskName)
        Create a new progress monitor for multiple sub-tasks.
        Parameters:
        out - stream for writing progress messages.
        taskName - name of the overall task.
      • MultiProgressMonitor

        public MultiProgressMonitor​(OutputStream out,
                                    String taskName,
                                    long maxIntervalTime,
                                    TimeUnit maxIntervalUnit)
        Create a new progress monitor for multiple sub-tasks.
        Parameters:
        out - stream for writing progress messages.
        taskName - name of the overall task.
        maxIntervalTime - maximum interval between progress messages.
        maxIntervalUnit - time unit for progress interval.
    • Method Detail

      • waitFor

        public void waitFor​(Future<?> workerFuture,
                            long timeoutTime,
                            TimeUnit timeoutUnit)
                     throws ExecutionException
        Wait for a task managed by a Future.

        Must be called from the main thread, not a worker thread. Once a worker thread calls end(), the future has an additional maxInterval to finish before it is forcefully cancelled and ExecutionException is thrown.

        Parameters:
        workerFuture - a future that returns when worker threads are finished.
        timeoutTime - overall timeout for the task; the future is forcefully cancelled if the task exceeds the timeout. Non-positive values indicate no timeout.
        timeoutUnit - unit for overall task timeout.
        Throws:
        ExecutionException - if this thread or a worker thread was interrupted, the worker was cancelled, or timed out waiting for a worker to call end().
      • beginSubTask

        public MultiProgressMonitor.Task beginSubTask​(String subTask,
                                                      int subTaskWork)
        Begin a sub-task.
        Parameters:
        subTask - sub-task name.
        subTaskWork - total work units in sub-task, or UNKNOWN.
        Returns:
        sub-task handle.
      • end

        public void end()
        End the overall task.

        Must be called from a worker thread.