@@ -22,37 +22,46 @@ public class BaseEppoClient {
22
22
private final ObjectMapper mapper =
23
23
new ObjectMapper ()
24
24
.registerModule (EppoModule .eppoModule ()); // TODO: is this the best place for this?
25
- private static final String DEFAULT_HOST = "https://fscdn.eppo.cloud" ;
26
- private static final boolean DEFAULT_IS_GRACEFUL_MODE = true ;
25
+
26
+ protected static final String DEFAULT_HOST = "https://fscdn.eppo.cloud" ;
27
+ protected final ConfigurationRequestor requestor ;
27
28
28
29
private final ConfigurationStore configurationStore ;
29
- private final ConfigurationRequestor requestor ;
30
30
private final AssignmentLogger assignmentLogger ;
31
31
private final BanditLogger banditLogger ;
32
32
private final String sdkName ;
33
33
private final String sdkVersion ;
34
34
private final boolean isConfigObfuscated ;
35
35
private boolean isGracefulMode ;
36
36
37
- private static BaseEppoClient instance ;
38
-
39
37
// Fields useful for testing in situations where we want to mock the http client or configuration
40
38
// store (accessed via reflection)
41
39
/** @noinspection FieldMayBeFinal */
42
40
private static EppoHttpClient httpClientOverride = null ;
43
41
44
- private BaseEppoClient (
42
+ protected BaseEppoClient (
45
43
String apiKey ,
46
44
String sdkName ,
47
45
String sdkVersion ,
48
46
String host ,
49
- ConfigurationStore configurationStore ,
50
47
AssignmentLogger assignmentLogger ,
51
48
BanditLogger banditLogger ,
52
- boolean isGracefulMode ) {
49
+ boolean isGracefulMode ,
50
+ boolean expectObfuscatedConfig ) {
51
+
52
+ if (apiKey == null ) {
53
+ throw new IllegalArgumentException ("Unable to initialize Eppo SDK due to missing API key" );
54
+ }
55
+ if (sdkName == null || sdkVersion == null ) {
56
+ throw new IllegalArgumentException (
57
+ "Unable to initialize Eppo SDK due to missing SDK name or version" );
58
+ }
59
+ if (host == null ) {
60
+ host = DEFAULT_HOST ;
61
+ }
53
62
54
63
EppoHttpClient httpClient = buildHttpClient (host , apiKey , sdkName , sdkVersion );
55
- this .configurationStore = configurationStore ;
64
+ this .configurationStore = new ConfigurationStore () ;
56
65
requestor = new ConfigurationRequestor (configurationStore , httpClient );
57
66
this .assignmentLogger = assignmentLogger ;
58
67
this .banditLogger = banditLogger ;
@@ -61,8 +70,10 @@ private BaseEppoClient(
61
70
this .sdkName = sdkName ;
62
71
this .sdkVersion = sdkVersion ;
63
72
// For now, the configuration is only obfuscated for Android clients
64
- this .isConfigObfuscated = sdkName .toLowerCase ().contains ("android" );
73
+ this .isConfigObfuscated = expectObfuscatedConfig ;
74
+
65
75
// TODO: caching initialization (such as setting an API-key-specific prefix
76
+ // will probably involve passing in configurationStore to the constructor
66
77
}
67
78
68
79
private EppoHttpClient buildHttpClient (
@@ -78,51 +89,7 @@ private EppoHttpClient buildHttpClient(
78
89
return httpClient ;
79
90
}
80
91
81
- public static BaseEppoClient init (
82
- String apiKey ,
83
- String sdkName ,
84
- String sdkVersion ,
85
- String host ,
86
- AssignmentLogger assignmentLogger ,
87
- BanditLogger banditLogger ,
88
- boolean isGracefulMode ) {
89
-
90
- if (apiKey == null ) {
91
- throw new IllegalArgumentException ("Unable to initialize Eppo SDK due to missing API key" );
92
- }
93
- if (sdkName == null || sdkVersion == null ) {
94
- throw new IllegalArgumentException (
95
- "Unable to initialize Eppo SDK due to missing SDK name or version" );
96
- }
97
-
98
- if (instance != null ) {
99
- // TODO: also check we're not running a test
100
- log .warn ("Reinitializing an Eppo Client instance that was already initialized" );
101
- }
102
- instance =
103
- new BaseEppoClient (
104
- apiKey ,
105
- sdkName ,
106
- sdkVersion ,
107
- host ,
108
- new ConfigurationStore (),
109
- assignmentLogger ,
110
- banditLogger ,
111
- isGracefulMode );
112
- instance .refreshConfiguration ();
113
-
114
- return instance ;
115
- }
116
-
117
- /**
118
- * Ability to ad-hoc kick off a configuration load. Will load from a filesystem cached file as
119
- * well as fire off an HTTPS request for an updated configuration. If the cache load finishes
120
- * first, those assignments will be used until the fetch completes.
121
- *
122
- * <p>Deprecated, as we plan to make a more targeted and configurable way to do so in the future.
123
- */
124
- @ Deprecated
125
- public void refreshConfiguration () {
92
+ protected void loadConfiguration () {
126
93
requestor .load ();
127
94
}
128
95
@@ -479,65 +446,7 @@ private <T> T throwIfNotGraceful(Exception e, T defaultValue) {
479
446
throw new RuntimeException (e );
480
447
}
481
448
482
- public static BaseEppoClient getInstance () {
483
- if (BaseEppoClient .instance == null ) {
484
- throw new IllegalStateException ("Eppo SDK has not been initialized" );
485
- }
486
-
487
- return BaseEppoClient .instance ;
488
- }
489
-
490
449
public void setIsGracefulFailureMode (boolean isGracefulFailureMode ) {
491
450
this .isGracefulMode = isGracefulFailureMode ;
492
451
}
493
-
494
- public static class Builder {
495
- private String apiKey ;
496
- private String sdkName ;
497
- private String sdkVersion ;
498
- private String host = DEFAULT_HOST ;
499
- private AssignmentLogger assignmentLogger ;
500
- private BanditLogger banditLogger ;
501
- private boolean isGracefulMode = DEFAULT_IS_GRACEFUL_MODE ;
502
-
503
- public Builder apiKey (String apiKey ) {
504
- this .apiKey = apiKey ;
505
- return this ;
506
- }
507
-
508
- public Builder sdkName (String sdkName ) {
509
- this .sdkName = sdkName ;
510
- return this ;
511
- }
512
-
513
- public Builder sdkVersion (String sdkVersion ) {
514
- this .sdkVersion = sdkVersion ;
515
- return this ;
516
- }
517
-
518
- public Builder host (String host ) {
519
- this .host = host ;
520
- return this ;
521
- }
522
-
523
- public Builder assignmentLogger (AssignmentLogger assignmentLogger ) {
524
- this .assignmentLogger = assignmentLogger ;
525
- return this ;
526
- }
527
-
528
- public Builder banditLogger (BanditLogger banditLogger ) {
529
- this .banditLogger = banditLogger ;
530
- return this ;
531
- }
532
-
533
- public Builder isGracefulMode (boolean isGracefulMode ) {
534
- this .isGracefulMode = isGracefulMode ;
535
- return this ;
536
- }
537
-
538
- public BaseEppoClient buildAndInit () {
539
- return BaseEppoClient .init (
540
- apiKey , sdkName , sdkVersion , host , assignmentLogger , banditLogger , isGracefulMode );
541
- }
542
- }
543
452
}
0 commit comments