Class FBClientImp
- All Implemented Interfaces:
FBClient,Closeable,AutoCloseable
-
Constructor Summary
ConstructorsConstructorDescriptionFBClientImp(String envSecret, FBConfig config) Creates a new client to connect to feature flag center with a specified configuration. -
Method Summary
Modifier and TypeMethodDescriptionbooleanboolVariation(String featureFlagKey, FBUser user, Boolean defaultValue) Calculates the boolean value of a feature flag for a given user.boolVariationDetail(String featureFlagKey, FBUser user, Boolean defaultValue) Calculates the value of a feature flag for a given user, and returns an object that describes the way the value was determined.voidclose()doubledoubleVariation(String featureFlagKey, FBUser user, Double defaultValue) Calculates the double value of a feature flag for a given user.doubleVariationDetail(String featureFlagKey, FBUser user, Double defaultValue) Calculates the double value of a feature flag for a given user, and returns an object that describes the way the value was determined.voidflush()Flushes all pending events.Returns a list of all feature flags value with details for a given user, including the reason that describes the way the value was determined, that can be used on the client side sdk or a front end .Returns an interface for tracking the status of the update processor.voidregister a userbooleaninitialization in the offline modeintintVariation(String featureFlagKey, FBUser user, Integer defaultValue) Calculates the integer value of a feature flag for a given user.intVariationDetail(String featureFlagKey, FBUser user, Integer defaultValue) Calculates the int value of a feature flag for a given user, and returns an object that describes the way the value was determined.booleanalias of boolVariation for a given userbooleanisFlagKnown(String featureKey) Returns true if the specified feature flag currently exists.booleanTests whether the client is ready to be used.boolean<T> TjsonVariation(String featureFlagKey, FBUser user, Class<T> clazz, T defaultValue) Calculates the json value of a feature flag for a given user.<T> FlagState<T>jsonVariationDetail(String featureFlagKey, FBUser user, Class<T> clazz, T defaultValue) Calculates the json value of a feature flag for a given user, and returns an object that describes the way the value was determined.longlongVariation(String featureFlagKey, FBUser user, Long defaultValue) Calculates the long value of a feature flag for a given user.longVariationDetail(String featureFlagKey, FBUser user, Long defaultValue) Calculates the long value of a feature flag for a given user, and returns an object that describes the way the value was determined.voidtrackMetric(FBUser user, String eventName) tracks that a user performed an event and provides a default numeric value for custom metricsvoidtrackMetric(FBUser user, String eventName, double metricValue) tracks that a user performed an event, and provides an additional numeric value for custom metrics.voidtrackMetrics(FBUser user, String... eventNames) tracks that a user performed a series of events with default numeric value for custom metricsvoidtrackMetrics(FBUser user, Map<String, Double> metrics) tracks that a user performed a series of eventsCalculates the value of a feature flag for a given user.variationDetail(String featureFlagKey, FBUser user, String defaultValue) Calculates the value of a feature flag for a given user, and returns an object that describes the way the value was determined.
-
Constructor Details
-
FBClientImp
Creates a new client to connect to feature flag center with a specified configuration.This constructor can be used to configure advanced SDK features; see
FBConfig.Builder.Applications SHOULD instantiate a single instance for the lifetime of the application. In the case where an application needs to evaluate feature flags from different environments, you may create multiple clients, but they should still be retained for the lifetime of the application rather than created per request or per thread.
Note that unless client is configured in offline mode
FBConfig.Builder.offline(boolean)or set byFactory.externalDataSynchronization(), this client try to connect to feature flag center as soon as the constructor is called. The constructor will return when it successfully connects, or when the timeout set byFBConfig.Builder.startWaitTime(Duration)(default: 15 seconds) expires, whichever comes first. If it has not succeeded in connecting when the timeout elapses, you will receive the client in an uninitialized state where feature flags will return default values; it will still continue trying to connect in the background unless there has been anProtocolExceptionor you close the clientclose(). You can detect whether initialization has succeeded by callingisInitialized().If you prefer to have the constructor return immediately, and then wait for initialization to finish at some other point, you can use
getDataUpdateStatusProvider()as follows:FBConfig config = new FBConfig.Builder() .startWait(Duration.ZERO) .streamingURI("your streaming URI") .eventURI("your event URI") .build(); FBClient client = new FBClientImp(sdkKey, config); // later, when you want to wait for initialization to finish: boolean inited = client.getDataUpdateStatusProvider().waitForOKState(Duration.ofSeconds(15)) if (!inited) { // do whatever is appropriate if initialization has timed out }This constructor can throw unchecked exceptions if it is immediately apparent that the SDK cannot work with these parameters. In fact, if the env secret is not valid, it will throw an
IllegalArgumentExceptiona null value for a non-nullable parameter may throw aNullPointerException. The constructor will not throw any exception that could only be detected after making a request to our API- Parameters:
envSecret- the secret key for your own environmentconfig- a client configuration objectFBConfig- Throws:
NullPointerException- if a non-nullable parameter was nullIllegalArgumentException- if envSecret is invalid
-
-
Method Details
-
isInitialized
public boolean isInitialized()Description copied from interface:FBClientTests whether the client is ready to be used.- Specified by:
isInitializedin interfaceFBClient- Returns:
- true if the client is ready, or false if it is still initializing
-
variation
Description copied from interface:FBClientCalculates the value of a feature flag for a given user. -
variationDetail
Description copied from interface:FBClientCalculates the value of a feature flag for a given user, and returns an object that describes the way the value was determined.- Specified by:
variationDetailin interfaceFBClient- Parameters:
featureFlagKey- the unique key for the feature flaguser- the end user requesting the flagdefaultValue- the default value of the flag- Returns:
- an
FlagStateobject
-
boolVariation
Description copied from interface:FBClientCalculates the boolean value of a feature flag for a given user.- Specified by:
boolVariationin interfaceFBClient- Parameters:
featureFlagKey- the unique key for the feature flaguser- the end user requesting the flagdefaultValue- the default value of the flag- Returns:
- if the flag should be enabled, or
defaultValueif the flag is disabled or an error occurs
-
isEnabled
Description copied from interface:FBClientalias of boolVariation for a given user -
boolVariationDetail
public FlagState<Boolean> boolVariationDetail(String featureFlagKey, FBUser user, Boolean defaultValue) Description copied from interface:FBClientCalculates the value of a feature flag for a given user, and returns an object that describes the way the value was determined.- Specified by:
boolVariationDetailin interfaceFBClient- Parameters:
featureFlagKey- the unique key for the feature flaguser- the end user requesting the flagdefaultValue- the default value of the flag- Returns:
- an
FlagStateobject
-
doubleVariation
Description copied from interface:FBClientCalculates the double value of a feature flag for a given user.- Specified by:
doubleVariationin interfaceFBClient- Parameters:
featureFlagKey- the unique key for the feature flaguser- the end user requesting the flagdefaultValue- the default value of the flag- Returns:
- the variation for the given user, or
defaultValueif the flag is disabled or an error occurs
-
doubleVariationDetail
public FlagState<Double> doubleVariationDetail(String featureFlagKey, FBUser user, Double defaultValue) Description copied from interface:FBClientCalculates the double value of a feature flag for a given user, and returns an object that describes the way the value was determined.- Specified by:
doubleVariationDetailin interfaceFBClient- Parameters:
featureFlagKey- the unique key for the feature flaguser- the end user requesting the flagdefaultValue- the default value of the flag- Returns:
- an
FlagStateobject
-
intVariation
Description copied from interface:FBClientCalculates the integer value of a feature flag for a given user. Note that If the variation has a numeric value, but not an integer, it is rounded toward zero(DOWN mode)- Specified by:
intVariationin interfaceFBClient- Parameters:
featureFlagKey- the unique key for the feature flaguser- the end user requesting the flagdefaultValue- the default value of the flag- Returns:
- the variation for the given user, or
defaultValueif the flag is disabled or an error occurs
-
intVariationDetail
public FlagState<Integer> intVariationDetail(String featureFlagKey, FBUser user, Integer defaultValue) Description copied from interface:FBClientCalculates the int value of a feature flag for a given user, and returns an object that describes the way the value was determined.Note that If the variation has a numeric value, but not an int value, it is rounded toward zero(DOWN mode)
- Specified by:
intVariationDetailin interfaceFBClient- Parameters:
featureFlagKey- the unique key for the feature flaguser- the end user requesting the flagdefaultValue- the default value of the flag- Returns:
- an
FlagStateobject
-
longVariation
Description copied from interface:FBClientCalculates the long value of a feature flag for a given user. Note that If the variation has a numeric value, but not a long value, it is rounded toward zero(DOWN mode)- Specified by:
longVariationin interfaceFBClient- Parameters:
featureFlagKey- the unique key for the feature flaguser- the end user requesting the flagdefaultValue- the default value of the flag- Returns:
- the variation for the given user, or
defaultValueif the flag is disabled or an error occurs
-
longVariationDetail
Description copied from interface:FBClientCalculates the long value of a feature flag for a given user, and returns an object that describes the way the value was determined.Note that If the variation has a numeric value, but not a long value, it is rounded toward zero(DOWN mode)
- Specified by:
longVariationDetailin interfaceFBClient- Parameters:
featureFlagKey- the unique key for the feature flaguser- the end user requesting the flagdefaultValue- the default value of the flag- Returns:
- an
FlagStateobject
-
jsonVariation
Description copied from interface:FBClientCalculates the json value of a feature flag for a given user.- Specified by:
jsonVariationin interfaceFBClient- Type Parameters:
T- json object type- Parameters:
featureFlagKey- the unique key for the feature flaguser- the end user requesting the flagclazz- json deserialization classdefaultValue- the default value of the flag- Returns:
- the variation for the given user, or
defaultValueif the flag is disabled, current user doesn't exist
-
jsonVariationDetail
public <T> FlagState<T> jsonVariationDetail(String featureFlagKey, FBUser user, Class<T> clazz, T defaultValue) Description copied from interface:FBClientCalculates the json value of a feature flag for a given user, and returns an object that describes the way the value was determined.- Specified by:
jsonVariationDetailin interfaceFBClient- Type Parameters:
T- json object type- Parameters:
featureFlagKey- the unique key for the feature flaguser- the end user requesting the flagclazz- json deserialization classdefaultValue- the default value of the flag- Returns:
- an
FlagStateobject
-
isFlagKnown
Description copied from interface:FBClientReturns true if the specified feature flag currently exists.- Specified by:
isFlagKnownin interfaceFBClient- Parameters:
featureKey- the unique key for the feature flag- Returns:
- true if the flag exists
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
isOffline
public boolean isOffline() -
getDataUpdateStatusProvider
Description copied from interface:FBClientReturns an interface for tracking the status of the update processor.The update processor is the mechanism that the SDK uses to get feature flag, such as a streaming connection. The
Status.DataUpdateStatusProvideris used to check whether the update processor is currently operational- Specified by:
getDataUpdateStatusProviderin interfaceFBClient- Returns:
- a
Status.DataUpdateStatusProvider
-
initializeFromExternalJson
Description copied from interface:FBClientinitialization in the offline mode- Specified by:
initializeFromExternalJsonin interfaceFBClient- Parameters:
json- feature flags in the json format- Returns:
- true if the initialization is well done
-
getAllLatestFlagsVariations
Description copied from interface:FBClientReturns a list of all feature flags value with details for a given user, including the reason that describes the way the value was determined, that can be used on the client side sdk or a front end .note that this method does not send insight events back to feature flag center.
- Specified by:
getAllLatestFlagsVariationsin interfaceFBClient- Parameters:
user- the end user requesting the flag- Returns:
- a
AllFlagStates
-
flush
public void flush()Description copied from interface:FBClientFlushes all pending events. -
identify
Description copied from interface:FBClientregister a user -
trackMetric
Description copied from interface:FBClienttracks that a user performed an event and provides a default numeric value for custom metrics- Specified by:
trackMetricin interfaceFBClient- Parameters:
user- the user that performed the eventeventName- the name of the event
-
trackMetric
Description copied from interface:FBClienttracks that a user performed an event, and provides an additional numeric value for custom metrics.- Specified by:
trackMetricin interfaceFBClient- Parameters:
user- the user that performed the eventeventName- the name of the eventmetricValue- a numeric value used by the experimentation feature in numeric custom metrics.
-
trackMetrics
Description copied from interface:FBClienttracks that a user performed a series of events with default numeric value for custom metrics- Specified by:
trackMetricsin interfaceFBClient- Parameters:
user- the user that performed the eventeventNames- event names
-
trackMetrics
Description copied from interface:FBClienttracks that a user performed a series of events- Specified by:
trackMetricsin interfaceFBClient- Parameters:
user- the user that performed the eventmetrics- event name and numeric value in K/V
-