-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow RetryOptions to configure HttpResponse and Throwable retry logic (
#38469) Allow for RetryOptions to configure HttpResponse and Throwable retry behaviors
- Loading branch information
1 parent
aae066d
commit 2956906
Showing
8 changed files
with
336 additions
and
19 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
64 changes: 64 additions & 0 deletions
64
...main/java/com/azure/core/implementation/accesshelpers/ExponentialBackoffAccessHelper.java
This file contains 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,64 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
package com.azure.core.implementation.accesshelpers; | ||
|
||
import com.azure.core.http.HttpResponse; | ||
import com.azure.core.http.policy.ExponentialBackoff; | ||
import com.azure.core.http.policy.ExponentialBackoffOptions; | ||
|
||
import java.util.function.Predicate; | ||
|
||
/** | ||
* Class containing helper methods for accessing private members of {@link ExponentialBackoff}. | ||
*/ | ||
public final class ExponentialBackoffAccessHelper { | ||
private static ExponentialBackoffAccessor accessor; | ||
|
||
/** | ||
* Type defining the methods to set the non-public properties of an {@link ExponentialBackoff} instance. | ||
*/ | ||
public interface ExponentialBackoffAccessor { | ||
/** | ||
* Creates an {@link ExponentialBackoff} instance with the passed {@code exponentialBackoffOptions}, | ||
* {@code shouldRetry} and {@code shouldRetryException}. | ||
* | ||
* @param exponentialBackoffOptions The {@link ExponentialBackoffOptions}. | ||
* @param shouldRetry The {@link Predicate} to determine if a response should be retried. | ||
* @param shouldRetryException The {@link Predicate} to determine if a {@link Throwable} should be retried. | ||
* @return The created {@link ExponentialBackoff} instance. | ||
*/ | ||
ExponentialBackoff create(ExponentialBackoffOptions exponentialBackoffOptions, | ||
Predicate<HttpResponse> shouldRetry, Predicate<Throwable> shouldRetryException); | ||
} | ||
|
||
/** | ||
* The method called from {@link ExponentialBackoff} to set it's accessor. | ||
* | ||
* @param exponentialBackoffAccessor The accessor. | ||
*/ | ||
public static void setAccessor(final ExponentialBackoffAccessor exponentialBackoffAccessor) { | ||
accessor = exponentialBackoffAccessor; | ||
} | ||
|
||
/** | ||
* Creates an {@link ExponentialBackoff} instance with the passed {@code exponentialBackoffOptions}, | ||
* {@code shouldRetry} and {@code shouldRetryException}. | ||
* | ||
* @param exponentialBackoffOptions The {@link ExponentialBackoffOptions}. | ||
* @param shouldRetry The {@link Predicate} to determine if a response should be retried. | ||
* @param shouldRetryException The {@link Predicate} to determine if a {@link Throwable} should be retried. | ||
* @return The created {@link ExponentialBackoff} instance. | ||
*/ | ||
public static ExponentialBackoff create(ExponentialBackoffOptions exponentialBackoffOptions, | ||
Predicate<HttpResponse> shouldRetry, Predicate<Throwable> shouldRetryException) { | ||
if (accessor == null) { | ||
new ExponentialBackoff(); | ||
} | ||
|
||
assert accessor != null; | ||
return accessor.create(exponentialBackoffOptions, shouldRetry, shouldRetryException); | ||
} | ||
|
||
private ExponentialBackoffAccessHelper() { | ||
} | ||
} |
Oops, something went wrong.