Skip to content
This repository was archived by the owner on Sep 26, 2023. It is now read-only.

Commit 68644a4

Browse files
authored
feat!: deprecate RetrySettings.isJittered [gax-java] (#1308)
* feat!: deprecate RetrySettings.isJittered * fix: Address comments
1 parent ee370f6 commit 68644a4

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

‎gax/src/main/java/com/google/api/gax/retrying/ExponentialRetryAlgorithm.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public boolean shouldRetry(TimedAttemptSettings nextAttemptSettings) {
187187

188188
// Injecting Random is not possible here, as Random does not provide nextLong(long bound) method
189189
protected long nextRandomLong(long bound) {
190-
return bound > 0 && globalSettings.isJittered()
190+
return bound > 0 && globalSettings.isJittered() // Jitter check needed for testing purposes.
191191
? ThreadLocalRandom.current().nextLong(bound)
192192
: bound;
193193
}

‎gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
package com.google.api.gax.retrying;
3131

3232
import com.google.auto.value.AutoValue;
33+
import com.google.common.annotations.VisibleForTesting;
3334
import java.io.Serializable;
3435
import org.threeten.bp.Duration;
3536

@@ -112,7 +113,11 @@ public abstract class RetrySettings implements Serializable {
112113
* <pre>{@code actualDelay = rand_between(0, min(maxRetryDelay, delay))}</pre>
113114
*
114115
* The default value is {@code true}.
116+
*
117+
* @deprecated Retries always jitter.
115118
*/
119+
@Deprecated
120+
@VisibleForTesting
116121
public abstract boolean isJittered();
117122

118123
/**
@@ -194,13 +199,17 @@ public abstract static class Builder {
194199
public abstract Builder setMaxAttempts(int maxAttempts);
195200

196201
/**
197-
* Jitter determines if the delay time should be randomized. In most cases, if jitter is set to
198-
* {@code true} the actual delay time is calculated in the following way:
202+
* Jitter determines if the delay time should be randomized. If jitter is set to {@code true}
203+
* the actual delay time is calculated in the following way:
199204
*
200205
* <pre>{@code actualDelay = rand_between(0, min(maxRetryDelay, exponentialDelay))}</pre>
201206
*
202-
* The default value is {@code true}.
207+
* The default value is {@code true}, and this method will be a no-op soon.
208+
*
209+
* @deprecated Retries always jitter.
203210
*/
211+
@Deprecated
212+
@VisibleForTesting
204213
public abstract Builder setJittered(boolean jittered);
205214

206215
/**

0 commit comments

Comments
 (0)