From 692845aa34e5a6acc24802a14fdf7df5851ce986 Mon Sep 17 00:00:00 2001 From: Peter Csajtai Date: Tue, 24 Sep 2024 15:49:48 +0200 Subject: [PATCH] Fix Java OpenFeature docs (#490) * Fix Java OpenFeature docs * Update java.mdx --- website/docs/sdk-reference/android.mdx | 6 +-- website/docs/sdk-reference/dart.mdx | 2 +- website/docs/sdk-reference/dotnet.mdx | 2 +- website/docs/sdk-reference/java.mdx | 4 +- .../docs/sdk-reference/openfeature/java.mdx | 43 +++++++++++++------ .../docs/sdk-reference/openfeature/php.mdx | 2 +- website/docs/sdk-reference/php.mdx | 2 +- .../version-V1/sdk-reference/android.mdx | 6 +-- .../version-V1/sdk-reference/dart.mdx | 2 +- .../version-V1/sdk-reference/dotnet.mdx | 2 +- .../version-V1/sdk-reference/java.mdx | 4 +- .../sdk-reference/openfeature/java.mdx | 43 +++++++++++++------ .../sdk-reference/openfeature/php.mdx | 2 +- .../version-V1/sdk-reference/php.mdx | 2 +- 14 files changed, 78 insertions(+), 44 deletions(-) diff --git a/website/docs/sdk-reference/android.mdx b/website/docs/sdk-reference/android.mdx index 9ad4bd249..e3291596c 100644 --- a/website/docs/sdk-reference/android.mdx +++ b/website/docs/sdk-reference/android.mdx @@ -55,7 +55,7 @@ ConfigCatClient client = ConfigCatClient.get("#YOUR-SDK-KEY#"); ```java boolean isMyAwesomeFeatureEnabled = client.getValue(Boolean.class, "", false); -if(isMyAwesomeFeatureEnabled) { +if (isMyAwesomeFeatureEnabled) { doTheNewThing(); } else { doTheOldThing(); @@ -64,7 +64,7 @@ if(isMyAwesomeFeatureEnabled) { // Or asynchronously client.getValueAsync(Boolean.class, "", false) .thenAccept(isMyAwesomeFeatureEnabled -> { - if(isMyAwesomeFeatureEnabled) { + if (isMyAwesomeFeatureEnabled) { doTheNewThing(); } else { doTheOldThing(); @@ -176,7 +176,7 @@ client.getValueAsync( User.newBuilder().build("#UNIQUE-USER-IDENTIFIER#"), // Optional User Object false // Default value ).thenAccept(isMyAwesomeFeatureEnabled -> { - if(isMyAwesomeFeatureEnabled) { + if (isMyAwesomeFeatureEnabled) { doTheNewThing(); } else { doTheOldThing(); diff --git a/website/docs/sdk-reference/dart.mdx b/website/docs/sdk-reference/dart.mdx index 21293d31f..cfe0a9e71 100644 --- a/website/docs/sdk-reference/dart.mdx +++ b/website/docs/sdk-reference/dart.mdx @@ -74,7 +74,7 @@ final client = ConfigCatClient.get( ```dart final isMyAwesomeFeatureEnabled = await client.getValue(key: 'isMyAwesomeFeatureEnabled', defaultValue: false); -if(isMyAwesomeFeatureEnabled) { +if (isMyAwesomeFeatureEnabled) { doTheNewThing(); } else { doTheOldThing(); diff --git a/website/docs/sdk-reference/dotnet.mdx b/website/docs/sdk-reference/dotnet.mdx index b545f062e..24da989be 100644 --- a/website/docs/sdk-reference/dotnet.mdx +++ b/website/docs/sdk-reference/dotnet.mdx @@ -55,7 +55,7 @@ var client = ConfigCatClient.Get("#YOUR-SDK-KEY#"); ```csharp var isMyAwesomeFeatureEnabled = await client.GetValueAsync("isMyAwesomeFeatureEnabled", false); -if(isMyAwesomeFeatureEnabled) +if (isMyAwesomeFeatureEnabled) { doTheNewThing(); } diff --git a/website/docs/sdk-reference/java.mdx b/website/docs/sdk-reference/java.mdx index 2c370c4c9..0afdc7f9d 100644 --- a/website/docs/sdk-reference/java.mdx +++ b/website/docs/sdk-reference/java.mdx @@ -62,7 +62,7 @@ ConfigCatClient client = ConfigCatClient.get("#YOUR-SDK-KEY#"); ```java boolean isMyAwesomeFeatureEnabled = client.getValue(Boolean.class, "isMyAwesomeFeatureEnabled", false); -if(isMyAwesomeFeatureEnabled) { +if (isMyAwesomeFeatureEnabled) { doTheNewThing(); } else { doTheOldThing(); @@ -183,7 +183,7 @@ client.getValueAsync( User.newBuilder().build("#UNIQUE-USER-IDENTIFIER#"), // Optional User Object false // Default value ).thenAccept(isMyAwesomeFeatureEnabled -> { - if(isMyAwesomeFeatureEnabled) { + if (isMyAwesomeFeatureEnabled) { doTheNewThing(); } else { doTheOldThing(); diff --git a/website/docs/sdk-reference/openfeature/java.mdx b/website/docs/sdk-reference/openfeature/java.mdx index e6f818c1a..5090269df 100644 --- a/website/docs/sdk-reference/openfeature/java.mdx +++ b/website/docs/sdk-reference/openfeature/java.mdx @@ -19,6 +19,7 @@ import TabItem from '@theme/TabItem'; ```groovy title="build.gradle" dependencies { implementation 'dev.openfeature.contrib.providers:configcat:0.0.4' + implementation 'dev.openfeature:sdk:1.+' } ``` @@ -27,9 +28,14 @@ dependencies { ```xml title="pom.xml" - dev.openfeature.contrib.providers - configcat - 0.0.4 + dev.openfeature.contrib.providers + configcat + 0.0.4 + + + dev.openfeature + sdk + [1.0,) ``` @@ -42,10 +48,13 @@ The `ConfigCatProvider` constructor takes a `ConfigCatProviderConfig` argument c ```java // Build options for the ConfigCat SDK. ConfigCatProviderConfig configCatProviderConfig = ConfigCatProviderConfig.builder() - .sdkKey("#YOUR-SDK-KEY#") - .pollingMode(PollingModes.autoPoll()) - .logLevel(LogLevel.WARNING) - .build(); + .sdkKey("#YOUR-SDK-KEY#") + .options(options -> { + options.pollingMode(PollingModes.autoPoll()); + options.logLevel(LogLevel.WARNING); + // ... + }) + .build(); // Configure the provider. OpenFeatureAPI.getInstance().setProviderAndWait(new ConfigCatProvider(configCatProviderConfig)); @@ -60,7 +69,7 @@ For more information about all the configuration options, see the [Java SDK docu ```java boolean isAwesomeFeatureEnabled = client.getBooleanValue("isAwesomeFeatureEnabled", false); -if(isAwesomeFeatureEnabled) +if (isAwesomeFeatureEnabled) { doTheNewThing(); } @@ -70,6 +79,14 @@ else } ``` +### 4. Cleaning up + +On application shutdown, clean up the OpenFeature provider and the underlying ConfigCat client. + +```cs +OpenFeatureAPI.getInstance().shutdown(); +``` + ## Evaluation Context An evaluation context in the OpenFeature specification is a container for arbitrary contextual data that can be used as a basis for feature flag evaluation. @@ -87,11 +104,11 @@ The following table shows how the different context attributes are mapped to Use To evaluate feature flags for a context, use the OpenFeature Evaluation API: ```java -MutableContext evaluationContext = new MutableContext(); -evaluationContext.setTargetingKey("#SOME-USER-ID#"); -evaluationContext.add("Email", "configcat@example.com"); -evaluationContext.add("Country", "CountryID"); -evaluationContext.add("Rating", 4.5); +MutableContext context = new MutableContext(); +context.setTargetingKey("#SOME-USER-ID#"); +context.add("Email", "configcat@example.com"); +context.add("Country", "CountryID"); +context.add("Rating", 4.5); boolean isAwesomeFeatureEnabled = client.getBooleanValue("isAwesomeFeatureEnabled", false, context); ``` diff --git a/website/docs/sdk-reference/openfeature/php.mdx b/website/docs/sdk-reference/openfeature/php.mdx index 994bd9ba7..280a93183 100644 --- a/website/docs/sdk-reference/openfeature/php.mdx +++ b/website/docs/sdk-reference/openfeature/php.mdx @@ -56,7 +56,7 @@ For more information about all the configuration options, see the [PHP SDK docum ```php $isAwesomeFeatureEnabled = $client->getBooleanValue('isAwesomeFeatureEnabled', false); -if(is_bool($isAwesomeFeatureEnabled) && $isAwesomeFeatureEnabled) { +if (is_bool($isAwesomeFeatureEnabled) && $isAwesomeFeatureEnabled) { doTheNewThing(); } else { doTheOldThing(); diff --git a/website/docs/sdk-reference/php.mdx b/website/docs/sdk-reference/php.mdx index 6c99e084c..f9b393632 100644 --- a/website/docs/sdk-reference/php.mdx +++ b/website/docs/sdk-reference/php.mdx @@ -35,7 +35,7 @@ $client = new \ConfigCat\ConfigCatClient("#YOUR-SDK-KEY#"); ```php $isMyAwesomeFeatureEnabled = $client->getValue("isMyAwesomeFeatureEnabled", false); -if(is_bool($isMyAwesomeFeatureEnabled) && $isMyAwesomeFeatureEnabled) { +if (is_bool($isMyAwesomeFeatureEnabled) && $isMyAwesomeFeatureEnabled) { doTheNewThing(); } else { doTheOldThing(); diff --git a/website/versioned_docs/version-V1/sdk-reference/android.mdx b/website/versioned_docs/version-V1/sdk-reference/android.mdx index eab92f943..9e3f15948 100644 --- a/website/versioned_docs/version-V1/sdk-reference/android.mdx +++ b/website/versioned_docs/version-V1/sdk-reference/android.mdx @@ -61,7 +61,7 @@ ConfigCatClient client = ConfigCatClient.get("#YOUR-SDK-KEY#"); ```java boolean isMyAwesomeFeatureEnabled = client.getValue(Boolean.class, "", false); -if(isMyAwesomeFeatureEnabled) { +if (isMyAwesomeFeatureEnabled) { doTheNewThing(); } else { doTheOldThing(); @@ -70,7 +70,7 @@ if(isMyAwesomeFeatureEnabled) { // Or asynchronously client.getValueAsync(Boolean.class, "", false) .thenAccept(isMyAwesomeFeatureEnabled -> { - if(isMyAwesomeFeatureEnabled) { + if (isMyAwesomeFeatureEnabled) { doTheNewThing(); } else { doTheOldThing(); @@ -182,7 +182,7 @@ client.getValueAsync( User.newBuilder().build("#UNIQUE-USER-IDENTIFIER#"), // Optional User Object false // Default value ).thenAccept(isMyAwesomeFeatureEnabled -> { - if(isMyAwesomeFeatureEnabled) { + if (isMyAwesomeFeatureEnabled) { doTheNewThing(); } else { doTheOldThing(); diff --git a/website/versioned_docs/version-V1/sdk-reference/dart.mdx b/website/versioned_docs/version-V1/sdk-reference/dart.mdx index c95ebf449..7b39fd51f 100644 --- a/website/versioned_docs/version-V1/sdk-reference/dart.mdx +++ b/website/versioned_docs/version-V1/sdk-reference/dart.mdx @@ -80,7 +80,7 @@ final client = ConfigCatClient.get( ```dart final isMyAwesomeFeatureEnabled = await client.getValue(key: 'isMyAwesomeFeatureEnabled', defaultValue: false); -if(isMyAwesomeFeatureEnabled) { +if (isMyAwesomeFeatureEnabled) { doTheNewThing(); } else { doTheOldThing(); diff --git a/website/versioned_docs/version-V1/sdk-reference/dotnet.mdx b/website/versioned_docs/version-V1/sdk-reference/dotnet.mdx index 653b795f5..6cf692614 100644 --- a/website/versioned_docs/version-V1/sdk-reference/dotnet.mdx +++ b/website/versioned_docs/version-V1/sdk-reference/dotnet.mdx @@ -61,7 +61,7 @@ var client = ConfigCatClient.Get("#YOUR-SDK-KEY#"); ```csharp var isMyAwesomeFeatureEnabled = client.GetValue("isMyAwesomeFeatureEnabled", false); -if(isMyAwesomeFeatureEnabled) +if (isMyAwesomeFeatureEnabled) { doTheNewThing(); } diff --git a/website/versioned_docs/version-V1/sdk-reference/java.mdx b/website/versioned_docs/version-V1/sdk-reference/java.mdx index 2f2171df8..f76b53d88 100644 --- a/website/versioned_docs/version-V1/sdk-reference/java.mdx +++ b/website/versioned_docs/version-V1/sdk-reference/java.mdx @@ -68,7 +68,7 @@ ConfigCatClient client = ConfigCatClient.get("#YOUR-SDK-KEY#"); ```java boolean isMyAwesomeFeatureEnabled = client.getValue(Boolean.class, "isMyAwesomeFeatureEnabled", false); -if(isMyAwesomeFeatureEnabled) { +if (isMyAwesomeFeatureEnabled) { doTheNewThing(); } else { doTheOldThing(); @@ -188,7 +188,7 @@ client.getValueAsync( User.newBuilder().build("#UNIQUE-USER-IDENTIFIER#"), // Optional User Object false // Default value ).thenAccept(isMyAwesomeFeatureEnabled -> { - if(isMyAwesomeFeatureEnabled) { + if (isMyAwesomeFeatureEnabled) { doTheNewThing(); } else { doTheOldThing(); diff --git a/website/versioned_docs/version-V1/sdk-reference/openfeature/java.mdx b/website/versioned_docs/version-V1/sdk-reference/openfeature/java.mdx index e6f818c1a..5090269df 100644 --- a/website/versioned_docs/version-V1/sdk-reference/openfeature/java.mdx +++ b/website/versioned_docs/version-V1/sdk-reference/openfeature/java.mdx @@ -19,6 +19,7 @@ import TabItem from '@theme/TabItem'; ```groovy title="build.gradle" dependencies { implementation 'dev.openfeature.contrib.providers:configcat:0.0.4' + implementation 'dev.openfeature:sdk:1.+' } ``` @@ -27,9 +28,14 @@ dependencies { ```xml title="pom.xml" - dev.openfeature.contrib.providers - configcat - 0.0.4 + dev.openfeature.contrib.providers + configcat + 0.0.4 + + + dev.openfeature + sdk + [1.0,) ``` @@ -42,10 +48,13 @@ The `ConfigCatProvider` constructor takes a `ConfigCatProviderConfig` argument c ```java // Build options for the ConfigCat SDK. ConfigCatProviderConfig configCatProviderConfig = ConfigCatProviderConfig.builder() - .sdkKey("#YOUR-SDK-KEY#") - .pollingMode(PollingModes.autoPoll()) - .logLevel(LogLevel.WARNING) - .build(); + .sdkKey("#YOUR-SDK-KEY#") + .options(options -> { + options.pollingMode(PollingModes.autoPoll()); + options.logLevel(LogLevel.WARNING); + // ... + }) + .build(); // Configure the provider. OpenFeatureAPI.getInstance().setProviderAndWait(new ConfigCatProvider(configCatProviderConfig)); @@ -60,7 +69,7 @@ For more information about all the configuration options, see the [Java SDK docu ```java boolean isAwesomeFeatureEnabled = client.getBooleanValue("isAwesomeFeatureEnabled", false); -if(isAwesomeFeatureEnabled) +if (isAwesomeFeatureEnabled) { doTheNewThing(); } @@ -70,6 +79,14 @@ else } ``` +### 4. Cleaning up + +On application shutdown, clean up the OpenFeature provider and the underlying ConfigCat client. + +```cs +OpenFeatureAPI.getInstance().shutdown(); +``` + ## Evaluation Context An evaluation context in the OpenFeature specification is a container for arbitrary contextual data that can be used as a basis for feature flag evaluation. @@ -87,11 +104,11 @@ The following table shows how the different context attributes are mapped to Use To evaluate feature flags for a context, use the OpenFeature Evaluation API: ```java -MutableContext evaluationContext = new MutableContext(); -evaluationContext.setTargetingKey("#SOME-USER-ID#"); -evaluationContext.add("Email", "configcat@example.com"); -evaluationContext.add("Country", "CountryID"); -evaluationContext.add("Rating", 4.5); +MutableContext context = new MutableContext(); +context.setTargetingKey("#SOME-USER-ID#"); +context.add("Email", "configcat@example.com"); +context.add("Country", "CountryID"); +context.add("Rating", 4.5); boolean isAwesomeFeatureEnabled = client.getBooleanValue("isAwesomeFeatureEnabled", false, context); ``` diff --git a/website/versioned_docs/version-V1/sdk-reference/openfeature/php.mdx b/website/versioned_docs/version-V1/sdk-reference/openfeature/php.mdx index 994bd9ba7..280a93183 100644 --- a/website/versioned_docs/version-V1/sdk-reference/openfeature/php.mdx +++ b/website/versioned_docs/version-V1/sdk-reference/openfeature/php.mdx @@ -56,7 +56,7 @@ For more information about all the configuration options, see the [PHP SDK docum ```php $isAwesomeFeatureEnabled = $client->getBooleanValue('isAwesomeFeatureEnabled', false); -if(is_bool($isAwesomeFeatureEnabled) && $isAwesomeFeatureEnabled) { +if (is_bool($isAwesomeFeatureEnabled) && $isAwesomeFeatureEnabled) { doTheNewThing(); } else { doTheOldThing(); diff --git a/website/versioned_docs/version-V1/sdk-reference/php.mdx b/website/versioned_docs/version-V1/sdk-reference/php.mdx index 296fdf983..35966d67e 100644 --- a/website/versioned_docs/version-V1/sdk-reference/php.mdx +++ b/website/versioned_docs/version-V1/sdk-reference/php.mdx @@ -41,7 +41,7 @@ $client = new \ConfigCat\ConfigCatClient("#YOUR-SDK-KEY#"); ```php $isMyAwesomeFeatureEnabled = $client->getValue("isMyAwesomeFeatureEnabled", false); -if(is_bool($isMyAwesomeFeatureEnabled) && $isMyAwesomeFeatureEnabled) { +if (is_bool($isMyAwesomeFeatureEnabled) && $isMyAwesomeFeatureEnabled) { doTheNewThing(); } else { doTheOldThing();