-
public class OpenFeatureAPI
-
-
Field Summary
Fields Modifier and Type Field Description private final MutableStateFlow<FeatureProvider>providersFlowprivate final Flow<OpenFeatureStatus>statusFlowprivate List<Hook<?>>hookspublic final static OpenFeatureAPIINSTANCE
-
Method Summary
Modifier and Type Method Description final UnitsetProvider(FeatureProvider provider, CoroutineDispatcher dispatcher, EvaluationContext initialContext)Set the FeatureProvider for the SDK. final UnitsetProviderAndWait(FeatureProvider provider, EvaluationContext initialContext, CoroutineDispatcher dispatcher)Set the FeatureProvider for the SDK. final FeatureProvidergetProvider()Get the current FeatureProvider for the SDK. final UnitclearProvider()Clear the current FeatureProvider for the SDK and set it to a no-op provider. final UnitsetEvaluationContextAndWait(EvaluationContext evaluationContext)Set the EvaluationContext for the SDK. final UnitsetEvaluationContext(EvaluationContext evaluationContext, CoroutineDispatcher dispatcher)Set the EvaluationContext for the SDK. final EvaluationContextgetEvaluationContext()Get the current EvaluationContext for the SDK. final ProviderMetadatagetProviderMetadata()Get the ProviderMetadata for the current FeatureProvider. final ClientgetClient(String name, String version)Get a Client for the SDK. final UnitaddHooks(List<Hook<?>> hooks)Add Hooks to the SDK. final UnitclearHooks()Clear all Hooks from the SDK. final Unitshutdown()Shutdown the SDK. final OpenFeatureStatusgetStatus()Get the current OpenFeatureStatus of the SDK. final <T extends OpenFeatureProviderEvents> Flow<T>observe()Observe events from currently configured Provider. final MutableStateFlow<FeatureProvider>getProvidersFlow()final Flow<OpenFeatureStatus>getStatusFlow()final List<Hook<?>>getHooks()final UnitsetHooks(List<Hook<?>> hooks)-
-
Method Detail
-
setProvider
final Unit setProvider(FeatureProvider provider, CoroutineDispatcher dispatcher, EvaluationContext initialContext)
Set the FeatureProvider for the SDK. This method will return immediately and initialize the provider in a coroutine scope When the provider is successfully initialized it will set the status to Ready. If the provider fails to initialize it will set the status to Error.
This method requires you to manually wait for the status to be Ready before using the SDK for flag evaluations. This can be done by using the statusFlow and waiting for the first Ready status or by accessing getStatus
- Parameters:
provider- the provider to setdispatcher- the dispatcher to use for the provider initialization coroutine.initialContext- the initial EvaluationContext to use for the provider initialization.
-
setProviderAndWait
final Unit setProviderAndWait(FeatureProvider provider, EvaluationContext initialContext, CoroutineDispatcher dispatcher)
Set the FeatureProvider for the SDK. This method will block until the provider is initialized.
- Parameters:
provider- the FeatureProvider to setinitialContext- the initial EvaluationContext to use for the provider initialization.
-
getProvider
final FeatureProvider getProvider()
Get the current FeatureProvider for the SDK.
-
clearProvider
final Unit clearProvider()
Clear the current FeatureProvider for the SDK and set it to a no-op provider.
-
setEvaluationContextAndWait
final Unit setEvaluationContextAndWait(EvaluationContext evaluationContext)
Set the EvaluationContext for the SDK. This method will block until the context is set and the provider is ready.
If the new context is different compare to the old context, this will cause the provider to reconcile with the new context. When the provider "Reconciles" it will set the status to OpenFeatureStatus.Reconciling. When the provider successfully reconciles it will set the status to OpenFeatureStatus.Ready. If the provider fails to reconcile it will set the status to OpenFeatureStatus.Error.
- Parameters:
evaluationContext- the EvaluationContext to set
-
setEvaluationContext
final Unit setEvaluationContext(EvaluationContext evaluationContext, CoroutineDispatcher dispatcher)
Set the EvaluationContext for the SDK. This method will return immediately and set the context in a coroutine scope.
If the new context is different compare to the old context, this will cause the provider to reconcile with the new context. When the provider "Reconciles" it will set the status to OpenFeatureStatus.Reconciling. When the provider successfully reconciles it will set the status to OpenFeatureStatus.Ready. If the provider fails to reconcile it will set the status to OpenFeatureStatus.Error.
This method requires you to manually wait for the status to be Ready before using the SDK for flag evaluations. This can be done by using the statusFlow and waiting for the first Ready status or by accessing getStatus
- Parameters:
evaluationContext- the EvaluationContext to set
-
getEvaluationContext
final EvaluationContext getEvaluationContext()
Get the current EvaluationContext for the SDK.
-
getProviderMetadata
final ProviderMetadata getProviderMetadata()
Get the ProviderMetadata for the current FeatureProvider.
-
getClient
final Client getClient(String name, String version)
Get a Client for the SDK. This client can be used to evaluate flags.
-
clearHooks
final Unit clearHooks()
Clear all Hooks from the SDK.
-
shutdown
final Unit shutdown()
Shutdown the SDK. This will cancel the provider set job and call the provider's shutdown method. The SDK status will be set to OpenFeatureStatus.NotReady.
-
getStatus
final OpenFeatureStatus getStatus()
Get the current OpenFeatureStatus of the SDK.
-
observe
final <T extends OpenFeatureProviderEvents> Flow<T> observe()
Observe events from currently configured Provider.
-
getProvidersFlow
final MutableStateFlow<FeatureProvider> getProvidersFlow()
-
getStatusFlow
final Flow<OpenFeatureStatus> getStatusFlow()
-
-
-
-