-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathSplitClientConfig.java
More file actions
1264 lines (1113 loc) · 44.2 KB
/
SplitClientConfig.java
File metadata and controls
1264 lines (1113 loc) · 44.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package io.split.client;
import io.split.client.dtos.ProxyMTLSAuth;
import io.split.client.impressions.ImpressionListener;
import io.split.client.impressions.ImpressionsManager;
import io.split.client.utils.FileTypeEnum;
import io.split.integrations.IntegrationsConfig;
import io.split.service.CustomHttpModule;
import io.split.storages.enums.OperationMode;
import io.split.storages.enums.StorageMode;
import org.apache.hc.core5.http.HttpHost;
import pluggable.CustomStorageWrapper;
import java.io.IOException;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Properties;
import java.util.concurrent.ThreadFactory;
import java.io.InputStream;
import static io.split.inputValidation.FlagSetsValidator.cleanup;
/**
* Configurations for the SplitClient.
*
* @author adil
*/
public class SplitClientConfig {
public static final String LOCALHOST_DEFAULT_FILE = "split.yaml";
public static final String SDK_ENDPOINT = "https://sdk.split.io";
public static final String EVENTS_ENDPOINT = "https://events.split.io";
public static final String AUTH_ENDPOINT = "https://auth.split.io/api/v2/auth";
public static final String STREAMING_ENDPOINT = "https://streaming.split.io/sse";
public static final String TELEMETRY_ENDPOINT = "https://telemetry.split.io/api/v1";
public static class HttpScheme {
private HttpScheme() {
throw new IllegalStateException("Utility class");
}
public static final String HTTP = "http";
public static final String HTTPS = "https";
}
private final String _endpoint;
private final String _eventsEndpoint;
private final int _featuresRefreshRate;
private final int _segmentsRefreshRate;
private final int _impressionsRefreshRate;
private final int _impressionsQueueSize;
private final ImpressionsManager.Mode _impressionsMode;
private final int _metricsRefreshRate;
private final int _connectionTimeout;
private final int _readTimeout;
private final int _numThreadsForSegmentFetch;
private final boolean _debugEnabled;
private final boolean _labelsEnabled;
private final boolean _ipAddressEnabled;
private final boolean _localhostRefreshEnabled;
private final int _ready;
private final int _waitBeforeShutdown;
private final int _eventsQueueSize;
private final long _eventSendIntervalInMillis;
private final int _maxStringLength;
private final boolean _destroyOnShutDown;
private final String _splitFile;
private final FileTypeEnum _fileType;
private final InputStream _inputStream;
private final String _segmentDirectory;
private final IntegrationsConfig _integrationsConfig;
private final boolean _streamingEnabled;
private final int _authRetryBackoffBase;
private final int _streamingReconnectBackoffBase;
private final String _authServiceURL;
private final String _streamingServiceURL;
private final String _telemetryURL;
private final int _telemetryRefreshRate;
private final int _onDemandFetchRetryDelayMs;
private final int _onDemandFetchMaxRetries;
private final int _failedAttemptsBeforeLogging;
private final int _uniqueKeysRefreshRateInMemory;
private final int _uniqueKeysRefreshRateRedis;
private static int _filterUniqueKeysRefreshRate;
private final OperationMode _operationMode;
private long _validateAfterInactivityInMillis;
private final long _startingSyncCallBackoffBaseMs;
private final CustomStorageWrapper _customStorageWrapper;
private final StorageMode _storageMode;
private final ThreadFactory _threadFactory;
// Proxy configs
private final HttpHost _proxy;
private final String _proxyUsername;
private final String _proxyPassword;
private final ProxyCredentialsProvider _proxyCredentialsProvider;
private final ProxyMTLSAuth _proxyMtlsAuth;
// To be set during startup
public static String splitSdkVersion;
private final long _lastSeenCacheSize;
private final HashSet<String> _flagSetsFilter;
private final int _invalidSets;
private final CustomHeaderDecorator _customHeaderDecorator;
private final CustomHttpModule _alternativeHTTPModule;
public static Builder builder() {
return new Builder();
}
private SplitClientConfig(String endpoint,
String eventsEndpoint,
int pollForFeatureChangesEveryNSeconds,
int segmentsRefreshRate,
int impressionsRefreshRate,
int impressionsQueueSize,
ImpressionsManager.Mode impressionsMode,
int metricsRefreshRate,
int connectionTimeout,
int readTimeout,
int numThreadsForSegmentFetch,
int ready,
boolean debugEnabled,
boolean labelsEnabled,
boolean ipAddressEnabled,
boolean localhostRefreshEnabled,
int waitBeforeShutdown,
HttpHost proxy,
String proxyUsername,
String proxyPassword,
ProxyCredentialsProvider proxyCredentialsProvider,
ProxyMTLSAuth proxyMtlsAuth,
int eventsQueueSize,
long eventSendIntervalInMillis,
int maxStringLength,
boolean destroyOnShutDown,
String splitFile,
FileTypeEnum fileType,
InputStream inputStream,
String segmentDirectory,
IntegrationsConfig integrationsConfig,
boolean streamingEnabled,
int authRetryBackoffBase,
int streamingReconnectBackoffBase,
String authServiceURL,
String streamingServiceURL,
String telemetryURL,
int telemetryRefreshRate,
int onDemandFetchRetryDelayMs,
int onDemandFetchMaxRetries,
int failedAttemptsBeforeLogging,
OperationMode operationMode,
long validateAfterInactivityInMillis,
long startingSyncCallBackoffBaseMs,
CustomStorageWrapper customStorageWrapper,
StorageMode storageMode,
int uniqueKeysRefreshRateInMemory,
int uniqueKeysRefreshRateRedis,
int filterUniqueKeysRefreshRate,
long lastSeenCacheSize,
ThreadFactory threadFactory,
HashSet<String> flagSetsFilter,
int invalidSets,
CustomHeaderDecorator customHeaderDecorator,
CustomHttpModule alternativeHTTPModule) {
_endpoint = endpoint;
_eventsEndpoint = eventsEndpoint;
_featuresRefreshRate = pollForFeatureChangesEveryNSeconds;
_segmentsRefreshRate = segmentsRefreshRate;
_impressionsRefreshRate = impressionsRefreshRate;
_impressionsQueueSize = impressionsQueueSize;
_impressionsMode = impressionsMode;
_metricsRefreshRate = metricsRefreshRate;
_connectionTimeout = connectionTimeout;
_readTimeout = readTimeout;
_numThreadsForSegmentFetch = numThreadsForSegmentFetch;
_ready = ready;
_debugEnabled = debugEnabled;
_labelsEnabled = labelsEnabled;
_ipAddressEnabled = ipAddressEnabled;
_localhostRefreshEnabled = localhostRefreshEnabled;
_waitBeforeShutdown = waitBeforeShutdown;
_proxy = proxy;
_proxyUsername = proxyUsername;
_proxyPassword = proxyPassword;
_proxyCredentialsProvider = proxyCredentialsProvider;
_proxyMtlsAuth = proxyMtlsAuth;
_eventsQueueSize = eventsQueueSize;
_eventSendIntervalInMillis = eventSendIntervalInMillis;
_maxStringLength = maxStringLength;
_destroyOnShutDown = destroyOnShutDown;
_splitFile = splitFile;
_fileType = fileType;
_inputStream = inputStream;
_segmentDirectory = segmentDirectory;
_integrationsConfig = integrationsConfig;
_streamingEnabled = streamingEnabled;
_authRetryBackoffBase = authRetryBackoffBase;
_streamingReconnectBackoffBase = streamingReconnectBackoffBase;
_authServiceURL = authServiceURL;
_streamingServiceURL = streamingServiceURL;
_telemetryURL = telemetryURL;
_telemetryRefreshRate = telemetryRefreshRate;
_uniqueKeysRefreshRateInMemory = uniqueKeysRefreshRateInMemory;
_uniqueKeysRefreshRateRedis = uniqueKeysRefreshRateRedis;
_filterUniqueKeysRefreshRate = filterUniqueKeysRefreshRate;
_onDemandFetchRetryDelayMs = onDemandFetchRetryDelayMs;
_onDemandFetchMaxRetries = onDemandFetchMaxRetries;
_failedAttemptsBeforeLogging = failedAttemptsBeforeLogging;
_operationMode = operationMode;
_storageMode = storageMode;
_validateAfterInactivityInMillis = validateAfterInactivityInMillis;
_startingSyncCallBackoffBaseMs = startingSyncCallBackoffBaseMs;
_customStorageWrapper = customStorageWrapper;
_lastSeenCacheSize = lastSeenCacheSize;
_threadFactory = threadFactory;
_flagSetsFilter = flagSetsFilter;
_invalidSets = invalidSets;
_customHeaderDecorator = customHeaderDecorator;
_alternativeHTTPModule = alternativeHTTPModule;
Properties props = new Properties();
try {
props.load(this.getClass().getClassLoader().getResourceAsStream("splitversion.properties"));
} catch (IOException e) {
throw new IllegalStateException("cannot find client version in classpath", e);
}
splitSdkVersion = "undefined";
if (props.getProperty("sdk.version") != null) {
splitSdkVersion = "java-" + props.getProperty("sdk.version");
}
}
public String endpoint() {
return _endpoint;
}
public String eventsEndpoint() {
return _eventsEndpoint;
}
public int featuresRefreshRate() {
return _featuresRefreshRate;
}
public int segmentsRefreshRate() {
return _segmentsRefreshRate;
}
public int numThreadsForSegmentFetch() {
return _numThreadsForSegmentFetch;
}
public int impressionsRefreshRate() {
return _impressionsRefreshRate;
}
public int uniqueKeysRefreshRateInMemory() {
return _uniqueKeysRefreshRateInMemory;
}
public int uniqueKeysRefreshRateRedis() {
return _uniqueKeysRefreshRateRedis;
}
public static int filterUniqueKeysRefreshRate() {
return _filterUniqueKeysRefreshRate;
}
public int impressionsQueueSize() {
return _impressionsQueueSize;
}
public ImpressionsManager.Mode impressionsMode() { return _impressionsMode; }
public int metricsRefreshRate() {
return _metricsRefreshRate;
}
public int connectionTimeout() {
return _connectionTimeout;
}
public int readTimeout() {
return _readTimeout;
}
public boolean debugEnabled() {
return _debugEnabled;
}
public boolean labelsEnabled() { return _labelsEnabled;}
public boolean ipAddressEnabled() { return _ipAddressEnabled; }
public boolean localhostRefreshEnabled() {
return _localhostRefreshEnabled;
}
public int blockUntilReady() {
return _ready;
}
public int waitBeforeShutdown() {
return _waitBeforeShutdown;
}
public HttpHost proxy() {
return _proxy;
}
public String proxyUsername() {
return _proxyUsername;
}
public String proxyPassword() {
return _proxyPassword;
}
public ProxyCredentialsProvider proxyCredentialsProvider() {
return _proxyCredentialsProvider;
}
public ProxyMTLSAuth proxyMTLSAuth() {
return _proxyMtlsAuth;
}
public long eventSendIntervalInMillis() {
return _eventSendIntervalInMillis;
}
public int eventsQueueSize() {
return _eventsQueueSize;
}
public int maxStringLength() {
return _maxStringLength;
}
public boolean destroyOnShutDown() {
return _destroyOnShutDown;
}
public String splitFile() {
return _splitFile;
}
public FileTypeEnum fileType() {
return _fileType;
}
public InputStream inputStream(){
return _inputStream;
}
public String segmentDirectory() {
return _segmentDirectory;
}
public IntegrationsConfig integrationsConfig() {
return _integrationsConfig;
}
public boolean streamingEnabled() {
return _streamingEnabled;
}
public int authRetryBackoffBase() {
return _authRetryBackoffBase;
}
public int streamingReconnectBackoffBase() {
return _streamingReconnectBackoffBase;
}
public String authServiceURL() {
return _authServiceURL;
}
public String streamingServiceURL() {
return _streamingServiceURL;
}
public String telemetryURL() {
return _telemetryURL;
}
/**
* @deprecated As of release 4.X.X, replaced by {@link #getTelemetryRefreshRate()} } //todo update version
**/
@Deprecated
public int get_telemetryRefreshRate() {
return _telemetryRefreshRate;
}
public int getTelemetryRefreshRate() {
return _telemetryRefreshRate;
}
public int streamingRetryDelay() {return _onDemandFetchRetryDelayMs;}
public int streamingFetchMaxRetries() {return _onDemandFetchMaxRetries;}
public int failedAttemptsBeforeLogging() {return _failedAttemptsBeforeLogging;}
public OperationMode operationMode() { return _operationMode;}
public long validateAfterInactivityInMillis() {
return _validateAfterInactivityInMillis;
}
public long startingSyncCallBackoffBaseMs(){ return _startingSyncCallBackoffBaseMs;}
public CustomStorageWrapper customStorageWrapper() {
return _customStorageWrapper;
}
public StorageMode storageMode() { return _storageMode;}
public long getLastSeenCacheSize() {
return _lastSeenCacheSize;
}
public ThreadFactory getThreadFactory() {
return _threadFactory;
}
public HashSet<String> getSetsFilter() {
return _flagSetsFilter;
}
public int getInvalidSets() {
return _invalidSets;
}
public CustomHeaderDecorator customHeaderDecorator() {
return _customHeaderDecorator;
}
public boolean isSdkEndpointOverridden() {
return !_endpoint.equals(SDK_ENDPOINT);
}
public CustomHttpModule alternativeHTTPModule() { return _alternativeHTTPModule; }
public static final class Builder {
private String _endpoint = SDK_ENDPOINT;
private boolean _endpointSet = false;
private String _eventsEndpoint = EVENTS_ENDPOINT;
private boolean _eventsEndpointSet = false;
private int _featuresRefreshRate = 60;
private int _segmentsRefreshRate = 60;
private int _impressionsRefreshRate = -1; // use -1 to identify lack of a user submitted value & handle in build()
private int _impressionsQueueSize = 30000;
private ImpressionsManager.Mode _impressionsMode = ImpressionsManager.Mode.OPTIMIZED;
private int _connectionTimeout = 15000;
private int _readTimeout = 15000;
private int _numThreadsForSegmentFetch = 10;
private boolean _debugEnabled = false;
private int _ready = -1; // -1 means no blocking
private int _metricsRefreshRate = 60;
private boolean _labelsEnabled = true;
private boolean _ipAddressEnabled = true;
private boolean _localhostRefreshEnable = false;
private int _waitBeforeShutdown = 5000;
private String _proxyHost = "localhost";
private int _proxyPort = -1;
private String _proxyScheme = HttpScheme.HTTP;
private String _proxyUsername;
private String _proxyPassword;
private ProxyCredentialsProvider _proxyCredentialsProvider;
private ProxyMTLSAuth _proxyMtlsAuth;
private int _eventsQueueSize = 500;
private long _eventSendIntervalInMillis = 30 * (long)1000;
private int _maxStringLength = 250;
private boolean _destroyOnShutDown = true;
private String _splitFile = null;
private FileTypeEnum _fileType = null;
private InputStream _inputStream = null;
private String _segmentDirectory = null;
private IntegrationsConfig _integrationsConfig = null;
private boolean _streamingEnabled = true;
private int _authRetryBackoffBase = 1;
private int _streamingReconnectBackoffBase = 1;
private String _authServiceURL = AUTH_ENDPOINT;
private String _streamingServiceURL = STREAMING_ENDPOINT;
private String _telemetryURl = TELEMETRY_ENDPOINT;
private int _telemetryRefreshRate = 600;
private final int _uniqueKeysRefreshRateInMemory = 900;
private final int _uniqueKeysRefreshRateRedis = 300;
private final int _filterUniqueKeysRefreshRate = 86400;
private int _onDemandFetchRetryDelayMs = 50;
private final int _onDemandFetchMaxRetries = 10;
private final int _failedAttemptsBeforeLogging = 10;
private OperationMode _operationMode = OperationMode.STANDALONE;
private long _validateAfterInactivityInMillis = 1000;
private static final long STARTING_SYNC_CALL_BACKOFF_BASE_MS = 1000; //backoff base starting at 1 seconds
private CustomStorageWrapper _customStorageWrapper;
private StorageMode _storageMode = StorageMode.MEMORY;
private final long _lastSeenCacheSize = 500000;
private ThreadFactory _threadFactory;
private HashSet<String> _flagSetsFilter = new HashSet<>();
private int _invalidSetsCount = 0;
private CustomHeaderDecorator _customHeaderDecorator = null;
private CustomHttpModule _alternativeHTTPModule = null;
public Builder() {
}
/**
* The amount of threads used for the thread pool that fetches segments.
* Usually and for most cases 2 is more than enough. But for organization
* that have a lot of segments, increasing this value can help expedite the
* time to ready.
* <p/>
*
* This is an ADVANCED parameter.
*
* @param numThreadsForSegmentFetch MUST be > 0. Default is 2.
* @return this builder
*/
public Builder numThreadsForSegmentFetch(int numThreadsForSegmentFetch) {
_numThreadsForSegmentFetch = numThreadsForSegmentFetch;
return this;
}
/**
* Max size of the queue to trigger a flush
*
* @param eventsQueueSize
* @return this builder
*/
public Builder eventsQueueSize(int eventsQueueSize) {
_eventsQueueSize = eventsQueueSize;
return this;
}
/**
* How often to flush data to the collection services
*
* @param eventFlushIntervalInMillis
* @return this builder
*/
public Builder eventFlushIntervalInMillis(long eventFlushIntervalInMillis) {
_eventSendIntervalInMillis = eventFlushIntervalInMillis;
return this;
}
/**
* The rest endpoint that sdk will hit for latest features and segments.
*
* @param endpoint MUST NOT be null
* @return this builder
*/
public Builder endpoint(String endpoint, String eventsEndpoint) {
_endpoint = endpoint;
_eventsEndpoint = eventsEndpoint;
return this;
}
/**
* The SDK will poll the endpoint for changes to features at this period.
* <p>
* Implementation Note: The SDK actually polls at a random interval
* chosen between (0.5 * n, n). This is to ensure that
* SDKs that are deployed simultaneously on different machines do not
* inundate the backend with requests at the same interval.
* </p>
*
* @param seconds MUST be greater than 0. Default value is 60.
* @return this builder
*/
public Builder featuresRefreshRate(int seconds) {
_featuresRefreshRate = seconds;
return this;
}
/**
* The SDK will poll the endpoint for changes to segments at this period in seconds.
* <p>
* Implementation Note: The SDK actually polls at a random interval
* chosen between (0.5 * n, n). This is to ensure that
* SDKs that are deployed simultaneously on different machines do not
* inundate the backend with requests at the same interval.
* </p>
*
* @param seconds MUST be greater than 0. Default value is 60.
* @return this builder
*/
public Builder segmentsRefreshRate(int seconds) {
_segmentsRefreshRate = seconds;
return this;
}
/**
* The ImpressionListener captures the which key saw what treatment ("on", "off", etc)
* at what time. This log is periodically pushed back to split endpoint.
* This parameter controls how quickly does the cache expire after a write.
* <p/>
* This is an ADVANCED parameter
*
* @param seconds MUST be > 0.
* @return this builder
*/
public Builder impressionsRefreshRate(int seconds) {
_impressionsRefreshRate = seconds;
return this;
}
public Builder impressionsMode(ImpressionsManager.Mode mode) {
_impressionsMode = mode;
return this;
}
/**
* The impression listener captures the which key saw what treatment ("on", "off", etc)
* at what time. This log is periodically pushed back to split endpoint.
* This parameter controls the in-memory queue size to store them before they are
* pushed back to split endpoint.
*
* If the value chosen is too small and more than the default size(5000) of impressions
* are generated, the old ones will be dropped and the sdk will show a warning.
* <p>
*
* This is an ADVANCED parameter.
*
* @param impressionsQueueSize MUST be > 0. Default is 5000.
* @return this builder
*/
public Builder impressionsQueueSize(int impressionsQueueSize) {
_impressionsQueueSize = impressionsQueueSize;
return this;
}
/**
*
* @deprecated As of release 3.2.5, replaced by {@link #integrationsConfig()} }
*
* You can provide your own ImpressionListener to capture all impressions
* generated by SplitClient. An Impression is generated each time getTreatment is called.
* <p>
*
* Note that we will wrap any ImpressionListener provided in our own implementation
* with an Executor controlling impressions going into your ImpressionListener. This is
* done to protect SplitClient from any slowness caused by your ImpressionListener. The
* Executor will be given the capacity you provide as parameter which is the
* number of impressions that can be saved in a blocking queue while waiting for
* your ImpressionListener to log them. Of course, the larger the value of capacity,
* the more memory can be taken up.
* <p>
*
* The executor will create two threads.
* <p>
*
* This is an ADVANCED function.
*
* @param impressionListener
* @param queueSize maximum number of impressions that will be queued in memory. If the impressionListener is
* slow, the queue will fill up and any subsequent impressions will be dropped.
* @return this builder
*/
@Deprecated
public Builder impressionListener(ImpressionListener impressionListener, int queueSize) {
if (null == _integrationsConfig) {
_integrationsConfig = new IntegrationsConfig.Builder()
.impressionsListener(impressionListener, queueSize)
.build();
} else {
_integrationsConfig.addStandardImpressionListener(impressionListener, queueSize);
}
return this;
}
/**
* The diagnostic metrics collected by the SDK are pushed back to split endpoint
* at this period.
* <p/>
* This is an ADVANCED parameter
*
* @param seconds MUST be > 0.
* @return this builder
*/
public Builder metricsRefreshRate(int seconds) {
_metricsRefreshRate = seconds;
return this;
}
/**
* Http client connection timeout. Default value is 15000ms.
*
* @param ms MUST be greater than 0.
* @return this builder
*/
public Builder connectionTimeout(int ms) {
_connectionTimeout = ms;
return this;
}
/**
* Http client read timeout. Default value is 15000ms.
*
* @param ms MUST be greater than 0.
* @return this builder
*/
public Builder readTimeout(int ms) {
_readTimeout = ms;
return this;
}
public Builder enableDebug() {
_debugEnabled = true;
return this;
}
/**
* Disable label capturing
* @return this builder
*/
public Builder disableLabels() {
_labelsEnabled = false;
return this;
}
public Builder disableIPAddress() {
_ipAddressEnabled = false;
return this;
}
/**
* The SDK kicks off background threads to download data necessary
* for using the SDK. You can choose to block until the SDK has
* downloaded split definitions so that you will not get
* the 'control' treatment.
* <p>
* <p>
* If this parameter is set to a non-negative value, the SDK
* will block for that number of milliseconds for the data to be downloaded when
* {@link SplitClient#blockUntilReady()} or {@link SplitManager#blockUntilReady()}
* is called
* <p/>
*
* @param milliseconds MUST BE greater than or equal to 0;
* @return this builder
*/
public Builder setBlockUntilReadyTimeout(int milliseconds) {
_ready = milliseconds;
return this;
}
/**
* How long to wait for impressions background thread before shutting down
* the underlying connections.
*
* @param waitTime tine in milliseconds
* @return this builder
*/
public Builder waitBeforeShutdown(int waitTime) {
_waitBeforeShutdown = waitTime;
return this;
}
/**
* The host location of the proxy. Default is localhost.
*
* @param proxyHost location of the proxy
* @return this builder
*/
public Builder proxyHost(String proxyHost) {
_proxyHost = proxyHost;
return this;
}
/**
* The port of the proxy. Default is -1.
*
* @param proxyPort port for the proxy
* @return this builder
*/
public Builder proxyPort(int proxyPort) {
_proxyPort = proxyPort;
return this;
}
/**
* The http scheme of the proxy. Default is http.
*
* @param proxyScheme protocol for the proxy
* @return this builder
*/
public Builder proxyScheme(String proxyScheme) {
_proxyScheme = proxyScheme;
return this;
}
/**
* Set the username for authentication against the proxy (if proxy settings are enabled). (Optional).
*
* @param proxyUsername
* @return this builder
*/
public Builder proxyUsername(String proxyUsername) {
_proxyUsername = proxyUsername;
return this;
}
/**
* Set the password for authentication against the proxy (if proxy settings are enabled). (Optional).
*
* @param proxyPassword
* @return this builder
*/
public Builder proxyPassword(String proxyPassword) {
_proxyPassword = proxyPassword;
return this;
}
/**
* Set the token for authentication against the proxy (if proxy settings are enabled). (Optional).
*
* @param proxyCredentialsProvider
* @return this builder
*/
public Builder proxyCredentialsProvider(ProxyCredentialsProvider proxyCredentialsProvider) {
_proxyCredentialsProvider = proxyCredentialsProvider;
return this;
}
/**
* Set the mtls authentication against the proxy (if proxy settings are enabled). (Optional).
*
* @param proxyMtlsAuth
* @return this builder
*/
public Builder proxyMtlsAuth(ProxyMTLSAuth proxyMtlsAuth) {
_proxyMtlsAuth = proxyMtlsAuth;
return this;
}
/**
* Disables running destroy() on shutdown by default.
*
* @return this builder
*/
public Builder disableDestroyOnShutDown() {
_destroyOnShutDown = false;
return this;
}
HttpHost proxy() {
if (_proxyPort != -1) {
return new HttpHost(_proxyScheme, _proxyHost, _proxyPort);
}
// Default is no proxy.
return null;
}
/**
* Set the location of the new yaml file for localhost mode defaulting to .split (legacy and deprecated format)
* This setting is optional.
*
* @param splitFile location
* @return this builder
*/
public Builder splitFile(String splitFile) {
_splitFile = splitFile;
return this;
}
public Builder splitFile(InputStream inputStream, FileTypeEnum fileType) {
_fileType = fileType;
_inputStream = inputStream;
return this;
}
/**
* Set the location of the directory where are the segment json files for localhost mode.
* This setting is optional.
*
* @param sementDirectory location
* @return this builder
*/
public Builder segmentDirectory(String sementDirectory){
_segmentDirectory = sementDirectory;
return this;
}
/**
* Sets up integrations for the Split SDK (Currently Impressions outgoing integrations supported only).
* @param config
* @return
*/
public Builder integrations(IntegrationsConfig config) {
_integrationsConfig = config;
return this;
}
/**
* Set if streaming is enabled or not. Default is true.
* @param streamingEnabled
* @return
*/
public Builder streamingEnabled(boolean streamingEnabled) {
_streamingEnabled = streamingEnabled;
return this;
}
/**
* Set if refresh is enabled or not for localhost mode. Default is false.
* @param localhostRefreshEnable
* @return
*/
public Builder localhostRefreshEnable(boolean localhostRefreshEnable) {
_localhostRefreshEnable = localhostRefreshEnable;
return this;
}
/**
* Set how many seconds to wait before re attempting to authenticate for push notifications. Default 1 second. Minimum 1 second.
* @param authRetryBackoffBase
* @return
*/
public Builder authRetryBackoffBase(int authRetryBackoffBase) {
_authRetryBackoffBase = authRetryBackoffBase;
return this;
}
/**
* Set how many seconds to wait before re attempting to connect to streaming. Default 1 second. Minimum 1 second.
* @param streamingReconnectBackoffBase
* @return
*/
public Builder streamingReconnectBackoffBase(int streamingReconnectBackoffBase) {
_streamingReconnectBackoffBase = streamingReconnectBackoffBase;
return this;
}
/**
* Set Authentication service URL.
* @param authServiceURL
* @return
*/
public Builder authServiceURL(String authServiceURL) {
_authServiceURL = authServiceURL;
return this;
}
/**
* Set Streaming service URL.
* @param streamingServiceURL
* @return
*/
public Builder streamingServiceURL(String streamingServiceURL) {
_streamingServiceURL = streamingServiceURL;
return this;
}
/** Set telemetry service URL.
* @param telemetryURL
* @return
*/
public Builder telemetryURL(String telemetryURL) {
_telemetryURl = telemetryURL;
return this;
}
/**
* How often send telemetry data
*
* @param telemetryRefreshRate
* @return this builder
*/
public Builder telemetryRefreshRate(int telemetryRefreshRate) {
_telemetryRefreshRate = telemetryRefreshRate;
return this;
}
/**
* Type of storage
*
* @param mode
* @return this builder
*/
public Builder operationMode(OperationMode mode) {
_operationMode = mode;
return this;
}
/**
*
* @param storage mode
* @return this builder
*/
public Builder storageMode(StorageMode mode) {
_storageMode = mode;
return this;
}
/**
* Storage wrapper
*
* @param customStorageWrapper