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:
progress
- The total progress at the current point of time.
Applies to
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應