Skip to content

Commit

Permalink
feat: add initialConfiguration to client Builder
Browse files Browse the repository at this point in the history
  • Loading branch information
typotter committed Sep 25, 2024
1 parent f913167 commit 3ef59d0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ java {
}

group = 'cloud.eppo'
version = '3.0.3-SNAPSHOT'
version = '3.1.0-SNAPSHOT'
ext.isReleaseVersion = !version.endsWith("SNAPSHOT")

import org.apache.tools.ant.filters.ReplaceTokens
Expand All @@ -31,7 +31,7 @@ repositories {

dependencies {
// Re-export classes and interfaces that will be used upstream
api 'cloud.eppo:sdk-common-jvm:3.1.1-SNAPSHOT'
api 'cloud.eppo:sdk-common-jvm:3.2.0-SNAPSHOT'

implementation 'com.github.zafarkhaja:java-semver:0.10.2'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.17.1'
Expand All @@ -40,7 +40,7 @@ dependencies {
// Logback classic 1.3.x is compatible with java 8
implementation 'ch.qos.logback:logback-classic:1.3.14'

testImplementation 'cloud.eppo:sdk-common-jvm:3.0.0-SNAPSHOT:tests'
testImplementation 'cloud.eppo:sdk-common-jvm:3.2.0-SNAPSHOT:tests'
testImplementation platform('org.junit:junit-bom:5.10.2')
testImplementation 'org.junit.jupiter:junit-jupiter'
testImplementation 'com.github.tomakehurst:wiremock-jre8:2.35.2'
Expand Down
33 changes: 30 additions & 3 deletions src/main/java/com/eppo/sdk/EppoClient.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.eppo.sdk;

import cloud.eppo.BaseEppoClient;
import cloud.eppo.api.Configuration;
import cloud.eppo.logging.AssignmentLogger;
import cloud.eppo.logging.BanditLogger;
import com.eppo.sdk.helpers.AppDetails;
import com.eppo.sdk.helpers.FetchConfigurationsTask;
import java.util.Timer;
import java.util.concurrent.CompletableFuture;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -41,9 +43,20 @@ private EppoClient(
String sdkVersion,
AssignmentLogger assignmentLogger,
BanditLogger banditLogger,
boolean isGracefulModel) {
boolean isGracefulModel,
CompletableFuture<Configuration> initialConfiguration) {
super(
apiKey, host, sdkName, sdkVersion, assignmentLogger, banditLogger, isGracefulModel, false);
apiKey,
host,
sdkName,
sdkVersion,
assignmentLogger,
banditLogger,
null,
isGracefulModel,
false,
true,
initialConfiguration);
}

/** Stops the client from polling Eppo for updated flag and bandit configurations */
Expand All @@ -62,6 +75,7 @@ public static class Builder {
private boolean forceReinitialize = DEFAULT_FORCE_REINITIALIZE;
private long pollingIntervalMs = DEFAULT_POLLING_INTERVAL_MS;
private String host = DEFAULT_HOST;
private CompletableFuture<Configuration> initialConfiguration;

/** Sets the API Key--created within the eppo application--to use. This is required. */
public Builder apiKey(String apiKey) {
Expand Down Expand Up @@ -125,6 +139,12 @@ public Builder host(String host) {
return this;
}

/** Sets the initial configuration for the client. */
public Builder initialConfiguration(CompletableFuture<Configuration> initialConfiguration) {
this.initialConfiguration = initialConfiguration;
return this;
}

public EppoClient buildAndInit() {
AppDetails appDetails = AppDetails.getInstance();
String sdkName = appDetails.getName();
Expand All @@ -143,7 +163,14 @@ public EppoClient buildAndInit() {

instance =
new EppoClient(
apiKey, sdkName, sdkVersion, host, assignmentLogger, banditLogger, isGracefulMode);
apiKey,
sdkName,
sdkVersion,
host,
assignmentLogger,
banditLogger,
isGracefulMode,
initialConfiguration);

// Stop any active polling
stopPolling();
Expand Down

0 comments on commit 3ef59d0

Please sign in to comment.