Skip to content

Commit 859a697

Browse files
Merge pull request #224 from splitio/connect-ready-sync-manager
Connect ready sync manager
2 parents 70486f0 + 78540db commit 859a697

33 files changed

+314
-945
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
import org.slf4j.Logger;
77
import org.slf4j.LoggerFactory;
88

9+
import java.util.HashMap;
10+
import java.util.Map;
11+
912
public class ApiKeyCounter {
1013

1114
private static final Logger _log = LoggerFactory.getLogger(ApiKeyCounter.class);
@@ -63,4 +66,18 @@ boolean isApiKeyPresent(String apiKey) {
6366
int getCount(String apiKey) {
6467
return USED_API_KEYS.count(apiKey);
6568
}
69+
70+
public Map<String, Long> getFactoryInstances() {
71+
Map<String, Long> factoryInstances = new HashMap<>();
72+
for (String factory :USED_API_KEYS) {
73+
factoryInstances.putIfAbsent(factory, new Long(getCount(factory)));
74+
}
75+
76+
return factoryInstances;
77+
}
78+
79+
@VisibleForTesting
80+
void clearApiKeys() {
81+
USED_API_KEYS.clear();
82+
}
6683
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ public LocalhostSplitFactory(String directory, String file) throws IOException {
5656
SplitCache splitCache = new InMemoryCacheImp();
5757
SDKReadinessGates sdkReadinessGates = new SDKReadinessGates();
5858

59-
sdkReadinessGates.splitsAreReady();
6059
_cacheUpdaterService = new CacheUpdaterService(splitCache);
6160
_cacheUpdaterService.updateCache(splitAndKeyToTreatment);
61+
sdkReadinessGates.sdkInternalReady();
6262
_client = new SplitClientImpl(this, splitCache,
6363
new ImpressionsManager.NoOpImpressionsManager(), new NoopEventClient(),
6464
SplitClientConfig.builder().setBlockUntilReadyTimeout(1).build(), sdkReadinessGates, new EvaluatorImp(splitCache), new NoopTelemetryStorage(), new NoopTelemetryStorage());

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import io.split.inputValidation.KeyValidator;
1616
import io.split.inputValidation.SplitNameValidator;
1717
import io.split.inputValidation.TrafficTypeValidator;
18-
import io.split.telemetry.domain.enums.LastSynchronizationRecordsEnum;
1918
import io.split.telemetry.domain.enums.MethodEnum;
2019
import io.split.telemetry.storage.TelemetryConfigProducer;
2120
import io.split.telemetry.storage.TelemetryEvaluationProducer;
@@ -138,7 +137,7 @@ public void blockUntilReady() throws TimeoutException, InterruptedException {
138137
if (_config.blockUntilReady() <= 0) {
139138
throw new IllegalArgumentException("setBlockUntilReadyTimeout must be positive but in config was: " + _config.blockUntilReady());
140139
}
141-
if (!_gates.isSDKReady(_config.blockUntilReady())) {
140+
if (!_gates.waitUntilInternalReady(_config.blockUntilReady())) {
142141
throw new TimeoutException("SDK was not ready in " + _config.blockUntilReady()+ " milliseconds");
143142
}
144143
_log.debug(String.format("Split SDK ready in %d ms", (System.currentTimeMillis() - startTime)));
@@ -188,7 +187,7 @@ private boolean track(Event event) {
188187
private SplitResult getTreatmentWithConfigInternal(String method, String matchingKey, String bucketingKey, String split, Map<String, Object> attributes, MethodEnum methodEnum) {
189188
long initTime = System.currentTimeMillis();
190189
try {
191-
if(!_gates.isSDKReadyNow()){
190+
if(!_gates.isSDKReady()){
192191
_log.warn(method + ": the SDK is not ready, results may be incorrect. Make sure to wait for SDK readiness before using this method");
193192
_telemetryConfigProducer.recordNonReadyUsage();
194193
}
@@ -215,7 +214,7 @@ private SplitResult getTreatmentWithConfigInternal(String method, String matchin
215214

216215
EvaluatorImp.TreatmentLabelAndChangeNumber result = _evaluator.evaluateFeature(matchingKey, bucketingKey, split, attributes);
217216

218-
if (result.treatment.equals(Treatments.CONTROL) && result.label.equals(Labels.DEFINITION_NOT_FOUND) && _gates.isSDKReadyNow()) {
217+
if (result.treatment.equals(Treatments.CONTROL) && result.label.equals(Labels.DEFINITION_NOT_FOUND) && _gates.isSDKReady()) {
219218
_log.warn(
220219
"getTreatment: you passed \"" + split + "\" that does not exist in this environment, " +
221220
"please double check what Splits exist in the web console.");

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import io.split.client.interceptors.GzipDecoderResponseInterceptor;
99
import io.split.client.interceptors.GzipEncoderRequestInterceptor;
1010
import io.split.client.interceptors.SdkMetadataInterceptorFilter;
11-
import io.split.client.metrics.HttpMetrics;
1211
import io.split.cache.InMemoryCacheImp;
1312
import io.split.cache.SplitCache;
1413
import io.split.engine.evaluator.Evaluator;
@@ -124,8 +123,8 @@ public SplitFactoryImpl(String apiToken, SplitClientConfig config) throws URISyn
124123
// Cache Initialisations
125124
_segmentCache = new SegmentCacheInMemoryImpl();
126125
_splitCache = new InMemoryCacheImp();
127-
_telemetrySynchronizer = new SynchronizerMemory(_httpclient, URI.create(config.get_telemetryURL()), _telemetryStorage, _splitCache, _segmentCache, _telemetryStorage);
128-
_telemetrySyncTask = new TelemetrySyncTask(config.get_telemetryRefreshRate(), _telemetrySynchronizer);
126+
_telemetrySynchronizer = new SynchronizerMemory(_httpclient, URI.create(config.get_telemetryURL()), _telemetryStorage, _splitCache, _segmentCache, _telemetryStorage, _startTime);
127+
129128

130129
// Segments
131130
_segmentSynchronizationTaskImp = buildSegments(config);
@@ -142,9 +141,7 @@ public SplitFactoryImpl(String apiToken, SplitClientConfig config) throws URISyn
142141
// EventClient
143142
_eventClient = EventClientImpl.create(_httpclient, _eventsRootTarget, config.eventsQueueSize(), config.eventFlushIntervalInMillis(), config.waitBeforeShutdown(), _telemetryStorage);
144143

145-
// SyncManager
146-
_syncManager = SyncManagerImp.build(config.streamingEnabled(), _splitSynchronizationTask, _splitFetcher, _segmentSynchronizationTaskImp, _splitCache, config.authServiceURL(), _httpclient, config.streamingServiceURL(), config.authRetryBackoffBase(), buildSSEdHttpClient(apiToken, config), _segmentCache, config.streamingRetryDelay(), _gates, _telemetryStorage);
147-
_syncManager.start();
144+
_telemetrySyncTask = new TelemetrySyncTask(config.get_telemetryRefreshRate(), _telemetrySynchronizer);
148145

149146
// Evaluator
150147
_evaluator = new EvaluatorImp(_splitCache);
@@ -155,6 +152,12 @@ public SplitFactoryImpl(String apiToken, SplitClientConfig config) throws URISyn
155152
// SplitManager
156153
_manager = new SplitManagerImpl(_splitCache, config, _gates, _telemetryStorage);
157154

155+
// SyncManager
156+
_syncManager = SyncManagerImp.build(config.streamingEnabled(), _splitSynchronizationTask, _splitFetcher, _segmentSynchronizationTaskImp, _splitCache,
157+
config.authServiceURL(), _httpclient, config.streamingServiceURL(), config.authRetryBackoffBase(), buildSSEdHttpClient(apiToken, config),
158+
_segmentCache, config.streamingRetryDelay(), _gates, _telemetryStorage, _telemetrySynchronizer,config);
159+
_syncManager.start();
160+
158161
// DestroyOnShutDown
159162
if (config.destroyOnShutDown()) {
160163
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
@@ -313,7 +316,7 @@ private SplitFetcher buildSplitFetcher() throws URISyntaxException {
313316
SplitChangeFetcher splitChangeFetcher = HttpSplitChangeFetcher.create(_httpclient, _rootTarget, _telemetryStorage);
314317
SplitParser splitParser = new SplitParser(_segmentSynchronizationTaskImp, _segmentCache);
315318

316-
return new SplitFetcherImp(splitChangeFetcher, splitParser, _gates, _splitCache, _telemetryStorage);
319+
return new SplitFetcherImp(splitChangeFetcher, splitParser, _splitCache, _telemetryStorage);
317320
}
318321

319322
private ImpressionsManagerImpl buildImpressionsManager(SplitClientConfig config) throws URISyntaxException {

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import io.split.cache.SplitCache;
77
import io.split.engine.experiments.ParsedSplit;
88
import io.split.inputValidation.SplitNameValidator;
9-
import io.split.telemetry.domain.enums.MethodEnum;
109
import io.split.telemetry.storage.TelemetryConfigProducer;
1110
import org.slf4j.Logger;
1211
import org.slf4j.LoggerFactory;
@@ -43,7 +42,7 @@ public SplitManagerImpl(SplitCache splitCache,
4342

4443
@Override
4544
public List<SplitView> splits() {
46-
if (!_gates.isSDKReadyNow()) { {
45+
if (!_gates.isSDKReady()) { {
4746
_log.warn("splits: the SDK is not ready, results may be incorrect. Make sure to wait for SDK readiness before using this method");
4847
_telemetryConfigProducer.recordNonReadyUsage();
4948
}}
@@ -58,7 +57,7 @@ public List<SplitView> splits() {
5857

5958
@Override
6059
public SplitView split(String featureName) {
61-
if (!_gates.isSDKReadyNow()) { {
60+
if (!_gates.isSDKReady()) { {
6261
_log.warn("split: the SDK is not ready, results may be incorrect. Make sure to wait for SDK readiness before using this method");
6362
_telemetryConfigProducer.recordNonReadyUsage();
6463
}}
@@ -70,7 +69,7 @@ public SplitView split(String featureName) {
7069

7170
ParsedSplit parsedSplit = _splitCache.get(featureName);
7271
if (parsedSplit == null) {
73-
if (_gates.isSDKReadyNow()) {
72+
if (_gates.isSDKReady()) {
7473
_log.warn("split: you passed \"" + featureName + "\" that does not exist in this environment, " +
7574
"please double check what Splits exist in the web console.");
7675
}
@@ -82,7 +81,7 @@ public SplitView split(String featureName) {
8281

8382
@Override
8483
public List<String> splitNames() {
85-
if (!_gates.isSDKReadyNow()) { {
84+
if (!_gates.isSDKReady()) { {
8685
_log.warn("splitNames: the SDK is not ready, results may be incorrect. Make sure to wait for SDK readiness before using this method");
8786
_telemetryConfigProducer.recordNonReadyUsage();
8887
}}
@@ -100,7 +99,7 @@ public void blockUntilReady() throws TimeoutException, InterruptedException {
10099
if (_config.blockUntilReady() <= 0) {
101100
throw new IllegalArgumentException("setBlockUntilReadyTimeout must be positive but in config was: " + _config.blockUntilReady());
102101
}
103-
if (!_gates.isSDKReady(_config.blockUntilReady())) {
102+
if (!_gates.waitUntilInternalReady(_config.blockUntilReady())) {
104103
_telemetryConfigProducer.recordBURTimeout();
105104
throw new TimeoutException("SDK was not ready in " + _config.blockUntilReady()+ " milliseconds");
106105
}

client/src/main/java/io/split/client/metrics/BinarySearchLatencyTracker.java

Lines changed: 0 additions & 131 deletions
This file was deleted.

client/src/main/java/io/split/client/metrics/DTOMetrics.java

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)