Skip to content

Commit 67a9a2a

Browse files
Merge pull request #229 from splitio/revalidate-stale-connections
add setting to revalidate stale connections
2 parents 4b8d6a6 + 712b08a commit 67a9a2a

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

client/src/main/java/io/split/client/SplitClientConfig.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public class SplitClientConfig {
5757
private final int _onDemandFetchMaxRetries;
5858
private final int _failedAttemptsBeforeLogging;
5959
private final boolean _cdnDebugLogging;
60+
private long _validateAfterInactivityInMillis;
6061

6162
// Proxy configs
6263
private final HttpHost _proxy;
@@ -106,7 +107,8 @@ private SplitClientConfig(String endpoint,
106107
int onDemandFetchRetryDelayMs,
107108
int onDemandFetchMaxRetries,
108109
int failedAttemptsBeforeLogging,
109-
boolean cdnDebugLogging) {
110+
boolean cdnDebugLogging,
111+
long validateAfterInactivityInMillis) {
110112
_endpoint = endpoint;
111113
_eventsEndpoint = eventsEndpoint;
112114
_featuresRefreshRate = pollForFeatureChangesEveryNSeconds;
@@ -143,6 +145,7 @@ private SplitClientConfig(String endpoint,
143145
_onDemandFetchMaxRetries = onDemandFetchMaxRetries;
144146
_failedAttemptsBeforeLogging = failedAttemptsBeforeLogging;
145147
_cdnDebugLogging = cdnDebugLogging;
148+
_validateAfterInactivityInMillis = validateAfterInactivityInMillis;
146149

147150
Properties props = new Properties();
148151
try {
@@ -286,6 +289,9 @@ public int get_telemetryRefreshRate() {
286289

287290
public boolean cdnDebugLogging() { return _cdnDebugLogging; }
288291

292+
public long validateAfterInactivityInMillis() {
293+
return _validateAfterInactivityInMillis;
294+
}
289295

290296
public static final class Builder {
291297

@@ -323,11 +329,12 @@ public static final class Builder {
323329
private String _authServiceURL = AUTH_ENDPOINT;
324330
private String _streamingServiceURL = STREAMING_ENDPOINT;
325331
private String _telemetryURl = TELEMETRY_ENDPOINT;
326-
private int _telemetryRefreshRate = 60;
332+
private int _telemetryRefreshRate = 3600;
327333
private int _onDemandFetchRetryDelayMs = 50;
328334
private final int _onDemandFetchMaxRetries = 10;
329335
private final int _failedAttemptsBeforeLogging = 10;
330336
private final boolean _cdnDebugLogging = true;
337+
private long _validateAfterInactivityInMillis = 1000;
331338

332339
public Builder() {
333340
}
@@ -719,8 +726,7 @@ public Builder streamingServiceURL(String streamingServiceURL) {
719726
return this;
720727
}
721728

722-
/**
723-
* Set telemetry service URL.
729+
/** Set telemetry service URL.
724730
* @param telemetryURL
725731
* @return
726732
*/
@@ -817,10 +823,15 @@ public SplitClientConfig build() {
817823
if (_onDemandFetchRetryDelayMs <= 0) {
818824
throw new IllegalStateException("streamingRetryDelay must be > 0");
819825
}
826+
820827
if(_onDemandFetchMaxRetries <= 0) {
821828
throw new IllegalStateException("_onDemandFetchMaxRetries must be > 0");
822829
}
823830

831+
if(_telemetryRefreshRate <= 60) {
832+
throw new IllegalStateException("_telemetryRefreshRate must be >= 60");
833+
}
834+
824835
return new SplitClientConfig(
825836
_endpoint,
826837
_eventsEndpoint,
@@ -857,7 +868,8 @@ public SplitClientConfig build() {
857868
_onDemandFetchRetryDelayMs,
858869
_onDemandFetchMaxRetries,
859870
_failedAttemptsBeforeLogging,
860-
_cdnDebugLogging);
871+
_cdnDebugLogging,
872+
_validateAfterInactivityInMillis);
861873
}
862874
}
863875
}

client/src/main/java/io/split/client/SplitFactoryImpl.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import org.apache.hc.core5.http.io.SocketConfig;
4848
import org.apache.hc.core5.http.ssl.TLS;
4949
import org.apache.hc.core5.ssl.SSLContexts;
50+
import org.apache.hc.core5.util.TimeValue;
5051
import org.apache.hc.core5.util.Timeout;
5152
import org.slf4j.Logger;
5253
import org.slf4j.LoggerFactory;
@@ -258,6 +259,7 @@ private static CloseableHttpClient buildHttpClient(String apiToken, SplitClientC
258259
.setDefaultSocketConfig(SocketConfig.custom()
259260
.setSoTimeout(Timeout.ofMilliseconds(config.readTimeout()))
260261
.build())
262+
.setValidateAfterInactivity(TimeValue.ofMilliseconds(config.validateAfterInactivityInMillis()))
261263
.build();
262264
cm.setMaxTotal(20);
263265
cm.setDefaultMaxPerRoute(20);

0 commit comments

Comments
 (0)