Skip to content

Commit bab72bc

Browse files
authored
feat: expose initial config load future for sub-classes of the BaseEppoClient (#48)
1 parent dfca826 commit bab72bc

File tree

4 files changed

+23
-11
lines changed

4 files changed

+23
-11
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ or [JVM](https://github.com/Eppo-exp/java-server-sdk) SDKs.
1010

1111
```groovy
1212
dependencies {
13-
implementation 'cloud.eppo:sdk-common-jvm:3.3.1'
13+
implementation 'cloud.eppo:sdk-common-jvm:3.3.2'
1414
}
1515
```
1616

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ plugins {
66
}
77

88
group = 'cloud.eppo'
9-
version = '3.3.2-SNAPSHOT'
9+
version = '3.3.2'
1010
ext.isReleaseVersion = !version.endsWith("SNAPSHOT")
1111

1212
java {

src/main/java/cloud/eppo/BaseEppoClient.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ public class BaseEppoClient {
3636
private final String sdkVersion;
3737
private boolean isGracefulMode;
3838

39+
@Nullable protected CompletableFuture<Boolean> getInitialConfigFuture() {
40+
return initialConfigFuture;
41+
}
42+
43+
private final CompletableFuture<Boolean> initialConfigFuture;
44+
3945
// Fields useful for testing in situations where we want to mock the http client or configuration
4046
// store (accessed via reflection)
4147
/** @noinspection FieldMayBeFinal */
@@ -73,9 +79,10 @@ protected BaseEppoClient(
7379
requestor =
7480
new ConfigurationRequestor(
7581
this.configurationStore, httpClient, expectObfuscatedConfig, supportBandits);
76-
if (initialConfiguration != null) {
77-
requestor.setInitialConfiguration(initialConfiguration);
78-
}
82+
initialConfigFuture =
83+
initialConfiguration != null
84+
? requestor.setInitialConfiguration(initialConfiguration)
85+
: null;
7986

8087
this.assignmentLogger = assignmentLogger;
8188
this.banditLogger = banditLogger;

src/main/java/cloud/eppo/ConfigurationRequestor.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class ConfigurationRequestor {
1818
private final boolean supportBandits;
1919

2020
private CompletableFuture<Void> remoteFetchFuture = null;
21-
private CompletableFuture<Void> configurationFuture = null;
21+
private CompletableFuture<Boolean> configurationFuture = null;
2222
private boolean initialConfigSet = false;
2323

2424
public ConfigurationRequestor(
@@ -42,38 +42,43 @@ public void setInitialConfiguration(@NotNull Configuration configuration) {
4242
configurationStore.saveConfiguration(configuration).thenApply(v -> true).join();
4343
}
4444

45-
// Asynchronously sets the initial configuration.
46-
public CompletableFuture<Void> setInitialConfiguration(
45+
/**
46+
* Asynchronously sets the initial configuration. Resolves to `true` if the initial configuration
47+
* was used, false if not (due to being empty, a fetched config taking precedence, etc.)
48+
*/
49+
public CompletableFuture<Boolean> setInitialConfiguration(
4750
@NotNull CompletableFuture<Configuration> configurationFuture) {
4851
if (initialConfigSet || this.configurationFuture != null) {
4952
throw new IllegalStateException("Configuration future has already been set");
5053
}
5154
this.configurationFuture =
5255
configurationFuture
53-
.thenAccept(
56+
.thenApply(
5457
(config) -> {
5558
synchronized (configurationStore) {
5659
if (config == null || config.isEmpty()) {
5760
log.debug("Initial configuration future returned empty/null");
61+
return false;
5862
} else if (remoteFetchFuture != null
5963
&& remoteFetchFuture.isDone()
6064
&& !remoteFetchFuture.isCompletedExceptionally()) {
6165
// Don't clobber a successful fetch.
6266
log.debug("Fetch has completed; ignoring initial config load.");
67+
return false;
6368
} else {
64-
log.debug("saving initial configuration");
6569
initialConfigSet =
6670
configurationStore
6771
.saveConfiguration(config)
6872
.thenApply((s) -> true)
6973
.join();
74+
return true;
7075
}
7176
}
7277
})
7378
.exceptionally(
7479
(e) -> {
7580
log.error("Error setting initial config", e);
76-
return null;
81+
return false;
7782
});
7883
return this.configurationFuture;
7984
}

0 commit comments

Comments
 (0)