feat(gax): add ResumableUploadStatus and progress tracking support - #14209
feat(gax): add ResumableUploadStatus and progress tracking support#14209whowes wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a progress-tracking mechanism for resumable uploads by adding the ResumableUploadProgressListener interface, the ResumableUploadStatus state snapshot class, and extending ResumableUploadFuture to support registering listeners. Feedback focuses on improving API backward compatibility by providing a default implementation for the single-parameter addProgressListener method, and adding state validation inside the ResumableUploadStatus builder to prevent invalid state configurations.
| /** | ||
| * Registers a listener for progress updates on the direct executor. | ||
| * | ||
| * @param listener the listener to receive progress updates | ||
| */ | ||
| void addProgressListener(ResumableUploadProgressListener listener); |
There was a problem hiding this comment.
To prevent breaking compilation for existing implementors of ResumableUploadFuture and to reduce boilerplate, consider providing a default implementation for the single-parameter addProgressListener method that delegates to the two-parameter overload using a direct executor (e.g., Runnable::run).
/**
* Registers a listener for progress updates on the direct executor.
*
* @param listener the listener to receive progress updates
*/
default void addProgressListener(ResumableUploadProgressListener listener) {
addProgressListener(listener, Runnable::run);
}|
|
||
| public abstract Builder setException(@Nullable Throwable exception); | ||
|
|
||
| public abstract ResumableUploadStatus build(); |
There was a problem hiding this comment.
To ensure the integrity of the ResumableUploadStatus object, consider adding validation to the builder's build() method. For example, bytesUploaded should not be negative, and if totalBytes is known (non-negative), bytesUploaded should not exceed totalBytes.
abstract ResumableUploadStatus autoBuild();
public ResumableUploadStatus build() {
ResumableUploadStatus status = autoBuild();
if (status.getBytesUploaded() < 0) {
throw new IllegalArgumentException("bytesUploaded cannot be negative");
}
if (status.hasTotalBytes() && status.getBytesUploaded() > status.getTotalBytes()) {
throw new IllegalArgumentException("bytesUploaded cannot exceed totalBytes");
}
return status;
}427aa49 to
5fffa4a
Compare
5fffa4a to
b486436
Compare
b486436 to
3963e06
Compare
3963e06 to
e36f121
Compare
e36f121 to
7a3ee93
Compare
7a3ee93 to
5efdc61
Compare
5efdc61 to
16ce2ef
Compare
4b1ddc0 to
9c72e37
Compare
9c72e37 to
e3be23f
Compare
e3be23f to
6da5170
Compare
|
|





Adds
ResumableUploadStatusandResumableUploadProgressListenerto track upload state transitions and byte counts. Also addsgetStatus()andaddProgressListener()toResumableUploadFutureso callers can monitor progress, optionally on a caller-suppliedExecutor.