java.lang.Object
dev.openfeature.sdk.OpenFeatureAPI
- All Implemented Interfaces:
EventBus<OpenFeatureAPI>
A global singleton which holds base configuration for the OpenFeature
library.
Configuration here will be shared across all
Clients.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds hooks for globally, used for all evaluations.voidRemoves all hooks.A factory function for creating new, OpenFeature client.A factory function for creating new domainless OpenFeature client.A factory function for creating new domainless OpenFeature client.Gets the global evaluation context, which will be used for all evaluations.getHooks()Fetch the hooks associated to this client.static OpenFeatureAPIProvisions theOpenFeatureAPIsingleton (if needed) and returns it.Return the default provider.getProvider(String domain) Fetch a provider for a domain.Get metadata about the default provider.getProviderMetadata(String domain) Get metadata about a registered provider using the client name.Return the transaction context propagator.on(ProviderEvent event, Consumer<EventDetails> handler) Add a handler for the specifiedProviderEvent.Add a handler for theProviderEvent.PROVIDER_CONFIGURATION_CHANGEDevent.onProviderError(Consumer<EventDetails> handler) Add a handler for theProviderEvent.PROVIDER_STALEevent.onProviderReady(Consumer<EventDetails> handler) Add a handler for theProviderEvent.PROVIDER_READYevent.onProviderStale(Consumer<EventDetails> handler) Add a handler for theProviderEvent.PROVIDER_ERRORevent.removeHandler(ProviderEvent event, Consumer<EventDetails> handler) Remove the previously attached handler by reference.setEvaluationContext(EvaluationContext evaluationContext) Sets the global evaluation context, which will be used for all evaluations.voidsetProvider(FeatureProvider provider) Set the default provider.voidsetProvider(String domain, FeatureProvider provider) Add a provider for a domain.voidsetProviderAndWait(FeatureProvider provider) Sets the default provider and waits for its initialization to complete.voidsetProviderAndWait(String domain, FeatureProvider provider) Add a provider for a domain and wait for initialization to finish.voidsetTransactionContext(EvaluationContext evaluationContext) Sets the transaction context using the registered transaction context propagator.voidsetTransactionContextPropagator(TransactionContextPropagator transactionContextPropagator) Sets the transaction context propagator.voidshutdown()Shut down and reset the current status of OpenFeature API.
-
Constructor Details
-
OpenFeatureAPI
protected OpenFeatureAPI()
-
-
Method Details
-
getInstance
Provisions theOpenFeatureAPIsingleton (if needed) and returns it.- Returns:
- The singleton instance.
-
getProviderMetadata
Get metadata about the default provider.- Returns:
- the provider metadata
-
getProviderMetadata
Get metadata about a registered provider using the client name. An unbound or empty client name will return metadata from the default provider.- Parameters:
domain- an identifier which logically binds clients with providers- Returns:
- the provider metadata
-
getClient
A factory function for creating new, OpenFeature client. Clients can contain their own state (e.g. logger, hook, context). Multiple clients can be used to segment feature flag configuration. All un-named or unbound clients use the default provider.- Returns:
- a new client instance
-
getClient
A factory function for creating new domainless OpenFeature client. Clients can contain their own state (e.g. logger, hook, context). Multiple clients can be used to segment feature flag configuration. If there is already a provider bound to this domain, this provider will be used. Otherwise, the default provider is used until a provider is assigned to that domain.- Parameters:
domain- an identifier which logically binds clients with providers- Returns:
- a new client instance
-
getClient
A factory function for creating new domainless OpenFeature client. Clients can contain their own state (e.g. logger, hook, context). Multiple clients can be used to segment feature flag configuration. If there is already a provider bound to this domain, this provider will be used. Otherwise, the default provider is used until a provider is assigned to that domain.- Parameters:
domain- a identifier which logically binds clients with providersversion- a version identifier- Returns:
- a new client instance
-
setEvaluationContext
Sets the global evaluation context, which will be used for all evaluations.- Parameters:
evaluationContext- the context- Returns:
- api instance
-
getEvaluationContext
Gets the global evaluation context, which will be used for all evaluations.- Returns:
- evaluation context
-
getTransactionContextPropagator
Return the transaction context propagator. -
setTransactionContextPropagator
public void setTransactionContextPropagator(TransactionContextPropagator transactionContextPropagator) Sets the transaction context propagator.- Throws:
IllegalArgumentException- iftransactionContextPropagatoris null
-
setTransactionContext
Sets the transaction context using the registered transaction context propagator. -
setProvider
Set the default provider. -
setProvider
Add a provider for a domain.- Parameters:
domain- The domain to bind the provider to.provider- The provider to set.
-
setProviderAndWait
Sets the default provider and waits for its initialization to complete.Note: If the provider fails during initialization, an
OpenFeatureErrorwill be thrown. It is recommended to wrap this call in a try-catch block to handle potential initialization failures gracefully.- Parameters:
provider- theFeatureProviderto set as the default.- Throws:
OpenFeatureError- if the provider fails during initialization.
-
setProviderAndWait
Add a provider for a domain and wait for initialization to finish.Note: If the provider fails during initialization, an
OpenFeatureErrorwill be thrown. It is recommended to wrap this call in a try-catch block to handle potential initialization failures gracefully.- Parameters:
domain- The domain to bind the provider to.provider- The provider to set.- Throws:
OpenFeatureError- if the provider fails during initialization.
-
getProvider
Return the default provider. -
getProvider
Fetch a provider for a domain. If not found, return the default.- Parameters:
domain- The domain to look for.- Returns:
- A named
FeatureProvider
-
addHooks
Adds hooks for globally, used for all evaluations. Hooks are run in the order they're added in the before stage. They are run in reverse order for all other stages.- Parameters:
hooks- The hook to add.
-
getHooks
Fetch the hooks associated to this client.- Returns:
- A list of
Hooks.
-
clearHooks
public void clearHooks()Removes all hooks. -
shutdown
public void shutdown()Shut down and reset the current status of OpenFeature API. This call cleans up all active providers and attempts to shut down internal event handling mechanisms. Once shut down is complete, API is reset and ready to use again. -
onProviderReady
Add a handler for theProviderEvent.PROVIDER_READYevent. Shorthand forEventBus.on(ProviderEvent, Consumer)- Specified by:
onProviderReadyin interfaceEventBus<OpenFeatureAPI>- Parameters:
handler- behavior to add with this event- Returns:
- this
-
onProviderConfigurationChanged
Add a handler for theProviderEvent.PROVIDER_CONFIGURATION_CHANGEDevent. Shorthand forEventBus.on(ProviderEvent, Consumer)- Specified by:
onProviderConfigurationChangedin interfaceEventBus<OpenFeatureAPI>- Parameters:
handler- behavior to add with this event- Returns:
- this
-
onProviderStale
Add a handler for theProviderEvent.PROVIDER_ERRORevent. Shorthand forEventBus.on(ProviderEvent, Consumer)- Specified by:
onProviderStalein interfaceEventBus<OpenFeatureAPI>- Parameters:
handler- behavior to add with this event- Returns:
- this
-
onProviderError
Add a handler for theProviderEvent.PROVIDER_STALEevent. Shorthand forEventBus.on(ProviderEvent, Consumer)- Specified by:
onProviderErrorin interfaceEventBus<OpenFeatureAPI>- Parameters:
handler- behavior to add with this event- Returns:
- this
-
on
Add a handler for the specifiedProviderEvent.- Specified by:
onin interfaceEventBus<OpenFeatureAPI>- Parameters:
event- event typehandler- behavior to add with this event- Returns:
- this
-
removeHandler
Remove the previously attached handler by reference. If the handler doesn't exists, no-op.- Specified by:
removeHandlerin interfaceEventBus<OpenFeatureAPI>- Parameters:
event- event typehandler- to be removed- Returns:
- this
-