Skip to content
This repository was archived by the owner on May 30, 2024. It is now read-only.

Commit 80166b3

Browse files
authored
Merge pull request #76 from launchdarkly/jko/backoff
Bump EventSource library, and make reconnect times configurable
2 parents a27c8b4 + 1621acc commit 80166b3

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ dependencies {
3232
compile "com.google.guava:guava:19.0"
3333
compile "joda-time:joda-time:2.9.3"
3434
compile "org.slf4j:slf4j-api:1.7.21"
35-
compile group: "com.launchdarkly", name: "okhttp-eventsource", version: "0.2.1", changing: true
35+
compile group: "com.launchdarkly", name: "okhttp-eventsource", version: "0.2.3", changing: true
3636
compile "redis.clients:jedis:2.8.1"
3737
testCompile "org.easymock:easymock:3.4"
3838
testCompile 'junit:junit:4.12'

src/main/java/com/launchdarkly/client/LDConfig.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public final class LDConfig {
2424
private static final long DEFAULT_POLLING_INTERVAL_MILLIS = 1000L;
2525
private static final long DEFAULT_START_WAIT_MILLIS = 5000L;
2626
private static final int DEFAULT_SAMPLING_INTERVAL = 0;
27+
private static final long DEFAULT_RECONNECT_TIME_MILLIS = 1000;
2728
private static final Logger logger = LoggerFactory.getLogger(LDConfig.class);
2829

2930
protected static final LDConfig DEFAULT = new Builder().build();
@@ -43,6 +44,7 @@ public final class LDConfig {
4344
final long pollingIntervalMillis;
4445
final long startWaitMillis;
4546
final int samplingInterval;
47+
final long reconnectTimeMs;
4648

4749
protected LDConfig(Builder builder) {
4850
this.baseURI = builder.baseURI;
@@ -64,6 +66,7 @@ protected LDConfig(Builder builder) {
6466
}
6567
this.startWaitMillis = builder.startWaitMillis;
6668
this.samplingInterval = builder.samplingInterval;
69+
this.reconnectTimeMs = builder.reconnectTimeMs;
6770
}
6871

6972
/**
@@ -95,6 +98,7 @@ public static class Builder {
9598
private FeatureStore featureStore = new InMemoryFeatureStore();
9699
private long startWaitMillis = DEFAULT_START_WAIT_MILLIS;
97100
private int samplingInterval = DEFAULT_SAMPLING_INTERVAL;
101+
private long reconnectTimeMs = DEFAULT_RECONNECT_TIME_MILLIS;
98102

99103
/**
100104
* Creates a builder with all configuration parameters set to the default
@@ -341,6 +345,20 @@ public Builder samplingInterval(int samplingInterval) {
341345
return this;
342346
}
343347

348+
/**
349+
* The reconnect base time in milliseconds for the streaming connection. The streaming connection
350+
* uses an exponential backoff algorithm (with jitter) for reconnects, but will start the backoff
351+
* with a value near the value specified here.
352+
*
353+
* @param reconnectTimeMs the reconnect time base value in milliseconds
354+
* @return the builder
355+
*/
356+
public Builder reconnectTimeMs(long reconnectTimeMs) {
357+
this.reconnectTimeMs = reconnectTimeMs;
358+
return this;
359+
}
360+
361+
344362
HttpHost proxyHost() {
345363
if (this.proxyHost == null && this.proxyPort == -1 && this.proxyScheme == null) {
346364
return null;

src/main/java/com/launchdarkly/client/StreamProcessor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ public void onError(Throwable throwable) {
109109

110110
es = new EventSource.Builder(handler, URI.create(config.streamURI.toASCIIString() + "/flags"))
111111
.headers(headers)
112+
.reconnectTimeMs(config.reconnectTimeMs)
112113
.build();
113114

114115
es.start();

0 commit comments

Comments
 (0)