-
Notifications
You must be signed in to change notification settings - Fork 914
Add progress listener design doc and prototype #1386
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
**Design:** New Feature, **Status:** [In Development](../../../README.md) | ||
|
||
# Project Tenets (unless you know better ones) | ||
|
||
1. Recording progress events should have minimal impact on the application performance. | ||
|
||
2. The supported progress event types should have minimum overlaps with existing execution interceptors. [To discuss] | ||
|
||
3. Progress events and publisher should be extensible. | ||
|
||
# Introduction | ||
|
||
This project provides Progress Listeners feature, which allows customers to track the progress of executions for streaming operations and execute callbacks | ||
on different progress events. | ||
|
||
# Default Progress Event Types | ||
|
||
- Byte Counting Events | ||
|
||
```java | ||
|
||
/** | ||
* Event of the content length to be sent in a request. | ||
*/ | ||
REQUEST_CONTENT_LENGTH_EVENT, | ||
/** | ||
* Event of the content length received in a response. | ||
*/ | ||
RESPONSE_CONTENT_LENGTH_EVENT, | ||
|
||
/** | ||
* Used to indicate the number of bytes to be sent to the services. | ||
*/ | ||
REQUEST_BYTE_TRANSFER_EVENT, | ||
|
||
/** | ||
* Used to indicate the number of bytes received from services. | ||
*/ | ||
RESPONSE_BYTE_TRANSFER_EVENT, | ||
|
||
``` | ||
|
||
- Request/Response Events | ||
|
||
```java | ||
|
||
|
||
//////////////////////////////////////// | ||
// Byte counting progress events | ||
//////////////////////////////////////// | ||
/** | ||
* Used to indicate the request body has been cancelled. | ||
*/ | ||
REQUEST_BODY_CANCEL_EVENT, | ||
|
||
/** | ||
* Used to indicate the request body is complete. | ||
*/ | ||
REQUEST_BODY_COMPLETE_EVENT, | ||
|
||
/** | ||
* Used to indicate the request has been reset. | ||
*/ | ||
REQUEST_BODY_RESET_EVENT, | ||
|
||
RESPONSE_BODY_CANCEL_EVENT, | ||
|
||
RESPONSE_BODY_COMPLETE_EVENT, | ||
|
||
RESPONSE_BODY_RESET_EVENT | ||
|
||
``` | ||
|
||
# Configuration | ||
```java | ||
|
||
ProgressEventListener eventListener = progressEvent -> { | ||
System.out.println(progressEvent); | ||
return CompletableFuture.completedFuture(null); | ||
}; | ||
|
||
S3AsyncClient.builder() | ||
.overrideConfiguration(b -> b.addProgressListener(eventListener)) | ||
//.overrideConfiguration(b -> b.progressListeners(Collections.singletonList(eventListener))) | ||
.build(); | ||
|
||
} | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
package software.amazon.awssdk.core.progress; | ||
|
||
/** | ||
* Listener interface to listen to the progress events. | ||
* | ||
* @see ProgressEvent the progress event | ||
*/ | ||
@SdkPublicApi | ||
@FunctionalInterface | ||
public interface ProgressEventListener { | ||
|
||
/** | ||
* Data notification sent by the {@link ProgressEventPublisher} when an event is available. | ||
* | ||
* <p> | ||
* It is recommended to process the events in a non-blocking way | ||
* | ||
* @param progressEvent the progress event | ||
* @return the complete future | ||
*/ | ||
CompletableFuture<?> onProgressEvent(ProgressEvent progressEvent); | ||
} | ||
|
||
/** | ||
* interface to publish {@link ProgressEvent}s to {@link ProgressEventListener}s. | ||
*/ | ||
@SdkPublicApi | ||
@FunctionalInterface | ||
public interface ProgressEventPublisher { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this different than the listener interface? |
||
|
||
/** | ||
* Publish the progress events | ||
* | ||
* @param progressEvent the event to publish | ||
* @return the future contains the results whether the publish is successful or not. | ||
*/ | ||
CompletableFuture<?> publishProgressEvent(ProgressEvent progressEvent); | ||
} | ||
|
||
/** | ||
* A progress event. Typically this is used to notify a chunk of bytes has been | ||
* transferred. This can also used to notify other types of progress events such as a | ||
* transfer starting, or failing. | ||
* | ||
* @see ProgressEventPublisher | ||
* @see ProgressEventListener | ||
*/ | ||
@SdkPublicApi | ||
public final class ProgressEvent { | ||
|
||
private final ProgressEventType eventType; | ||
private final ProgressEventData eventData; | ||
|
||
private ProgressEvent(ProgressEventType eventType, ProgressEventData eventData) { | ||
this.eventType = eventType; | ||
this.eventData = eventData; | ||
} | ||
|
||
public ProgressEvent(ProgressEventType eventType) { | ||
this(eventType, null); | ||
} | ||
|
||
public static ProgressEvent create(ProgressEventType eventType) { | ||
return new ProgressEvent(eventType); | ||
} | ||
|
||
public static ProgressEvent create(ProgressEventType eventType, ProgressEventData eventData) { | ||
return new ProgressEvent(eventType, eventData); | ||
} | ||
|
||
/** | ||
* @return the event type | ||
*/ | ||
public ProgressEventType eventType() { | ||
return eventType; | ||
} | ||
|
||
/** | ||
* @return the event data | ||
*/ | ||
public Optional<ProgressEventData> eventData() { | ||
return Optional.ofNullable(eventData); | ||
} | ||
} | ||
|
||
/** | ||
* The event data to be sent along within an {@link ProgressEvent}. | ||
*/ | ||
@SdkPublicApi | ||
public interface ProgressEventData { | ||
} | ||
|
||
/** | ||
* Progress Event type | ||
*/ | ||
@SdkPublicApi | ||
public interface ProgressEventType { | ||
} | ||
|
||
/** | ||
* Sdk default progress events. | ||
*/ | ||
@SdkPublicApi | ||
public enum SdkProgressEventType implements ProgressEventType { | ||
|
||
|
||
//////////////////////////////////////// | ||
// Byte counting progress events | ||
//////////////////////////////////////// | ||
|
||
/** | ||
* Event of the content length to be sent in a request. | ||
*/ | ||
REQUEST_CONTENT_LENGTH_EVENT, | ||
/** | ||
* Event of the content length received in a response. | ||
*/ | ||
RESPONSE_CONTENT_LENGTH_EVENT, | ||
|
||
/** | ||
* Used to indicate the number of bytes to be sent to the services. | ||
*/ | ||
REQUEST_BYTE_TRANSFER_EVENT, | ||
|
||
/** | ||
* Used to indicate the number of bytes received from services. | ||
*/ | ||
RESPONSE_BYTE_TRANSFER_EVENT, | ||
|
||
//////////////////////////////////////// | ||
// Request/Response progress events | ||
//////////////////////////////////////// | ||
|
||
/** | ||
* Used to indicate the request body has been cancelled. | ||
*/ | ||
REQUEST_BODY_CANCEL_EVENT, | ||
|
||
/** | ||
* Used to indicate the request body is complete. | ||
*/ | ||
REQUEST_BODY_COMPLETE_EVENT, | ||
|
||
/** | ||
* Used to indicate the request has been reset. | ||
*/ | ||
REQUEST_BODY_RESET_EVENT, | ||
|
||
RESPONSE_BODY_CANCEL_EVENT, | ||
|
||
RESPONSE_BODY_COMPLETE_EVENT, | ||
|
||
RESPONSE_BODY_RESET_EVENT | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe void instead of ?
What are the merits of each?