The following information is for the latest SDK version (6.x). The CloudBees platform requires that your installed SDK version be at least 6.x. Please install the latest SDK by following the instructions in the platform UI or in the SDK installation documentation. Any updates to version 6.x are noted in the platform changelog. |
Rox Namespace
The Rox
namespace provides an interface for the CloudBees platform to manage feature flags that control the behavior of your application.
This namespace handles communications with the server to obtain the latest flag values, implement flag settings, and set up flag configurations.
The values in the namespace are marked as feature flags and display in the platform UI once the application is run.
These classes and interfaces also allow you to manage custom properties.
These can be static settings of type string, Boolean, integer, or double, or you can use a generator class to provide a custom property that is dependent upon code state.
These generated properties must derive from CustomPropertyGeneratorInterface
.
You can also use an Options
object to configure some aspects of feature flag management.
For example, you can set the custom platform, impression handler, dynamic properties rule, and configuration fetched handler.
Setup
Configures the Rox
object to work with the provided application.
StateCode Setup(const char *api_key, Options *options = nullptr)
Parameter | Modifier and type | Description |
---|---|---|
apiKey |
const char * |
The environment-specific SDK key provided in the UI. |
options |
Options* |
An |
typedef enum RoxStateCode { RoxUninitialized = 0, RoxSettingUp = 1, RoxInitialized = 2, RoxShuttingDown = 3, RoxErrorEmptyApiKey = -1, RoxErrorInvalidApiKey = -2, RoxErrorGenericSetupFailure = -1000 } RoxStateCode;
In case of a successful call, Setup
returns RoxInitialized
code.
Otherwise, the application logs must be analyzed for errors and warnings.
If Setup
returns failure code, it may be called again after fixing the errors from the logs.
SetContext
Sets a global context. This context is available to all flag evaluations, in addition to the specific call context.
void SetContext(Context *context)
Rox::Client namespace
The Rox::Client
namespace is available in addition to its parent Rox
namespace.
It contains client-specific classes and interfaces, and implements features such as flag freeze and flag value overrides.
The client-specific OptionsBuilder
class extends the class of the same name from the parent Rox
namespace.
This class enables you to set the default flag freeze level and other options related to the client-only features.
Custom properties
The role of a custom property is to segment the audience and apply a set of flags for target groups defined by these properties.
Custom properties are any of the following types:
-
bool
-
int
-
double
-
semver
-
string
There are simple (direct) custom properties and calculated ones, using RoxContext
to be more dynamic.
Simple (direct) custom properties
Use as in the following examples.
Computed custom properties (using RoxContext)
Use as in the following examples.
SetCustomComputedProperty
Sets a computed T custom property on the Rox client.
This is a computable T, with an object that generates the value for the property.
The generator must be a delegate of type CustomPropertyGeneratorInterface
.
template<typename T> void SetCustomComputedProperty(const char *name, CustomPropertyGeneratorInterface *generator)
Parameter | Modifier and type | Description |
---|---|---|
name |
const char * |
The name of the property to create. |
generator |
CustomPropertyGeneratorInterface * |
A |
SetCustomComputedSemverProperty
Sets a computed semver custom property on the Rox client.
This is a computable semver, with an object that generates the value for the
property.
The generator must be a delegate of type CustomPropertyGeneratorInterface
.
void SetCustomComputedSemverProperty(const char *name, CustomPropertyGeneratorInterface *generator)
Parameter | Modifier and type | Description |
---|---|---|
name |
string |
The name of the property to create. |
generator |
CustomPropertyGeneratorInterface * |
A |
Class Options
RoxOptions
covers configuration options for the Rox client.
For example, you can set the impression handler and fetch handler.
Instances of this class must be created using OptionsBuilder
.
Set up a new Options
object as in the following example.
This options object sets the version, provides an impression handler, and calls the fetch handler.
Class OptionsBuilder
Use this Builder class to create a new Options
instance.
This class is from the Rox::Client namespace.
|
SetDefaultFreeze
Sets the default freeze level.
OptionsBuilder &SetDefaultFreeze(::Rox::Client::Freeze freeze)
SetVersion
Sets the version of the service running the CloudBees platform SDK. Use in the UI for targeting filtering.
OptionsBuilder &SetVersion(const char *version);
SetFetchInterval
Sets the polling interval for fetching configurations from the CloudBees platform storage service.
OptionsBuilder &SetFetchInterval(int intervalInSeconds)
SetConfigurationFetchedHandler
Sets the configuration event handler to actions after configurations are fetched.
OptionsBuilder &SetConfigurationFetchedHandler(ConfigurationFetchedHandlerInterface *handler)
SetImpressionHandler
Sets the impression event handler to add actions after an impression.
OptionsBuilder &SetImpressionHandler(ImpressionHandlerInterface *handler)
SetDynamicPropertiesRule
The dynamic custom property generator is called when an explicit custom property definition does not exist on the client side.
If you do not set the SetDynamicPropertiesRule
, it activates the
default function, which attempts to extract the value from the context
by its name.
OptionsBuilder &SetDynamicPropertiesRule(DynamicPropertiesRuleInterface *rule)
if (context != NULL) { return rox_context_get(context, prop_name); } return NULL;
Class DynamicPropertiesRuleInterface
Creates a custom dynamic property rule by overriding this class.
Class Flag
Boolean feature flag.
This class is from the Rox::Client namespace.
|
Create
Creates a flag with a default value and freeze level.
static Flag *Create(const char *name, bool defaultValue = false, ::Rox::Client::Freeze freeze = RoxFreezeNone)
IsEnabled
Returns the current value of the feature flag, or the default if no value is set.
bool IsEnabled(Context *context = nullptr)
Unfreeze
Unlocks the flag value from changes from the last time it was frozen.
void Unfreeze(::Rox::Client::Freeze freeze)
Create
Creates a String
with a default value and options.
static Flag *Create(const char *name, bool defaultValue = false) static String *Create(const char *name, const char *defaultValue, const std::vector<std::string> &options);
Unfreeze
Unlocks the flag value from changes from the last time it was frozen.
void Unfreeze(::Rox::Client::Freeze freeze)
Class Int
Int
is a feature flag containing integer values.
This class is from the Rox::Client namespace.
|
GetValue
Returns the current value of the feature flag, or the default if no value is set.
int GetValue(Context *context = nullptr)
Create
Creates a Int
with a default value and options.
static Int *Create(const char *name, int defaultValue) static Int *Create(const char *name, int defaultValue, const std::vector<int> &options);
Unfreeze
Unlocks the flag value from changes from the last time it was frozen.
void Unfreeze(::Rox::Client::Freeze freeze)
Class Double
Double
is a feature flag containing double precision values.
This class is from the Rox::Client namespace.
|
GetValue
Returns the current value of the feature flag, or the default if no value is set.
double GetValue(Context *context = nullptr)
Create
Create a Double
with default value and options.
static Double *Create(const char *name, double defaultValue) static Double *Create(const char *name, double defaultValue, const std::vector<double> &options);
Unfreeze
Unlocks the flag value from changes from the last time it was frozen.
void Unfreeze(::Rox::Client::Freeze freeze)
Class Overrides
Rox::Client::Overrides is used to override a flag value locally. Use only in development, not in production builds.
It is the base API that is used to show the flag update flow. The only way to use overrides is via the code, not the UI.
When you override an existing flag value using the SetOverride
method, the SDK disregards existing configuration from the UI and serializes the override on disk.
This value is loaded and overrides the flag after you call Rox::Setup
.
To clear the override from the cache, call the Clear
method.
This class is from the Rox::Client namespace.
|
SetOverride
Sets an override value on a specific flag.
This function also saves the override value on the local device disk, so it is recalled for the next time the SDK is loaded to production.
void SetOverride(const char *name, const char *value)
Parameter | Modifier and type | Description |
---|---|---|
name |
const char* |
The full flag name including the namespace, for example, |
value |
const char* |
The value of a flag.
If this is a Boolean flag, the value must be |
GetOverride
Returns the overridden flag value or nullptr
, if not yet overridden.
const char *GetOverride(const char *name)
Parameter | Modifier and type | Description |
---|---|---|
name |
const char* |
The full flag name including the namespace, for example, |
Class Context
Use the context class to pass data to the feature flag evaluation.
This object is used by the registered CustomProperties
to evaluate the experiment expression and return the value.
Create a context using the ContextBuilder
.
Class ContextBuilder
The following are simple constructors.
ContextBuilder()
AddBoolValue
Adds a bool value to the name
key in the context.
ContextBuilder &AddBoolValue(const char *name, bool value)
AddIntValue
Adds an int value to the name
key in the context.
ContextBuilder &AddIntValue(const char *name, int value)
AddDoubleValue
Adds a double value to the name
key in the context.
ContextBuilder &AddDoubleValue(const char *name, double value)
AddStringValue
Adds a string value to the name
key in the context.
ContextBuilder &AddStringValue(const char *name, const char *value)
Using ConfigurationFetchedHandler
Use SetConfigurationFetchedHandler`to write a handler for after a new configurations request.
To do so, implement `ConfigurationFetchedHandlerInterface
.
Use as follows:
virtual void ConfigurationFetched(ConfigurationFetchedArgs *args) = 0
For ConfigurationFetchedArgs
, refer to RoxConfigurationFetchedArgs
in the C SDK reference.
Using ImpressionHandler
To use ImpressionHandler
, implement the class ImpressionHandlerInterface
.
virtual void HandleImpression(ReportingValue *value, Experiment *experiment, Context *context) = 0
DynamicApi
An alternative way to evaluate flags and variants by name without having a static container. The dynamic API creates flags as if they were registered, including sending them to the UI.
Create
Creates a dynamicApi, the proxy to all dynamic flag and variant evaluations.
static DynamicApi *Create()
Logging
Logging assists you in debugging in case a flag behaves unexpectedly.
If no logging is set, default is used, which prints to stdout errors level logs.
There are two methods to control logging:
SetLogLevel
To use the default logging, with a different log level.
static void SetLogLevel(LogLevel logLevel)
SetLogMessageHandler
To use a customized logger, provide a class that implements LogMessageHandlerInterface
.
static void SetLogMessageHandler(LogMessageHandlerInterface *handler)
HandleLogMessage
The customized logging handler.
virtual void HandleLogMessage(LogMessage *message) = 0
C++ is a C wrapper. Please refer to the C SDK reference, as some structs have a matching struct without the Rox prefix, for example, |