-
public interface FlagsClientClient interface for evaluating feature flags and experiments.
This interface defines the public API that applications use to retrieve feature flag values. It follows the OpenFeature specification closely, to simplify implementing the OpenFeature Provider API on top.
To create a FlagsClient, use the Builder:
// Default client val client = FlagsClient.Builder().build() // Named client val client = FlagsClient.Builder("analytics").build() // With custom configuration val client = FlagsClient.Builder("analytics") .useCustomExposureEndpoint("https://custom.endpoint.com/exposure") .build()To retrieve an existing FlagsClient, use get:
val client = FlagsClient.get("analytics")
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public final classFlagsClient.BuilderBuilder for creating FlagsClient instances with custom configuration.
The builder uses a selective override pattern: configuration fields set explicitly on the builder override the defaults from FlagsFeature. Fields not set on the builder use the feature-level defaults.
Default FlagsClient:
val client = FlagsClient.Builder().build()Named FlagsClient:
val client = FlagsClient.Builder("analytics").build()With custom SDK core:
val client = FlagsClient.Builder(sdkCore = customCore) .build()public classFlagsClient.CompanionCompanion object providing static access to FlagsClient instances.
This companion manages the retrieval of FlagsClient instances from the FlagsFeature, ensuring thread-safe access and proper lifecycle management.
-
Method Summary
Modifier and Type Method Description abstract UnitsetEvaluationContext(EvaluationContext context, EvaluationContextCallback callback)Sets the EvaluationContext for flag resolution. abstract BooleanresolveBooleanValue(String flagKey, Boolean defaultValue)Resolves a boolean flag value. abstract StringresolveStringValue(String flagKey, String defaultValue)Resolves a string flag value. abstract DoubleresolveDoubleValue(String flagKey, Double defaultValue)Resolves a numeric flag value. abstract IntegerresolveIntValue(String flagKey, Integer defaultValue)Resolves an integer flag value. abstract JSONObjectresolveStructureValue(String flagKey, JSONObject defaultValue)Resolves a structured flag value as a JSONObject. abstract Map<String, Object>resolveStructureValue(String flagKey, Map<String, Object> defaultValue)Resolves a structured flag value as a Map. abstract <T extends Any> ResolutionDetails<T>resolve(String flagKey, T defaultValue)Resolves a flag value with detailed resolution information. abstract StateObservablegetState()Observable interface for tracking client state changes. -
-
Method Detail
-
setEvaluationContext
abstract Unit setEvaluationContext(EvaluationContext context, EvaluationContextCallback callback)
Sets the EvaluationContext for flag resolution.
The context is used to determine which flag values to return based on user targeting rules. This method triggers a background fetch of updated flag evaluations.
This method returns immediately without blocking. The actual context update and flag fetching happen asynchronously on a background thread.
- Parameters:
context- The EvaluationContext containing targeting key and attributes.callback- Optional callback to notify when the operation completes or fails.
-
resolveBooleanValue
abstract Boolean resolveBooleanValue(String flagKey, Boolean defaultValue)
Resolves a boolean flag value.
- Parameters:
flagKey- The unique identifier of the flag to resolve.defaultValue- The value to return if the flag cannot be retrieved or parsed.
-
resolveStringValue
abstract String resolveStringValue(String flagKey, String defaultValue)
Resolves a string flag value.
- Parameters:
flagKey- The unique identifier of the flag to resolve.defaultValue- The value to return if the flag cannot be retrieved or parsed.
-
resolveDoubleValue
abstract Double resolveDoubleValue(String flagKey, Double defaultValue)
Resolves a numeric flag value.
- Parameters:
flagKey- The unique identifier of the flag to resolve.defaultValue- The value to return if the flag cannot be retrieved or parsed.
-
resolveIntValue
abstract Integer resolveIntValue(String flagKey, Integer defaultValue)
Resolves an integer flag value.
- Parameters:
flagKey- The unique identifier of the flag to resolve.defaultValue- The value to return if the flag cannot be retrieved or parsed.
-
resolveStructureValue
abstract JSONObject resolveStructureValue(String flagKey, JSONObject defaultValue)
Resolves a structured flag value as a JSONObject.
- Parameters:
flagKey- The unique identifier of the flag to resolve.defaultValue- The value to return if the flag cannot be retrieved or parsed.
-
resolveStructureValue
abstract Map<String, Object> resolveStructureValue(String flagKey, Map<String, Object> defaultValue)
Resolves a structured flag value as a Map.
The returned Map contains only primitives (String, Int, Long, Double, Boolean), null values, nested Maps, and Lists. All nested structures are recursively converted.
This method is useful for integrations that prefer working with Kotlin collections over JSON types.
- Parameters:
flagKey- The unique identifier of the flag to resolve.defaultValue- The map to return if the flag cannot be retrieved or parsed.
-
resolve
abstract <T extends Any> ResolutionDetails<T> resolve(String flagKey, T defaultValue)
Resolves a flag value with detailed resolution information.
This is the core resolution method that provides comprehensive details about the flag resolution process, including the resolved value, variant identifier, resolution reason, error information, and any associated metadata.
// Boolean flag val boolResult = client.resolve("feature-enabled", false) if (boolResult.errorCode == null) { println("Feature is ${boolResult.value}, variant: ${boolResult.variant}") } // String flag val stringResult = client.resolve("api-endpoint", "https://default.com") println("Using endpoint: ${stringResult.value}") // With metadata val result = client.resolve("experiment", "control") result.flagMetadata?.let { metadata -> println("Experiment metadata: $metadata") }- Parameters:
flagKey- The unique identifier of the flag to resolve.defaultValue- The value to return if the flag cannot be retrieved or parsed.
-
getState
abstract StateObservable getState()
Observable interface for tracking client state changes.
Provides three ways to observe state:
Synchronous: StateObservable.getCurrentState for immediate queries (Java-friendly)
Callback: StateObservable.addListener for traditional observers (Java-friendly)
Example:
// Synchronous val current = client.state.getCurrentState() // Callback client.state.addListener(listener)
-
-
-
-