Skip to content

Commit 0101f00

Browse files
committed
add setting to revalidate stale connections
1 parent 5f84978 commit 0101f00

File tree

6 files changed

+35
-10
lines changed

6 files changed

+35
-10
lines changed

client/CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
CHANGES
22

3+
4.1.7 (Apr 15, 2021)
4+
- add validateAfterInactivityInMillis to config to help with stale connection handling
5+
36
4.1.6 (Apr 15, 2021)
47
-Updated log level and message in some messages.
58

client/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>io.split.client</groupId>
77
<artifactId>java-client-parent</artifactId>
8-
<version>4.1.6</version>
8+
<version>4.1.7-rc1</version>
99
</parent>
1010
<artifactId>java-client</artifactId>
1111
<packaging>jar</packaging>
@@ -171,7 +171,7 @@
171171
<groupId>org.slf4j</groupId>
172172
<artifactId>slf4j-log4j12</artifactId>
173173
<version>1.7.21</version>
174-
<scope>test</scope>
174+
<!-- <scope>test</scope>-->
175175
</dependency>
176176
<dependency>
177177
<groupId>org.glassfish.jersey.media</groupId>

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public class SplitClientConfig {
4646
private final int _streamingReconnectBackoffBase;
4747
private final String _authServiceURL;
4848
private final String _streamingServiceURL;
49+
private long _validateAfterInactivityInMillis;
4950

5051
// Proxy configs
5152
private final HttpHost _proxy;
@@ -89,7 +90,8 @@ private SplitClientConfig(String endpoint,
8990
int authRetryBackoffBase,
9091
int streamingReconnectBackoffBase,
9192
String authServiceURL,
92-
String streamingServiceURL) {
93+
String streamingServiceURL,
94+
long validateAfterInactivityInMillis) {
9395
_endpoint = endpoint;
9496
_eventsEndpoint = eventsEndpoint;
9597
_featuresRefreshRate = pollForFeatureChangesEveryNSeconds;
@@ -120,6 +122,7 @@ private SplitClientConfig(String endpoint,
120122
_streamingReconnectBackoffBase = streamingReconnectBackoffBase;
121123
_authServiceURL = authServiceURL;
122124
_streamingServiceURL = streamingServiceURL;
125+
_validateAfterInactivityInMillis = validateAfterInactivityInMillis;
123126

124127
Properties props = new Properties();
125128
try {
@@ -248,6 +251,10 @@ public String streamingServiceURL() {
248251
return _streamingServiceURL;
249252
}
250253

254+
public long validateAfterInactivityInMillis() {
255+
return _validateAfterInactivityInMillis;
256+
}
257+
251258
public static final class Builder {
252259

253260
private String _endpoint = "https://sdk.split.io";
@@ -283,6 +290,7 @@ public static final class Builder {
283290
private int _streamingReconnectBackoffBase = 1;
284291
private String _authServiceURL = "https://auth.split.io/api/auth";
285292
private String _streamingServiceURL = "https://streaming.split.io/sse";
293+
private long _validateAfterInactivityInMillis = -1;
286294

287295
public Builder() {
288296
}
@@ -674,6 +682,16 @@ public Builder streamingServiceURL(String streamingServiceURL) {
674682
return this;
675683
}
676684

685+
/**
686+
* Set the time after which period of inactivity a connection must be revalidated .
687+
* @param validateAfterInactivityInMillis
688+
* @return
689+
*/
690+
public Builder validateAfterInactivityInMillis(long validateAfterInactivityInMillis) {
691+
_validateAfterInactivityInMillis = validateAfterInactivityInMillis;
692+
return this;
693+
}
694+
677695
public SplitClientConfig build() {
678696
if (_featuresRefreshRate < 5 ) {
679697
throw new IllegalArgumentException("featuresRefreshRate must be >= 5: " + _featuresRefreshRate);
@@ -774,7 +792,8 @@ public SplitClientConfig build() {
774792
_authRetryBackoffBase,
775793
_streamingReconnectBackoffBase,
776794
_authServiceURL,
777-
_streamingServiceURL);
795+
_streamingServiceURL,
796+
_validateAfterInactivityInMillis);
778797
}
779798
}
780799
}

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import org.apache.hc.core5.http.io.SocketConfig;
4444
import org.apache.hc.core5.http.ssl.TLS;
4545
import org.apache.hc.core5.ssl.SSLContexts;
46+
import org.apache.hc.core5.util.TimeValue;
4647
import org.apache.hc.core5.util.Timeout;
4748
import org.slf4j.Logger;
4849
import org.slf4j.LoggerFactory;
@@ -210,7 +211,7 @@ private static CloseableHttpClient buildHttpClient(String apiToken, SplitClientC
210211

211212
SSLConnectionSocketFactory sslSocketFactory = SSLConnectionSocketFactoryBuilder.create()
212213
.setSslContext(SSLContexts.createSystemDefault())
213-
.setTlsVersions(TLS.V_1_1, TLS.V_1_2)
214+
.setTlsVersions(TLS.V_1_2)
214215
.build();
215216

216217
RequestConfig requestConfig = RequestConfig.custom()
@@ -223,9 +224,11 @@ private static CloseableHttpClient buildHttpClient(String apiToken, SplitClientC
223224
.setDefaultSocketConfig(SocketConfig.custom()
224225
.setSoTimeout(Timeout.ofMilliseconds(config.readTimeout()))
225226
.build())
227+
.setValidateAfterInactivity(TimeValue.ofMilliseconds(config.validateAfterInactivityInMillis()))
228+
.setConnectionTimeToLive(TimeValue.ofMilliseconds(2000))
226229
.build();
227-
cm.setMaxTotal(20);
228-
cm.setDefaultMaxPerRoute(20);
230+
cm.setMaxTotal(2);
231+
cm.setDefaultMaxPerRoute(2);
229232

230233
HttpClientBuilder httpClientbuilder = HttpClients.custom()
231234
.setConnectionManager(cm)
@@ -249,7 +252,7 @@ private static CloseableHttpClient buildSSEdHttpClient(SplitClientConfig config)
249252

250253
SSLConnectionSocketFactory sslSocketFactory = SSLConnectionSocketFactoryBuilder.create()
251254
.setSslContext(SSLContexts.createSystemDefault())
252-
.setTlsVersions(TLS.V_1_1, TLS.V_1_2)
255+
.setTlsVersions(TLS.V_1_2)
253256
.build();
254257

255258
PoolingHttpClientConnectionManager cm = PoolingHttpClientConnectionManagerBuilder.create()

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>io.split.client</groupId>
66
<artifactId>java-client-parent</artifactId>
7-
<version>4.1.6</version>
7+
<version>4.1.7-rc1</version>
88
<dependencyManagement>
99
<dependencies>
1010
<dependency>

testing/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>io.split.client</groupId>
88
<artifactId>java-client-parent</artifactId>
9-
<version>4.1.6</version>
9+
<version>4.1.7-rc1</version>
1010
</parent>
1111

1212
<artifactId>java-client-testing</artifactId>

0 commit comments

Comments
 (0)