Java Local Server SDK Usage
DevCycleUser Object
The user object is required for all methods. The only required field in the user object is userId.
See the DevCycleUser class in Java DevCycleUser model doc for all accepted fields.
DevCycleUser user = DevCycleUser.builder()
.userId("a_user_id")
.country("US")
.build();
Get and use Variable by key
This method will fetch a specific variable value by key for a given user. The default value will be used in cases where the user is not segmented into a feature using that variable, or the project configuration is unavailable to be fetched from DevCycle's CDN.
Boolean variableValue = client.variableValue(user, "super_cool_feature", true);
if (variableValue.booleanValue()) {
// New Feature code here
} else {
// Old code here
}
The default value can be of type String
, Boolean
, Number
, or Object
.
If you would like to get the full Variable Object you can use variable()
instead. This contains fields such as:
key
, value
, type
, defaultValue
, isDefaulted
.
Getting All Variables
This method will fetch all variables for a given user and returned as Map<String, Feature>. If the project configuration is unavailable, this will return an empty map.
To get values from your Variables, the value
field inside the variable object can be accessed.
Map<String, Variable> variables = client.allVariables(user);