Class ProgressReporter

java.lang.Object
com.azure.core.util.ProgressReporter

public final class ProgressReporter extends Object
ProgressReporter offers a convenient way to add progress tracking to I/O operations.

The ProgressReporter can be used to track a single operation as well as the progress of complex operations that involve multiple sub-operations. In the latter case ProgressReporter forms a tree where child nodes track the progress of sub-operations and report to the parent which in turn aggregates the total progress. The reporting tree can have arbitrary level of nesting.

Code samples

 /**
  * A simple operation that simulates I/O activity.
  * @param progressReporter The {@link ProgressReporter}.
  */
 public static void simpleOperation(ProgressReporter progressReporter) {
     for (long i = 0; i < 100; i++) {
         // Simulate 100 I/Os with 10 progress.
         progressReporter.reportProgress(10);
     }
 }

 /**
  * A complex operation that simulates I/O activity by invoking multiple {@link #simpleOperation(ProgressReporter)}.
  * @param progressReporter The {@link ProgressReporter}.
  */
 public static void complexOperation(ProgressReporter progressReporter) {
     simpleOperation(progressReporter.createChild());
     simpleOperation(progressReporter.createChild());
     simpleOperation(progressReporter.createChild());
 }

 /**
  * The main method.
  * @param args Program arguments.
  */
 public static void main(String[] args) {
     // Execute simpleOperation
     ProgressReporter simpleOperationProgressReporter = ProgressReporter
         .withProgressListener(progress -> System.out.println("Simple operation progress " + progress));
     simpleOperation(simpleOperationProgressReporter);

     // Execute complexOperation
     ProgressReporter complexOperationProgressReporter = ProgressReporter
         .withProgressListener(progress -> System.out.println("Complex operation progress " + progress));
     complexOperation(complexOperationProgressReporter);
 }