forked from Azure/azure-sdk-for-java
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9c048fc
commit 999fb18
Showing
2 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
...runtime/src/main/java/com/microsoft/azure/ResourceGetExponentialBackoffRetryStrategy.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,48 @@ | ||
/** | ||
* | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
* | ||
*/ | ||
|
||
package com.microsoft.azure; | ||
|
||
import com.microsoft.rest.retry.RetryStrategy; | ||
import okhttp3.Response; | ||
|
||
/** | ||
* A retry strategy with backoff parameters for calculating the exponential | ||
* delay between retries for 404s from GET calls. | ||
*/ | ||
public class ResourceGetExponentialBackoffRetryStrategy extends RetryStrategy { | ||
/** | ||
* Represents the default number of retries. | ||
*/ | ||
private static final int DEFAULT_NUMBER_OF_ATTEMPTS = 3; | ||
|
||
/** | ||
* Creates an instance of the retry strategy. | ||
*/ | ||
public ResourceGetExponentialBackoffRetryStrategy() { | ||
this(null, DEFAULT_FIRST_FAST_RETRY); | ||
} | ||
|
||
/** | ||
* Initializes a new instance of the {@link RetryStrategy} class. | ||
* | ||
* @param name The name of the retry strategy. | ||
* @param firstFastRetry true to immediately retry in the first attempt; otherwise, false. | ||
*/ | ||
private ResourceGetExponentialBackoffRetryStrategy(String name, boolean firstFastRetry) { | ||
super(name, firstFastRetry); | ||
} | ||
|
||
@Override | ||
public boolean shouldRetry(int retryCount, Response response) { | ||
int code = response.code(); | ||
//CHECKSTYLE IGNORE MagicNumber FOR NEXT 2 LINES | ||
return retryCount < DEFAULT_NUMBER_OF_ATTEMPTS | ||
&& code == 404 | ||
&& response.request().method().equalsIgnoreCase("GET"); | ||
} | ||
} |
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