docs: add try-catch example for setProviderAndWait usage (#1433)
* added the detailed instructions for the setProviderAndWait Signed-off-by: Abhay <abhayakg123@gmail.com.com> * fixup: checkstyle issues Signed-off-by: Simon Schrottner <simon.schrottner@dynatrace.com> --------- Signed-off-by: Abhay <abhayakg123@gmail.com.com> Signed-off-by: Simon Schrottner <simon.schrottner@dynatrace.com> Co-authored-by: Abhay <abhayakg123@gmail.com.com> Co-authored-by: Simon Schrottner <simon.schrottner@dynatrace.com>
This commit is contained in:
parent
99faaf88aa
commit
96cf9c7f54
14
README.md
14
README.md
|
|
@ -104,7 +104,12 @@ public void example(){
|
|||
|
||||
// configure a provider
|
||||
OpenFeatureAPI api = OpenFeatureAPI.getInstance();
|
||||
api.setProviderAndWait(new InMemoryProvider(myFlags));
|
||||
try {
|
||||
api.setProviderAndWait(new InMemoryProvider(myFlags));
|
||||
} catch (Exception e) {
|
||||
// handle initialization failure
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// create a client
|
||||
Client client = api.getClient();
|
||||
|
|
@ -149,7 +154,12 @@ To register a provider in a blocking manner to ensure it is ready before further
|
|||
|
||||
```java
|
||||
OpenFeatureAPI api = OpenFeatureAPI.getInstance();
|
||||
api.setProviderAndWait(new MyProvider());
|
||||
try {
|
||||
api.setProviderAndWait(new MyProvider());
|
||||
} catch (Exception e) {
|
||||
// handle initialization failure
|
||||
e.printStackTrace();
|
||||
}
|
||||
```
|
||||
|
||||
#### Asynchronous
|
||||
|
|
|
|||
|
|
@ -207,7 +207,13 @@ public class OpenFeatureAPI implements EventBus<OpenFeatureAPI> {
|
|||
}
|
||||
|
||||
/**
|
||||
* Set the default provider and wait for initialization to finish.
|
||||
* Sets the default provider and waits for its initialization to complete.
|
||||
*
|
||||
* <p>Note: If the provider fails during initialization, an {@link OpenFeatureError} will be thrown.
|
||||
* It is recommended to wrap this call in a try-catch block to handle potential initialization failures gracefully.
|
||||
*
|
||||
* @param provider the {@link FeatureProvider} to set as the default.
|
||||
* @throws OpenFeatureError if the provider fails during initialization.
|
||||
*/
|
||||
public void setProviderAndWait(FeatureProvider provider) throws OpenFeatureError {
|
||||
try (AutoCloseableLock __ = lock.writeLockAutoCloseable()) {
|
||||
|
|
@ -224,8 +230,12 @@ public class OpenFeatureAPI implements EventBus<OpenFeatureAPI> {
|
|||
/**
|
||||
* Add a provider for a domain and wait for initialization to finish.
|
||||
*
|
||||
* <p>Note: If the provider fails during initialization, an {@link OpenFeatureError} will be thrown.
|
||||
* It is recommended to wrap this call in a try-catch block to handle potential initialization failures gracefully.
|
||||
*
|
||||
* @param domain The domain to bind the provider to.
|
||||
* @param provider The provider to set.
|
||||
* @throws OpenFeatureError if the provider fails during initialization.
|
||||
*/
|
||||
public void setProviderAndWait(String domain, FeatureProvider provider) throws OpenFeatureError {
|
||||
try (AutoCloseableLock __ = lock.writeLockAutoCloseable()) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue