Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prepare 1.11.1 release #49

Merged
merged 41 commits into from
May 27, 2020
Merged
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
26dc142
add time threshold for backoff reset
eli-darkly Dec 11, 2018
881473f
Merge branch 'master' into eb/ch15975/backoff-reset
eli-darkly Dec 11, 2018
ca0865d
allow endpoint to be specified as either URI or HttpUrl
eli-darkly Dec 11, 2018
a35c7e6
add @since
eli-darkly Dec 11, 2018
8e4363b
add interface for customizing requests
eli-darkly Dec 11, 2018
54f11e0
Merge pull request #18 from launchdarkly/eb/ch15975/backoff-reset
eli-darkly Dec 13, 2018
7b104a0
Merge pull request #20 from launchdarkly/eb/ch28150/customize-request
eli-darkly Dec 13, 2018
32f80d8
Merge branch 'master' into eb/ch28144/okhttp-url
eli-darkly Dec 13, 2018
1bd8145
Merge pull request #19 from launchdarkly/eb/ch28144/okhttp-url
eli-darkly Dec 13, 2018
52d1732
javadoc fixes
eli-darkly Dec 13, 2018
e82ee5f
add changelog for past releases
eli-darkly Dec 13, 2018
5917b43
Merge branch 'master' of github.com:launchdarkly/okhttp-eventsource
eli-darkly Dec 13, 2018
d6a189b
remove JSR305
eli-darkly Mar 19, 2019
9674ef7
Merge pull request #21 from launchdarkly/eb/ch34379/annotations
eli-darkly Mar 20, 2019
ef15c12
Merge branch 'master' of github.com:launchdarkly/okhttp-eventsource
eli-darkly Mar 21, 2019
6d498fe
Merge branch 'master' of github.com:launchdarkly/okhttp-eventsource
eli-darkly Aug 1, 2019
890eada
replace SSL-specific config method with general-purpose HTTP config m…
eli-darkly Aug 1, 2019
7ba89f4
make helper method static
eli-darkly Aug 1, 2019
4acfb7e
Merge pull request #22 from launchdarkly/eb/ch44325/http-custom-config
eli-darkly Aug 1, 2019
95e4c37
add end-to-end EventSource tests
eli-darkly Aug 1, 2019
c93f4f0
spacing
eli-darkly Aug 1, 2019
0460bfe
Merge pull request #23 from launchdarkly/eb/ch28292/http-tests
eli-darkly Aug 1, 2019
5cd1b37
Merge branch 'master' of github.com:launchdarkly/okhttp-eventsource
eli-darkly Aug 1, 2019
64a67fc
Merge branch 'master' of github.com:launchdarkly/okhttp-eventsource
eli-darkly Aug 22, 2019
9f05a9a
omit default header value if there's a custom value
eli-darkly Oct 12, 2019
2e5354b
avoid trailing period in logger name
eli-darkly Oct 12, 2019
9f83742
Merge pull request #25 from launchdarkly/eb/ch52604/logger-name
eli-darkly Oct 18, 2019
3dd72a6
Merge pull request #24 from launchdarkly/eb/ch52602/override-header
eli-darkly Oct 18, 2019
b77ea93
merge from public after release
LaunchDarklyCI Oct 18, 2019
9874518
add 1.x branch
eli-darkly Jan 18, 2020
bf2f83c
javadoc fixes
eli-darkly Jan 18, 2020
685e03f
Merge branch '1.x' of github.com:launchdarkly/okhttp-eventsource into…
eli-darkly Mar 14, 2020
c6d5b46
bump OkHttp version to latest Java 7-compatible version
eli-darkly Mar 20, 2020
2c2ca19
Merge pull request #30 from launchdarkly/eb/ch70366/okhttp-update
eli-darkly Mar 20, 2020
e5c3b3d
merge from public after release
LaunchDarklyCI Mar 20, 2020
a7e19ed
Merge branch '1.x' of github.com:launchdarkly/okhttp-eventsource into…
eli-darkly Mar 20, 2020
48b0692
add ability to force a stream restart; improve tests so we can test t…
eli-darkly Mar 26, 2020
b96e581
merge from public after release
LaunchDarklyCI Mar 30, 2020
3f431f1
Merge branch '1.x' of github.com:launchdarkly/okhttp-eventsource into…
eli-darkly Apr 6, 2020
ae5e25f
fix jitter calculation when upper bound is a power of 2
eli-darkly May 27, 2020
1cbcf8e
Merge pull request #38 from launchdarkly/eb/ch77825/random-jitter-calc
eli-darkly May 27, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 4 additions & 19 deletions src/main/java/com/launchdarkly/eventsource/EventSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -375,32 +375,17 @@ private void maybeWaitWithBackoff(int reconnectAttempts) {
}

long backoffWithJitter(int reconnectAttempts) {
long jitterVal = Math.min(maxReconnectTimeMs, reconnectTimeMs * pow2(reconnectAttempts));
return jitterVal / 2 + nextLong(jitter, jitterVal) / 2;
long maxTimeLong = Math.min(maxReconnectTimeMs, reconnectTimeMs * pow2(reconnectAttempts));
// 2^31 milliseconds is much longer than any reconnect time we would reasonably want to use, so we can pin this to int
int maxTimeInt = maxTimeLong > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int)maxTimeLong;
return maxTimeInt / 2 + jitter.nextInt(maxTimeInt) / 2;
}

// Returns 2**k, or Integer.MAX_VALUE if 2**k would overflow
private int pow2(int k) {
return (k < Integer.SIZE - 1) ? (1 << k) : Integer.MAX_VALUE;
}

// Adapted from http://stackoverflow.com/questions/2546078/java-random-long-number-in-0-x-n-range
// Since ThreadLocalRandom.current().nextLong(n) requires Android 5
private long nextLong(Random rand, long bound) {
if (bound <= 0) {
throw new IllegalArgumentException("bound must be positive");
}

long r = rand.nextLong() & Long.MAX_VALUE;
long m = bound - 1L;
if ((bound & m) == 0) { // i.e., bound is a power of 2
r = (bound * r) >> (Long.SIZE - 1);
} else {
for (long u = r; u - (r = u % bound) + m < 0L; u = rand.nextLong() & Long.MAX_VALUE) ;
}
return r;
}

private static Headers addDefaultHeaders(Headers custom) {
Headers.Builder builder = new Headers.Builder();

Expand Down