-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #955 from sac-fork/refactor/incremental-backoff-ji…
…tter Fix incremental backoff jitter
- Loading branch information
Showing
10 changed files
with
267 additions
and
230 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
38 changes: 38 additions & 0 deletions
38
lib/src/main/java/io/ably/lib/util/ReconnectionStrategy.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,38 @@ | ||
package io.ably.lib.util; | ||
|
||
public class ReconnectionStrategy { | ||
|
||
/** | ||
* Spec: RTB1a | ||
* | ||
* @param count The retry count | ||
* @return The backoff coefficient | ||
*/ | ||
private static float getBackoffCoefficient(int count) { | ||
return Math.min((count + 2) / 3f, 2f); | ||
} | ||
|
||
/** | ||
* Spec: RTB1b | ||
* | ||
* @return The jitter coefficient | ||
*/ | ||
private static double getJitterCoefficient() { | ||
return 1 - Math.random() * 0.2; | ||
} | ||
|
||
/** | ||
* Spec: RTB1 | ||
* | ||
* @param initialTimeout The initial timeout value | ||
* @param retryAttempt integer indicating retryAttempt | ||
* @return RetryTimeout value for given timeout and retryAttempt. | ||
* If x is the value returned then, | ||
* Upper bound = min((retryAttempt + 2) / 3, 2) * initialTimeout, | ||
* Lower bound = 0.8 * Upper bound, | ||
* Lower bound < x < Upper bound | ||
*/ | ||
public static int getRetryTime(long initialTimeout, int retryAttempt) { | ||
return Double.valueOf(initialTimeout * getJitterCoefficient() * getBackoffCoefficient(retryAttempt)).intValue(); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.