Interface ProgressListener

All Known Subinterfaces:
ProgressReceiver, ProgressReceiver
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface ProgressListener
A ProgressListener is an interface that can be used to listen to the progress of the I/O transfers. The handleProgress(long) method will be called periodically with the total progress accumulated at the given point of time.

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);
 }
 
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    handleProgress(long progress)
    The callback function invoked as progress is reported.
  • Method Details

    • handleProgress

      void handleProgress(long progress)
      The callback function invoked as progress is reported.

      The callback can be called concurrently from multiple threads if reporting spans across multiple requests. The implementor must not perform thread blocking operations in the handler code.

      Parameters:
      progress - The total progress at the current point of time.