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

Commit

Permalink
feat!: deprecate RetrySettings.isJittered [gax-java] (#1308)
Browse files Browse the repository at this point in the history
* feat!: deprecate RetrySettings.isJittered

* fix: Address comments
  • Loading branch information
miraleung committed Feb 19, 2021
1 parent ee370f6 commit 68644a4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Expand Up @@ -187,7 +187,7 @@ public boolean shouldRetry(TimedAttemptSettings nextAttemptSettings) {

// Injecting Random is not possible here, as Random does not provide nextLong(long bound) method
protected long nextRandomLong(long bound) {
return bound > 0 && globalSettings.isJittered()
return bound > 0 && globalSettings.isJittered() // Jitter check needed for testing purposes.
? ThreadLocalRandom.current().nextLong(bound)
: bound;
}
Expand Down
15 changes: 12 additions & 3 deletions gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java
Expand Up @@ -30,6 +30,7 @@
package com.google.api.gax.retrying;

import com.google.auto.value.AutoValue;
import com.google.common.annotations.VisibleForTesting;
import java.io.Serializable;
import org.threeten.bp.Duration;

Expand Down Expand Up @@ -112,7 +113,11 @@ public abstract class RetrySettings implements Serializable {
* <pre>{@code actualDelay = rand_between(0, min(maxRetryDelay, delay))}</pre>
*
* The default value is {@code true}.
*
* @deprecated Retries always jitter.
*/
@Deprecated
@VisibleForTesting
public abstract boolean isJittered();

/**
Expand Down Expand Up @@ -194,13 +199,17 @@ public abstract static class Builder {
public abstract Builder setMaxAttempts(int maxAttempts);

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

/**
Expand Down

0 comments on commit 68644a4

Please sign in to comment.