-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
chris-hoefgen
committed
Oct 24, 2023
1 parent
895d01e
commit 6986077
Showing
7 changed files
with
93 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,35 +21,37 @@ public static void main(String[] args) throws InterruptedException { | |
System.exit(1); | ||
} | ||
|
||
DevCycleLocalOptions options = DevCycleLocalOptions.builder().configPollingIntervalMs(60000) | ||
DevCycleLocalOptions options = DevCycleLocalOptions.builder().configPollingIntervalMS(60000) | ||
.disableAutomaticEventLogging(false).disableCustomEventLogging(false).build(); | ||
|
||
// Initialize DevCycle Client | ||
DevCycleLocalClient devCycleClient = new DevCycleLocalClient(server_sdk_key, options); | ||
|
||
OpenFeatureAPI api = OpenFeatureAPI.getInstance(); | ||
|
||
for (int i = 0; i < 10; i++) { | ||
if(devCycleClient.isInitialized()) { | ||
if (devCycleClient.isInitialized()) { | ||
break; | ||
} | ||
Thread.sleep(500); | ||
} | ||
|
||
Map<String, Value> apiAttrs = new LinkedHashMap(); | ||
// Setup OpenFeature with the DevCycle Provider | ||
OpenFeatureAPI api = OpenFeatureAPI.getInstance(); | ||
api.setProvider(new DevCycleProvider(devCycleClient)); | ||
|
||
// Create the evaluation context to use for fetching variable values | ||
Map<String, Value> apiAttrs = new LinkedHashMap<>(); | ||
apiAttrs.put("email", new Value("[email protected]")); | ||
apiAttrs.put("country", new Value("US")); | ||
|
||
EvaluationContext ctx = new ImmutableContext("test-1234", apiAttrs); | ||
EvaluationContext context = new ImmutableContext("test-1234", apiAttrs); | ||
|
||
// The default value can be of type string, boolean, number, or JSON | ||
Boolean defaultValue = false; | ||
|
||
api.setProvider(new DevCycleProvider(devCycleClient)); | ||
|
||
// Fetch variable values using the identifier key, with a default value and user | ||
// object. The default value can be of type string, boolean, number, or JSON | ||
Boolean variableValue = api.getClient().getBooleanValue(VARIABLE_KEY, defaultValue, ctx); | ||
Boolean variableValue = api.getClient().getBooleanValue(VARIABLE_KEY, defaultValue, context); | ||
|
||
// Use variable value | ||
if (variableValue) { | ||
|
33 changes: 28 additions & 5 deletions
33
src/main/java/com/devcycle/sdk/server/common/api/IDevCycleClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,38 @@ | ||
package com.devcycle.sdk.server.common.api; | ||
|
||
import com.devcycle.sdk.server.common.exception.DevCycleException; | ||
import com.devcycle.sdk.server.common.model.DevCycleUser; | ||
import com.devcycle.sdk.server.common.model.Variable; | ||
|
||
/** | ||
* Base interface for DevCycle clients that can be used to evaluate Features and retrieve variables values. | ||
*/ | ||
public interface IDevCycleClient { | ||
public boolean isInitialized(); | ||
/** | ||
* @return true if the client is initialized and ready to be used. Clients should | ||
* return a default value if they are not initialized. | ||
*/ | ||
boolean isInitialized(); | ||
|
||
public <T> T variableValue(DevCycleUser user, String key, T defaultValue); | ||
/** | ||
* @param user (required) The user context for the evaluation. | ||
* @param key (required) The key of the feature variable to evaluate. | ||
* @param defaultValue (required) The default value to return if the feature variable is not found or the user | ||
* does not segment into the feature | ||
* @return the value of the variable for the given user, or the default value if the variable is not found. | ||
*/ | ||
<T> T variableValue(DevCycleUser user, String key, T defaultValue); | ||
|
||
public <T> Variable<T> variable(DevCycleUser user, String key, T defaultValue); | ||
/** | ||
* @param user (required) The user context for the evaluation. | ||
* @param key (required) The key of the feature variable to evaluate. | ||
* @param defaultValue (required) The default value to return if the feature variable is not found or the user | ||
* does not segment into the feature | ||
* @return the variable for the given user, or the default variable if the variable is not found. | ||
*/ | ||
<T> Variable<T> variable(DevCycleUser user, String key, T defaultValue); | ||
|
||
public void close(); | ||
/** | ||
* Close the client and release any resources. | ||
*/ | ||
void close(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.