Skip to content
This repository was archived by the owner on May 30, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ dependencies {
compile "com.google.guava:guava:19.0"
compile "joda-time:joda-time:2.9.3"
compile "org.slf4j:slf4j-api:1.7.21"
compile group: "com.launchdarkly", name: "okhttp-eventsource", version: "0.2.1", changing: true
compile group: "com.launchdarkly", name: "okhttp-eventsource", version: "0.2.3", changing: true
compile "redis.clients:jedis:2.8.1"
testCompile "org.easymock:easymock:3.4"
testCompile 'junit:junit:4.12'
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/com/launchdarkly/client/LDConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public final class LDConfig {
private static final long DEFAULT_POLLING_INTERVAL_MILLIS = 1000L;
private static final long DEFAULT_START_WAIT_MILLIS = 5000L;
private static final int DEFAULT_SAMPLING_INTERVAL = 0;
private static final long DEFAULT_RECONNECT_TIME_MILLIS = 1000;
private static final Logger logger = LoggerFactory.getLogger(LDConfig.class);

protected static final LDConfig DEFAULT = new Builder().build();
Expand All @@ -43,6 +44,7 @@ public final class LDConfig {
final long pollingIntervalMillis;
final long startWaitMillis;
final int samplingInterval;
final long reconnectTimeMs;

protected LDConfig(Builder builder) {
this.baseURI = builder.baseURI;
Expand All @@ -64,6 +66,7 @@ protected LDConfig(Builder builder) {
}
this.startWaitMillis = builder.startWaitMillis;
this.samplingInterval = builder.samplingInterval;
this.reconnectTimeMs = builder.reconnectTimeMs;
}

/**
Expand Down Expand Up @@ -95,6 +98,7 @@ public static class Builder {
private FeatureStore featureStore = new InMemoryFeatureStore();
private long startWaitMillis = DEFAULT_START_WAIT_MILLIS;
private int samplingInterval = DEFAULT_SAMPLING_INTERVAL;
private long reconnectTimeMs = DEFAULT_RECONNECT_TIME_MILLIS;

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

/**
* The reconnect base time in milliseconds for the streaming connection. The streaming connection
* uses an exponential backoff algorithm (with jitter) for reconnects, but will start the backoff
* with a value near the value specified here.
*
* @param reconnectTimeMs the reconnect time base value in milliseconds
* @return the builder
*/
public Builder reconnectTimeMs(long reconnectTimeMs) {
this.reconnectTimeMs = reconnectTimeMs;
return this;
}


HttpHost proxyHost() {
if (this.proxyHost == null && this.proxyPort == -1 && this.proxyScheme == null) {
return null;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/launchdarkly/client/StreamProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public void onError(Throwable throwable) {

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

es.start();
Expand Down