Class ParallelProgressManager

java.lang.Object
org.pepsoft.util.ParallelProgressManager

public class ParallelProgressManager extends Object
A manager of parallel progress receivers, which reports to one parent progress receiver, combining the progress values and managing the reporting of exceptions or task completion.
  1. Instantiate it with a parent progress receiver, and a task count (if known). Note: the parent progress receiver should be thread safe and not make assumptions about which threads its methods will be invoked from!
  2. Invoke createProgressReceiver() as many times as needed. Note: if the manager has not been created with a task count you cannot invoke this method any more after the first task has started!
  3. Start the tasks in background threads and invoke join() on the manager to wait for all tasks to complete (defined as either invoking ProgressReceiver.done() or ProgressReceiver.exceptionThrown(Throwable) on their progress receivers).

If a task invokes ProgressReceiver.exceptionThrown(Throwable) it will be reported to the parent progress receiver, and all subsequent invocations on their progress receivers by any other tasks will result in an ProgressReceiver.OperationCancelled exception being thrown. If any more exceptions are reported these are not reported to the parent progress receiver (instead they are logged using the java.util logging framework). Also, if an exception has been reported, ProgressReceiver.done() will not subsequently be invoked on the parent progress receiver.

If no exceptions are reported, ProgressReceiver.done() will be invoked on the parent progress receiver after the last task has invoked it on its sub progress receiver.

All invocations on ProgressReceiver.setMessage(String) are passed through unaltered to the parent progress receiver.

If the parent progress receiver throws an OperationCancelled exception at any time, it is stored and rethrown to every task whenever they next invoke a method (that declares it) on their sub progress receivers. It is immediately rethrown to the calling task.

  • Constructor Details

    • ParallelProgressManager

      public ParallelProgressManager(ProgressReceiver progressReceiver)
    • ParallelProgressManager

      public ParallelProgressManager(ProgressReceiver progressReceiver, int taskCount)
  • Method Details