From 180d2143e3ee89d38019a8ce0f11b943f7341965 Mon Sep 17 00:00:00 2001 From: Yash <93548927+code4Y@users.noreply.github.com> Date: Wed, 13 Sep 2023 15:18:41 +0530 Subject: [PATCH 1/2] Update setProviderAndWait in README.md - Updated the setProviderAndWait example in the quick start section - Expand the provider's section to show both the async and synchronous options. Signed-off-by: Yash <93548927+code4Y@users.noreply.github.com> --- README.md | 50 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index db729ed4a..79df33e47 100644 --- a/README.md +++ b/README.md @@ -104,7 +104,7 @@ public void example(){ // configure a provider OpenFeatureAPI api = OpenFeatureAPI.getInstance(); - api.setProvider(new InMemoryProvider(myFlags)); + api.setProviderAndWait(new InMemoryProvider(myFlags)); // create a client Client client = api.getClient(); @@ -139,12 +139,28 @@ See [here](https://javadoc.io/doc/dev.openfeature/sdk/latest/) for the Javadocs. Look [here](https://openfeature.dev/ecosystem?instant_search%5BrefinementList%5D%5Btype%5D%5B0%5D=Provider&instant_search%5BrefinementList%5D%5Btechnology%5D%5B0%5D=Java) for a complete list of available providers. If the provider you're looking for hasn't been created yet, see the [develop a provider](#develop-a-provider) section to learn how to build it yourself. -Once you've added a provider as a dependency, it can be registered with OpenFeature like this: +Once you've added a provider as a dependency, you can register it with OpenFeature in either an asynchronous or synchronous manner. Below are examples of how to set providers using both methods: + +#### Asynchronous Provider Registration +To register a provider asynchronously, ensuring it is initialized before further actions are taken, you can use the `setProviderAndWait` method as shown in the following example: ```java - OpenFeatureAPI.getInstance().setProvider(new MyProvider()); + OpenFeatureAPI api = OpenFeatureAPI.getInstance(); + api.setProviderAndWait(new MyProvider()); +``` + +This method is appropriate when you need to wait for the provider's initialization to complete before proceeding. + +#### Synchronous Provider Registration +For synchronous provider registration, where you set the provider without waiting for initialization, you can use the `setProvider` method directly: + +```java + OpenFeatureAPI api = OpenFeatureAPI.getInstance(); + api.setProvider(new MyProvider()); ``` +This is a straightforward synchronous operation, suitable when you don't need to wait for the provider to initialize before continuing. + In some situations, it may be beneficial to register multiple providers in the same application. This is possible using [named clients](#named-clients), which is covered in more details below. @@ -211,19 +227,41 @@ Clients can be given a name. A name is a logical identifier which can be used to associate clients with a particular provider. If a name has no associated provider, the global provider is used. +#### Asynchronous Named Provider Configuration + +To register providers asynchronously, ensuring they are initialized before further actions are taken, you can use the `setProviderAndWait` method as shown below: + ```java FeatureProvider scopedProvider = new MyProvider(); -// registering the default provider +// registering the default provider asynchronously +OpenFeatureAPI.getInstance().setProviderAndWait(LocalProvider()); +// registering a named provider asynchronously +OpenFeatureAPI.getInstance().setProviderAndWait("clientForCache", new CachedProvider()); + +// a client backed by the default provider +Client clientDefault = OpenFeatureAPI.getInstance().getClient(); +// a client backed by CachedProvider +Client clientNamed = OpenFeatureAPI.getInstance().getClient("clientForCache"); +``` + +#### Synchronous Named Provider Configuration + +For synchronous provider registration, where you set the provider without waiting for initialization, you can use the `setProvider` method directly, as shown in the following example: + +```java +FeatureProvider scopedProvider = new MyProvider(); + +// registering the default provider synchronously OpenFeatureAPI.getInstance().setProvider(LocalProvider()); -// registering a named provider +// registering a named provider synchronously OpenFeatureAPI.getInstance().setProvider("clientForCache", new CachedProvider()); // a client backed by default provider Client clientDefault = OpenFeatureAPI.getInstance().getClient(); // a client backed by CachedProvider Client clientNamed = OpenFeatureAPI.getInstance().getClient("clientForCache"); -``` +``` ### Eventing From a9b2a8ca8bfdf1fa1b8d0e80683d5a5c08c1f3cd Mon Sep 17 00:00:00 2001 From: Yash <93548927+code4Y@users.noreply.github.com> Date: Thu, 14 Sep 2023 00:01:29 +0530 Subject: [PATCH 2/2] Update Provider and Named clients README.md - blocking / non-blocking terms added in Providers section - removed repetition of code and added link in Named clients Signed-off-by: Yash <93548927+code4Y@users.noreply.github.com> --- README.md | 58 +++++++++++++++++-------------------------------------- 1 file changed, 18 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index 79df33e47..ebfa92ca5 100644 --- a/README.md +++ b/README.md @@ -139,27 +139,24 @@ See [here](https://javadoc.io/doc/dev.openfeature/sdk/latest/) for the Javadocs. Look [here](https://openfeature.dev/ecosystem?instant_search%5BrefinementList%5D%5Btype%5D%5B0%5D=Provider&instant_search%5BrefinementList%5D%5Btechnology%5D%5B0%5D=Java) for a complete list of available providers. If the provider you're looking for hasn't been created yet, see the [develop a provider](#develop-a-provider) section to learn how to build it yourself. -Once you've added a provider as a dependency, you can register it with OpenFeature in either an asynchronous or synchronous manner. Below are examples of how to set providers using both methods: +Once you've added a provider as a dependency, it can be registered with OpenFeature like this: -#### Asynchronous Provider Registration -To register a provider asynchronously, ensuring it is initialized before further actions are taken, you can use the `setProviderAndWait` method as shown in the following example: - +#### Synchronous + +To register a provider in a blocking manner to ensure it is ready before further actions are taken, you can use the `setProviderAndWait` method as shown below: + ```java OpenFeatureAPI api = OpenFeatureAPI.getInstance(); api.setProviderAndWait(new MyProvider()); -``` - -This method is appropriate when you need to wait for the provider's initialization to complete before proceeding. +``` + +#### Asynchronous -#### Synchronous Provider Registration -For synchronous provider registration, where you set the provider without waiting for initialization, you can use the `setProvider` method directly: +To register a provider in a non-blocking manner, you can use the `setProvider` method as shown below: ```java - OpenFeatureAPI api = OpenFeatureAPI.getInstance(); - api.setProvider(new MyProvider()); -``` - -This is a straightforward synchronous operation, suitable when you don't need to wait for the provider to initialize before continuing. + OpenFeatureAPI.getInstance().setProvider(new MyProvider()); +``` In some situations, it may be beneficial to register multiple providers in the same application. This is possible using [named clients](#named-clients), which is covered in more details below. @@ -225,43 +222,24 @@ The Java SDK uses SLF4J. See the [SLF4J manual](https://slf4j.org/manual.html) f Clients can be given a name. A name is a logical identifier which can be used to associate clients with a particular provider. -If a name has no associated provider, the global provider is used. - -#### Asynchronous Named Provider Configuration - -To register providers asynchronously, ensuring they are initialized before further actions are taken, you can use the `setProviderAndWait` method as shown below: +If a name has no associated provider, the global provider is used. ```java FeatureProvider scopedProvider = new MyProvider(); -// registering the default provider asynchronously -OpenFeatureAPI.getInstance().setProviderAndWait(LocalProvider()); -// registering a named provider asynchronously -OpenFeatureAPI.getInstance().setProviderAndWait("clientForCache", new CachedProvider()); - -// a client backed by the default provider -Client clientDefault = OpenFeatureAPI.getInstance().getClient(); -// a client backed by CachedProvider -Client clientNamed = OpenFeatureAPI.getInstance().getClient("clientForCache"); -``` - -#### Synchronous Named Provider Configuration - -For synchronous provider registration, where you set the provider without waiting for initialization, you can use the `setProvider` method directly, as shown in the following example: - -```java -FeatureProvider scopedProvider = new MyProvider(); - -// registering the default provider synchronously +// registering the default provider OpenFeatureAPI.getInstance().setProvider(LocalProvider()); -// registering a named provider synchronously +// registering a named provider OpenFeatureAPI.getInstance().setProvider("clientForCache", new CachedProvider()); // a client backed by default provider Client clientDefault = OpenFeatureAPI.getInstance().getClient(); // a client backed by CachedProvider Client clientNamed = OpenFeatureAPI.getInstance().getClient("clientForCache"); -``` +``` + +Named providers can be set in a blocking or non-blocking way. +For more details, please refer to the [providers](#providers) section. ### Eventing