diff --git a/client/src/main/java/io/split/client/SplitClientConfig.java b/client/src/main/java/io/split/client/SplitClientConfig.java index 7b2ae0e5b..d76bd57b9 100644 --- a/client/src/main/java/io/split/client/SplitClientConfig.java +++ b/client/src/main/java/io/split/client/SplitClientConfig.java @@ -57,6 +57,7 @@ public class SplitClientConfig { private final int _onDemandFetchMaxRetries; private final int _failedAttemptsBeforeLogging; private final boolean _cdnDebugLogging; + private long _validateAfterInactivityInMillis; // Proxy configs private final HttpHost _proxy; @@ -106,7 +107,8 @@ private SplitClientConfig(String endpoint, int onDemandFetchRetryDelayMs, int onDemandFetchMaxRetries, int failedAttemptsBeforeLogging, - boolean cdnDebugLogging) { + boolean cdnDebugLogging, + long validateAfterInactivityInMillis) { _endpoint = endpoint; _eventsEndpoint = eventsEndpoint; _featuresRefreshRate = pollForFeatureChangesEveryNSeconds; @@ -143,6 +145,7 @@ private SplitClientConfig(String endpoint, _onDemandFetchMaxRetries = onDemandFetchMaxRetries; _failedAttemptsBeforeLogging = failedAttemptsBeforeLogging; _cdnDebugLogging = cdnDebugLogging; + _validateAfterInactivityInMillis = validateAfterInactivityInMillis; Properties props = new Properties(); try { @@ -286,6 +289,9 @@ public int get_telemetryRefreshRate() { public boolean cdnDebugLogging() { return _cdnDebugLogging; } + public long validateAfterInactivityInMillis() { + return _validateAfterInactivityInMillis; + } public static final class Builder { @@ -323,11 +329,12 @@ public static final class Builder { private String _authServiceURL = AUTH_ENDPOINT; private String _streamingServiceURL = STREAMING_ENDPOINT; private String _telemetryURl = TELEMETRY_ENDPOINT; - private int _telemetryRefreshRate = 60; + private int _telemetryRefreshRate = 3600; private int _onDemandFetchRetryDelayMs = 50; private final int _onDemandFetchMaxRetries = 10; private final int _failedAttemptsBeforeLogging = 10; private final boolean _cdnDebugLogging = true; + private long _validateAfterInactivityInMillis = 1000; public Builder() { } @@ -719,8 +726,7 @@ public Builder streamingServiceURL(String streamingServiceURL) { return this; } - /** - * Set telemetry service URL. + /** Set telemetry service URL. * @param telemetryURL * @return */ @@ -817,10 +823,15 @@ public SplitClientConfig build() { if (_onDemandFetchRetryDelayMs <= 0) { throw new IllegalStateException("streamingRetryDelay must be > 0"); } + if(_onDemandFetchMaxRetries <= 0) { throw new IllegalStateException("_onDemandFetchMaxRetries must be > 0"); } + if(_telemetryRefreshRate <= 60) { + throw new IllegalStateException("_telemetryRefreshRate must be >= 60"); + } + return new SplitClientConfig( _endpoint, _eventsEndpoint, @@ -857,7 +868,8 @@ public SplitClientConfig build() { _onDemandFetchRetryDelayMs, _onDemandFetchMaxRetries, _failedAttemptsBeforeLogging, - _cdnDebugLogging); + _cdnDebugLogging, + _validateAfterInactivityInMillis); } } } diff --git a/client/src/main/java/io/split/client/SplitFactoryImpl.java b/client/src/main/java/io/split/client/SplitFactoryImpl.java index 1489bafec..eca563c84 100644 --- a/client/src/main/java/io/split/client/SplitFactoryImpl.java +++ b/client/src/main/java/io/split/client/SplitFactoryImpl.java @@ -47,6 +47,7 @@ import org.apache.hc.core5.http.io.SocketConfig; import org.apache.hc.core5.http.ssl.TLS; import org.apache.hc.core5.ssl.SSLContexts; +import org.apache.hc.core5.util.TimeValue; import org.apache.hc.core5.util.Timeout; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -258,6 +259,7 @@ private static CloseableHttpClient buildHttpClient(String apiToken, SplitClientC .setDefaultSocketConfig(SocketConfig.custom() .setSoTimeout(Timeout.ofMilliseconds(config.readTimeout())) .build()) + .setValidateAfterInactivity(TimeValue.ofMilliseconds(config.validateAfterInactivityInMillis())) .build(); cm.setMaxTotal(20); cm.setDefaultMaxPerRoute(20);