Skip to content
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

equivalent of static RetryCondition defaultRetryCondition() #5392

Closed
eternachen opened this issue Jul 11, 2024 · 5 comments
Closed

equivalent of static RetryCondition defaultRetryCondition() #5392

eternachen opened this issue Jul 11, 2024 · 5 comments
Labels
documentation This is a problem with documentation.

Comments

@eternachen
Copy link

Describe the issue

I'm just upgraded to 2.26.16 and I had a RetryCondition defaultRetryCondition()

I have to use RetryStrategy.Builder.html#retryOnException(java.util.function.Predicate)).

Deprecated.
Use instead RetryStrategy.Builder.retryOnException(Predicate).

Is there an equivalent or Predicate for defaultRetryCondition?

Links

https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/core/retry/conditions/RetryCondition.html#defaultRetryCondition()

@eternachen eternachen added documentation This is a problem with documentation. needs-triage This issue or PR still needs to be triaged. labels Jul 11, 2024
@sugmanue
Copy link
Contributor

The equivalent will be to use the static method AwsRetryStrategy.configure (source) to configure a RetryStrategy.Builder<?,?> type. For example:

StandardRetryStrategy.Builder builder = StandardRetryStrategy.builder();
builder = AwsRetryStrategy.configure(builder);
StandardRetryStrategy retryStrategy = builder.build();

Notice that the retry strategies returned by the static methods in AwsRetryStrategy are already configured to retry for AWS retryable errors using that configure method (source), so the example above can be simplified to:

StandardRetryStrategy builder = AwsRetryStrategy.standardRetryStrategy();

Please elaborate on your use case and what you're trying to accomplish if you need a more nuance answer.

@eternachen
Copy link
Author

eternachen commented Jul 12, 2024

Thanks a lot, @sugmanue. It is very helpful.

There are 2 things I am trying

  1. convert custom RetryCondition to Predicate.
    Old Code:
public final CustomRetryCondition implements RetryCondition {
      public boolean shouldRetry(RetryPolicyContext context) {
             SdkException exn = context.exception()...
             // test your condition here
      } 
}

New Code:

Public final CustomRetryPredicate implements Predicate<SdkException> {
      public boolean test(SDKException exn) {
            // test your condition here
      }
}
  1. Convert RetryOnExceptionsCondition.create(Set exns) and RetryOnErrorCodeCondition.create(Set codes) to Predicate
    It would be easier to have some utility class.

@debora-ito debora-ito removed the needs-triage This issue or PR still needs to be triaged. label Jul 12, 2024
@sugmanue
Copy link
Contributor

sugmanue commented Jul 13, 2024

For the first point, what's preventing you from implementing the predicate?

For the second point, you can see how is done by the SDK here which gets called here. Notice that the SDK is designed to be generic and not necessarily tied to AWS, therefore we put the generic logic (including retrying on specific status code on the sdk-core module while the AWS specific error codes are configured in the aws-core module). That's why we have to separated methods to configure retry startegies.

@eternachen
Copy link
Author

Thanks a lot, @sugmanue.

No issues on First point.

For the second point, thanks a lot for your sample code.

Copy link

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation This is a problem with documentation.
Projects
None yet
Development

No branches or pull requests

3 participants