ProgressListener Interface
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 progress) 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 and Description |
---|---|
abstract void |
handleProgress(long progress)
The callback function invoked as progress is reported. |
Method Details
handleProgress
public abstract 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:
Applies to
Azure SDK for Java
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for