-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathSplitClientConfig.java
More file actions
1296 lines (1124 loc) · 46.3 KB
/
SplitClientConfig.java
File metadata and controls
1296 lines (1124 loc) · 46.3 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.android.client;
import static io.split.android.client.utils.Utils.checkNotNull;
import androidx.annotation.NonNull;
import java.net.URI;
import java.util.concurrent.TimeUnit;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.X509TrustManager;
import io.split.android.android_client.BuildConfig;
import io.split.android.client.impressions.ImpressionListener;
import io.split.android.client.network.CertificatePinningConfiguration;
import io.split.android.client.network.DevelopmentSslConfig;
import io.split.android.client.network.HttpProxy;
import io.split.android.client.network.SplitAuthenticator;
import io.split.android.client.service.ServiceConstants;
import io.split.android.client.service.impressions.ImpressionsMode;
import io.split.android.client.shared.UserConsent;
import io.split.android.client.telemetry.TelemetryHelperImpl;
import io.split.android.client.utils.Utils;
import io.split.android.client.utils.logger.Logger;
import io.split.android.client.utils.logger.SplitLogLevel;
import io.split.android.client.validators.PrefixValidatorImpl;
import io.split.android.client.validators.ValidationErrorInfo;
/**
* Configurations for the SplitClient.
*/
public class SplitClientConfig {
private static final int MIN_FEATURES_REFRESH_RATE = 30;
private static final int MIN_MY_SEGMENTS_REFRESH_RATE = 30;
private static final int MIN_IMPRESSIONS_REFRESH_RATE = 30;
private static final int MIN_IMPRESSIONS_QUEUE_SIZE = 0;
private static final int MIN_IMPRESSIONS_CHUNK_SIZE = 0;
private static final int MIN_CONNECTION_TIMEOUT = 0;
private static final int MIN_READ_TIMEOUT = 0;
private static final int DEFAULT_FEATURES_REFRESH_RATE_SECS = 3600;
private static final int DEFAULT_SEGMENTS_REFRESH_RATE_SECS = 1800;
private static final int DEFAULT_IMPRESSIONS_REFRESH_RATE_SECS = 1800;
private static final int DEFAULT_IMPRESSIONS_QUEUE_SIZE = 30000;
private static final int DEFAULT_IMPRESSIONS_PER_PUSH = 2000;
private static final int DEFAULT_IMP_COUNTERS_REFRESH_RATE_SECS = 1800;
private static final int DEFAULT_CONNECTION_TIMEOUT_SECS = 10000;
private static final int DEFAULT_READ_TIMEOUT_SECS = 10000;
private static final int DEFAULT_READY = -1;
private static final int DEFAULT_IMPRESSIONS_CHUNK_SIZE = 2 * 1024;
private static final int DEFAULT_EVENTS_QUEUE_SIZE = 10000;
private static final int DEFAULT_EVENTS_FLUSH_INTERVAL = 1800;
private static final int DEFAULT_EVENTS_PER_PUSH = 2000;
private static final int DEFAULT_BACKGROUND_SYNC_PERIOD_MINUTES = 15;
private static final long MIN_IMPRESSIONS_DEDUPE_TIME_INTERVAL = TimeUnit.HOURS.toMillis(1);
private static final long MAX_IMPRESSIONS_DEDUPE_TIME_INTERVAL = TimeUnit.HOURS.toMillis(24);
private static final int DEFAULT_MTK_PER_PUSH = 30000;
// Validation settings
private static final int MAXIMUM_KEY_LENGTH = 250;
private static final String TRACK_EVENT_NAME_PATTERN = "^[a-zA-Z0-9][-_.:a-zA-Z0-9]{0,79}$";
// Data folder
private static final String DEFAULT_DATA_FOLDER = "split_data";
private static final long OBSERVER_CACHE_EXPIRATION_PERIOD = ServiceConstants.DEFAULT_OBSERVER_CACHE_EXPIRATION_PERIOD_MS;
private final String mEndpoint;
private final String mEventsEndpoint;
private final String mTelemetryEndpoint;
private final String mHostname;
private final String mIp;
private final HttpProxy mProxy;
private final SplitAuthenticator mProxyAuthenticator;
private final int mFeaturesRefreshRate;
private final int mSegmentsRefreshRate;
private final int mImpressionsRefreshRate;
private final int mImpressionsQueueSize;
private final int mImpressionsPerPush;
private final int mImpCountersRefreshRate;
private final int mMtkPerPush;
private final int mMtkRefreshRate;
private final int mConnectionTimeout;
private final int mReadTimeout;
private final boolean mLabelsEnabled;
private final int mReady;
private final ImpressionListener mImpressionListener;
private final long mImpressionsChunkSize;
// Background sync
private final boolean mSynchronizeInBackground;
private final long mBackgroundSyncPeriod;
private final boolean mBackgroundSyncWhenBatteryNotLow;
private final boolean mBackgroundSyncWhenWifiOnly;
//.Track configuration
private final int mEventsQueueSize;
private final int mEventsPerPush;
private final long mEventFlushInterval;
private final String mTrafficType;
// Push notification settings
private final boolean mStreamingEnabled;
private final String mAuthServiceUrl;
private final String mStreamingServiceUrl;
private final DevelopmentSslConfig mDevelopmentSslConfig;
private final SyncConfig mSyncConfig;
private final boolean mLlegacyStorageMigrationEnabled;
private final ImpressionsMode mImpressionsMode;
private final boolean mIsPersistentAttributesEnabled;
private final int mOfflineRefreshRate;
private boolean mShouldRecordTelemetry;
private final long mTelemetryRefreshRate;
private boolean mSyncEnabled = true;
private int mLogLevel = SplitLogLevel.NONE;
private UserConsent mUserConsent;
private boolean mEncryptionEnabled = false;
private final String mPrefix;
private final long mDefaultSSEConnectionDelayInSecs;
private final int mSSEDisconnectionDelayInSecs;
// To be set during startup
public static String splitSdkVersion;
private final long mObserverCacheExpirationPeriod;
private final CertificatePinningConfiguration mCertificatePinningConfiguration;
private final long mImpressionsDedupeTimeInterval;
@NonNull
private final RolloutCacheConfiguration mRolloutCacheConfiguration;
public static Builder builder() {
return new Builder();
}
private SplitClientConfig(String endpoint,
String eventsEndpoint,
int featureRefreshRate,
int segmentsRefreshRate,
int impressionsRefreshRate,
int impressionsQueueSize,
long impressionsChunkSize,
int impressionsPerPush,
int connectionTimeout,
int readTimeout,
int ready,
boolean labelsEnabled,
ImpressionListener impressionListener,
String hostname,
String ip,
HttpProxy proxy,
SplitAuthenticator proxyAuthenticator,
int eventsQueueSize,
int eventsPerPush,
long eventFlushInterval,
String trafficType,
boolean synchronizeInBackground,
long backgroundSyncPeriod,
boolean backgroundSyncWhenBatteryNotLow,
boolean backgroundSyncWhenWifiOnly,
boolean streamingEnabled,
String authServiceUrl,
String streamingServiceUrl,
DevelopmentSslConfig developmentSslConfig,
SyncConfig syncConfig,
boolean legacyStorageMigrationEnabled,
ImpressionsMode impressionsMode,
int impCountersRefreshRate,
boolean isPersistentAttributesEnabled,
int offlineRefreshRate,
String telemetryEndpoint,
long telemetryRefreshRate,
boolean shouldRecordTelemetry,
boolean syncEnabled,
int logLevel,
int mtkPerPush,
int mtkRefreshRate,
UserConsent userConsent,
boolean encryptionEnabled,
long defaultSSEConnectionDelayInSecs,
int sseDisconnectionDelayInSecs,
String prefix,
long observerCacheExpirationPeriod,
CertificatePinningConfiguration certificatePinningConfiguration,
long impressionsDedupeTimeInterval,
RolloutCacheConfiguration rolloutCacheConfiguration) {
mEndpoint = endpoint;
mEventsEndpoint = eventsEndpoint;
mTelemetryEndpoint = telemetryEndpoint;
mFeaturesRefreshRate = featureRefreshRate;
mSegmentsRefreshRate = segmentsRefreshRate;
mImpressionsRefreshRate = impressionsRefreshRate;
mImpressionsQueueSize = impressionsQueueSize;
mImpressionsPerPush = impressionsPerPush;
mImpCountersRefreshRate = impCountersRefreshRate;
mMtkRefreshRate = mtkRefreshRate;
mConnectionTimeout = connectionTimeout;
mReadTimeout = readTimeout;
mReady = ready;
mLabelsEnabled = labelsEnabled;
mImpressionListener = impressionListener;
mImpressionsChunkSize = impressionsChunkSize;
mHostname = hostname;
mIp = ip;
mProxy = proxy;
mProxyAuthenticator = proxyAuthenticator;
mEventsQueueSize = eventsQueueSize;
mEventsPerPush = eventsPerPush;
mEventFlushInterval = eventFlushInterval;
mTrafficType = trafficType;
mSynchronizeInBackground = synchronizeInBackground;
mBackgroundSyncPeriod = backgroundSyncPeriod;
mBackgroundSyncWhenBatteryNotLow = backgroundSyncWhenBatteryNotLow;
mBackgroundSyncWhenWifiOnly = backgroundSyncWhenWifiOnly;
mStreamingEnabled = streamingEnabled;
mAuthServiceUrl = authServiceUrl;
mStreamingServiceUrl = streamingServiceUrl;
mDevelopmentSslConfig = developmentSslConfig;
mSyncConfig = syncConfig;
mLlegacyStorageMigrationEnabled = legacyStorageMigrationEnabled;
mImpressionsMode = impressionsMode;
mIsPersistentAttributesEnabled = isPersistentAttributesEnabled;
mOfflineRefreshRate = offlineRefreshRate;
mTelemetryRefreshRate = telemetryRefreshRate;
mSyncEnabled = syncEnabled;
mLogLevel = logLevel;
mUserConsent = userConsent;
splitSdkVersion = "Android-" + BuildConfig.SPLIT_VERSION_NAME;
mShouldRecordTelemetry = shouldRecordTelemetry;
mMtkPerPush = mtkPerPush;
mEncryptionEnabled = encryptionEnabled;
mDefaultSSEConnectionDelayInSecs = defaultSSEConnectionDelayInSecs;
mSSEDisconnectionDelayInSecs = sseDisconnectionDelayInSecs;
mPrefix = prefix;
mObserverCacheExpirationPeriod = observerCacheExpirationPeriod;
mCertificatePinningConfiguration = certificatePinningConfiguration;
mImpressionsDedupeTimeInterval = impressionsDedupeTimeInterval;
mRolloutCacheConfiguration = rolloutCacheConfiguration;
}
public String trafficType() {
return mTrafficType;
}
@Deprecated
public long cacheExpirationInSeconds() {
return TimeUnit.DAYS.toSeconds(rolloutCacheConfiguration().getExpirationDays());
}
public long eventFlushInterval() {
return mEventFlushInterval;
}
public int eventsQueueSize() {
return mEventsQueueSize;
}
public int eventsPerPush() {
return mEventsPerPush;
}
public String endpoint() {
return mEndpoint;
}
public String eventsEndpoint() {
return mEventsEndpoint;
}
public String telemetryEndpoint() {
return mTelemetryEndpoint;
}
public int featuresRefreshRate() {
return mFeaturesRefreshRate;
}
public int segmentsRefreshRate() {
return mSegmentsRefreshRate;
}
public int impressionsRefreshRate() {
return mImpressionsRefreshRate;
}
public int impressionsQueueSize() {
return mImpressionsQueueSize;
}
public long impressionsChunkSize() {
return mImpressionsChunkSize;
}
public int impressionsPerPush() {
return mImpressionsPerPush;
}
public int connectionTimeout() {
return mConnectionTimeout;
}
public int readTimeout() {
return mReadTimeout;
}
public boolean labelsEnabled() {
return mLabelsEnabled;
}
public int blockUntilReady() {
return mReady;
}
public ImpressionListener impressionListener() {
return mImpressionListener;
}
public HttpProxy proxy() {
return mProxy;
}
@Deprecated
public SplitAuthenticator proxyAuthenticator() {
return mProxyAuthenticator;
}
public String hostname() {
return mHostname;
}
public int logLevel() {
return mLogLevel;
}
/**
* Regex to validate Track event name
*
* @return Regex pattern string
*/
String trackEventNamePattern() {
return TRACK_EVENT_NAME_PATTERN;
}
/**
* Maximum key char length for matching and bucketing
*
* @return Maximum char length
*/
int maximumKeyLength() {
return MAXIMUM_KEY_LENGTH;
}
/**
* Default data folder to use when some
* problem arises while creating it
* based on SDK key
*
* @return Default data folder
*/
String defaultDataFolder() {
return DEFAULT_DATA_FOLDER;
}
String prefix() {
return mPrefix;
}
public String ip() {
return mIp;
}
public boolean synchronizeInBackground() {
return mSynchronizeInBackground;
}
public long backgroundSyncPeriod() {
return mBackgroundSyncPeriod;
}
public boolean backgroundSyncWhenBatteryNotLow() {
return mBackgroundSyncWhenBatteryNotLow;
}
public boolean backgroundSyncWhenBatteryWifiOnly() {
return mBackgroundSyncWhenWifiOnly;
}
// Push notification settings
public boolean streamingEnabled() {
return mStreamingEnabled;
}
public String authServiceUrl() {
return mAuthServiceUrl;
}
public String streamingServiceUrl() {
return mStreamingServiceUrl;
}
public SplitAuthenticator authenticator() {
return mProxyAuthenticator;
}
public DevelopmentSslConfig developmentSslConfig() {
return mDevelopmentSslConfig;
}
public SyncConfig syncConfig() {
return mSyncConfig;
}
public boolean isStorageMigrationEnabled() {
return mLlegacyStorageMigrationEnabled;
}
public ImpressionsMode impressionsMode() {
return mImpressionsMode;
}
public int impressionsCounterRefreshRate() {
return mImpCountersRefreshRate;
}
public boolean persistentAttributesEnabled() {
return mIsPersistentAttributesEnabled;
}
public int offlineRefreshRate() { return mOfflineRefreshRate; }
public boolean shouldRecordTelemetry() {
return mShouldRecordTelemetry;
}
public long telemetryRefreshRate() {
return mTelemetryRefreshRate;
}
public boolean syncEnabled() { return mSyncEnabled; }
public int mtkPerPush() {
return mMtkPerPush;
}
public int mtkRefreshRate() {
return mMtkRefreshRate;
}
public UserConsent userConsent() {
return mUserConsent;
}
protected void setUserConsent(UserConsent status) {
mUserConsent = status;
}
public boolean encryptionEnabled() {
return mEncryptionEnabled;
}
public long defaultSSEConnectionDelay() {
return mDefaultSSEConnectionDelayInSecs;
}
public int sseDisconnectionDelay() {
return mSSEDisconnectionDelayInSecs;
}
private void enableTelemetry() { mShouldRecordTelemetry = true; }
public long observerCacheExpirationPeriod() {
return Math.max(mImpressionsDedupeTimeInterval, mObserverCacheExpirationPeriod);
}
public CertificatePinningConfiguration certificatePinningConfiguration() {
return mCertificatePinningConfiguration;
}
public long impressionsDedupeTimeInterval() {
return mImpressionsDedupeTimeInterval;
}
public RolloutCacheConfiguration rolloutCacheConfiguration() {
return mRolloutCacheConfiguration;
}
public static final class Builder {
static final int PROXY_PORT_DEFAULT = 80;
private ServiceEndpoints mServiceEndpoints = null;
private int mFeaturesRefreshRate = DEFAULT_FEATURES_REFRESH_RATE_SECS;
private int mSegmentsRefreshRate = DEFAULT_SEGMENTS_REFRESH_RATE_SECS;
private int mImpressionsRefreshRate = DEFAULT_IMPRESSIONS_REFRESH_RATE_SECS;
private int mImpressionsQueueSize = DEFAULT_IMPRESSIONS_QUEUE_SIZE;
private int mImpressionsPerPush = DEFAULT_IMPRESSIONS_PER_PUSH;
private int mImpCountersRefreshRate = DEFAULT_IMP_COUNTERS_REFRESH_RATE_SECS;
private int mConnectionTimeout = DEFAULT_CONNECTION_TIMEOUT_SECS;
private int mReadTimeout = DEFAULT_READ_TIMEOUT_SECS;
private int mReady = DEFAULT_READY; // -1 means no blocking
private boolean mLabelsEnabled = true;
private ImpressionListener mImpressionListener;
private long mImpressionsChunkSize = DEFAULT_IMPRESSIONS_CHUNK_SIZE; //2KB default size
private boolean mIsPersistentAttributesEnabled = false;
static final int OFFLINE_REFRESH_RATE_DEFAULT = -1;
static final int DEFAULT_TELEMETRY_REFRESH_RATE = 3600;
//.track configuration
private int mEventsQueueSize = DEFAULT_EVENTS_QUEUE_SIZE;
private long mEventFlushInterval = DEFAULT_EVENTS_FLUSH_INTERVAL;
private int mEventsPerPush = DEFAULT_EVENTS_PER_PUSH;
private String mTrafficType = null;
private String mHostname = "unknown";
private String mIp = "unknown";
private String mProxyHost = null;
private SplitAuthenticator mProxyAuthenticator = null;
private boolean mSynchronizeInBackground = false;
private long mBackgroundSyncPeriod = DEFAULT_BACKGROUND_SYNC_PERIOD_MINUTES;
private boolean mBackgroundSyncWhenBatteryNotLow = true;
private boolean mBackgroundSyncWhenWifiOnly = false;
// Push notification settings
private boolean mStreamingEnabled = true;
private DevelopmentSslConfig mDevelopmentSslConfig;
private SyncConfig mSyncConfig = SyncConfig.builder().build();
private boolean mLegacyStorageMigrationEnabled = false;
private ImpressionsMode mImpressionsMode = ImpressionsMode.OPTIMIZED;
private int mOfflineRefreshRate = OFFLINE_REFRESH_RATE_DEFAULT;
private long mTelemetryRefreshRate = DEFAULT_TELEMETRY_REFRESH_RATE;
private boolean mSyncEnabled = true;
private int mLogLevel = SplitLogLevel.NONE;
private final int mMtkPerPush = DEFAULT_MTK_PER_PUSH;
private final int mMtkRefreshRate = 15 * 60;
private UserConsent mUserConsent = UserConsent.GRANTED;
private boolean mEncryptionEnabled = false;
private final long mDefaultSSEConnectionDelayInSecs = ServiceConstants.DEFAULT_SSE_CONNECTION_DELAY_SECS;
private final int mSSEDisconnectionDelayInSecs = 60;
private final long mObserverCacheExpirationPeriod = OBSERVER_CACHE_EXPIRATION_PERIOD;
private String mPrefix = null;
private CertificatePinningConfiguration mCertificatePinningConfiguration = null;
private long mImpressionsDedupeTimeInterval = ServiceConstants.DEFAULT_IMPRESSIONS_DEDUPE_TIME_INTERVAL;
private RolloutCacheConfiguration mRolloutCacheConfiguration = RolloutCacheConfiguration.builder().build();
public Builder() {
mServiceEndpoints = ServiceEndpoints.builder().build();
}
/**
* Default Traffic Type to use in .track method
*
* @param trafficType
* @return this builder
*/
public Builder trafficType(String trafficType) {
mTrafficType = trafficType;
return this;
}
/**
* Max size of the queue to trigger a flush
*
* @param eventsQueueSize
* @return this builder
*/
public Builder eventsQueueSize(int eventsQueueSize) {
mEventsQueueSize = eventsQueueSize;
return this;
}
/**
* Max size of the batch to push events
*
* @param eventsPerPush
* @return this builder
*/
public Builder eventsPerPush(int eventsPerPush) {
mEventsPerPush = eventsPerPush;
return this;
}
/**
* How often to flush data to the collection services
*
* @param eventFlushInterval
* @return this builder
*/
public Builder eventFlushInterval(long eventFlushInterval) {
mEventFlushInterval = eventFlushInterval;
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) {
mFeaturesRefreshRate = 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) {
mSegmentsRefreshRate = seconds;
return this;
}
/**
* The ImpressionListener captures the key saw what treatment ("on", "off", etc)
* at what time. This log is periodically pushed to Split.
* This parameter controls how quickly the cache expires after a write.
* <p/>
* This is an ADVANCED parameter
*
* @param seconds MUST be > 0.
* @return this builder
*/
public Builder impressionsRefreshRate(int seconds) {
mImpressionsRefreshRate = seconds;
return this;
}
/**
* The impression listener captures the which key saw what treatment ("on", "off", etc)
* at what time. This log is periodically pushed to Split.
* This parameter controls the in-memory queue size to store them before they are
* pushed to Split.
* <p>
* 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/>
* <p>
* This is an ADVANCED parameter.
*
* @param impressionsQueueSize MUST be > 0. Default is 5000.
* @return this builder
*/
public Builder impressionsQueueSize(int impressionsQueueSize) {
mImpressionsQueueSize = impressionsQueueSize;
return this;
}
/**
* Max size of the batch to push impressions
*
* @param impressionsPerPush
* @return this builder
*/
public Builder impressionsPerPush(int impressionsPerPush) {
mImpressionsPerPush = impressionsPerPush;
return this;
}
/**
* You can provide your own ImpressionListener to capture all impressions
* generated by SplitClient. An Impression is generated each time getTreatment is called.
* <p>
* <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>
* <p>
* The executor will create two threads.
* <p>
* <p>
* This is an ADVANCED function.
*
* @param impressionListener
* @return this builder
*/
public Builder impressionListener(ImpressionListener impressionListener) {
mImpressionListener = impressionListener;
return this;
}
/**
* Http client connection timeout. Default value is 10000ms.
*
* @param ms MUST be greater than 0.
* @return this builder
*/
public Builder connectionTimeout(int ms) {
mConnectionTimeout = ms;
return this;
}
/**
* Http client read timeout. Default value is 10000ms.
*
* @param ms MUST be greater than 0.
* @return this builder
*/
public Builder readTimeout(int ms) {
mReadTimeout = ms;
return this;
}
/**
* Level of logging.
* The values are the same than standard Android logging plus NONE, to
* disable logging. Any not supported value will be considered NONE.
* {@link SplitLogLevel} or {@link android.util.Log} values can be used
*
* @return this builder
*/
public Builder logLevel(int level) {
mLogLevel = level;
Logger.instance().setLevel(mLogLevel);
return this;
}
/**
* Disable label capturing
*
* @return this builder
*/
public Builder disableLabels() {
mLabelsEnabled = 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 feature flag 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.
* <p/>
* <p/>
* If the download is not successful in this time period, a TimeOutException
* will be thrown.
* <p/>
* <p/>
* A negative value implies that the SDK building MUST NOT block. In this
* scenario, the SDK might return the 'control' treatment until the
* desired data has been downloaded.
*
* @param milliseconds MUST BE greater than or equal to 0;
* @return this builder
*/
public Builder ready(int milliseconds) {
mReady = milliseconds;
return this;
}
/**
* The proxy URI in standard "scheme://user:password@domain:port/path format. Default is null.
* If no port is provided default is 80
*
* @param proxyHost proxy URI
* @return this builder
*/
public Builder proxyHost(String proxyHost) {
if (proxyHost != null && proxyHost.endsWith("/")) {
mProxyHost = proxyHost.substring(0, proxyHost.length() - 1);
} else {
mProxyHost = proxyHost;
}
return this;
}
/**
* Set a custom authenticator for the proxy. This feature is experimental and
* and unsupported. It could be removed from the SDK
*
* @param proxyAuthenticator
* @return this builder
*/
public Builder proxyAuthenticator(SplitAuthenticator proxyAuthenticator) {
mProxyAuthenticator = proxyAuthenticator;
return this;
}
/**
* Maximum size for impressions chunk to dump to storage and post.
*
* @param size MUST be > 0.
* @return this builder
*/
public Builder impressionsChunkSize(long size) {
mImpressionsChunkSize = size;
return this;
}
/**
* The host name for the current device.
*
* @param hostname
* @return this builder
*/
public Builder hostname(String hostname) {
mHostname = hostname;
return this;
}
/**
* The current device IP address.
*
* @param ip
* @return this builder
*/
public Builder ip(String ip) {
mIp = ip;
return this;
}
/**
* When set to true app sync is done
* using android resources event while app is in background.
* Otherwise synchronization only occurs while app
* is in foreground
*
* @return this builder
*/
public Builder synchronizeInBackground(boolean synchronizeInBackground) {
mSynchronizeInBackground = synchronizeInBackground;
return this;
}
/**
* Period in minutes to execute background synchronization.
* Default value is 15 minutes and is the minimum allowed.
* If a lower value is specified, the default value will be used.
*
* @return this builder
*/
public Builder synchronizeInBackgroundPeriod(long backgroundSyncPeriod) {
mBackgroundSyncPeriod = backgroundSyncPeriod;
return this;
}
/**
* Synchronize in background only if battery has no low charge level
* Default value is set to true
*
* @return this builder
*/
public Builder backgroundSyncWhenBatteryNotLow(boolean backgroundSyncWhenBatteryNotLow) {
mBackgroundSyncWhenBatteryNotLow = backgroundSyncWhenBatteryNotLow;
return this;
}
/**
* Synchronize in background only when a connection is wifi (unmetered)
* When value is set to false, synchronization will occur whenever connection is available.
* Default value is set to false
*
* @return this builder
*/
public Builder backgroundSyncWhenWifiOnly(boolean backgroundSyncWhenWifiOnly) {
mBackgroundSyncWhenWifiOnly = backgroundSyncWhenWifiOnly;
return this;
}
/**
* Whether we should attempt to use streaming or not.
* If the variable is false, the SDK will start in polling mode and stay that way.
*
* @return This builder
* @default: True
*/
public Builder streamingEnabled(boolean streamingEnabled) {
mStreamingEnabled = streamingEnabled;
return this;
}
/**
* Alternative service endpoints URL. Should only be adjusted for playing well in test environments.
*
* @param serviceEndpoints ServiceEndpoints
* @return this builder
*/
public Builder serviceEndpoints(ServiceEndpoints serviceEndpoints) {
mServiceEndpoints = serviceEndpoints;
return this;
}
/**
* Allows setup a custom SSL factory and trust manager. Do not activate this feature in production.
*
* @return: This builder
* @default: null
*/
public Builder developmentSslConfig(@NonNull SSLSocketFactory sslSocketFactory,
@NonNull X509TrustManager trustManager,
@NonNull HostnameVerifier hostnameVerifier) {
mDevelopmentSslConfig = new DevelopmentSslConfig(checkNotNull(sslSocketFactory),
checkNotNull(trustManager), checkNotNull(hostnameVerifier));
return this;
}
/**
* Settings to customize how data sync is done
*
* @return: This builder
* @default: null
*/
public Builder syncConfig(SyncConfig syncConfig) {
mSyncConfig = syncConfig;
return this;
}
/**
* Activates migration from old storage to sqlite db
*
* @return: This builder
* @default: false
*/
public Builder legacyStorageMigrationEnabled(boolean legacyStorageMigrationEnabled) {
mLegacyStorageMigrationEnabled = legacyStorageMigrationEnabled;
return this;
}
/**
* Setup the impressions mode.
*
* @param mode Values:<br>
* DEBUG: All impressions are sent
* OPTIMIZED: Impressions are sent using an optimization algorithm
* NONE: Only unique keys evaluated for a particular feature flag are sent
* @return: This builder
* @default: OPTIMIZED
*/
public Builder impressionsMode(ImpressionsMode mode) {
mImpressionsMode = mode;
return this;
}
/**
* Setup the impressions mode using a string.
*
* @param mode Values:<br>
* DEBUG: All impressions are sent and
* OPTIMIZED: Impressions are sent using an optimization algorithm
* NONE: Only unique keys evaluated for a particular feature flag are sent
*
* <p>
* NOTE: If the string is invalid (Neither DEBUG, OPTIMIZED nor NONE) default value will be used
* </p>
* @return: This builder
* @default: OPTIMIZED
*/