Package io.unlaunch
Class OfflineUnlaunchClient
java.lang.Object
io.unlaunch.OfflineUnlaunchClient
- All Implemented Interfaces:
UnlaunchClient,java.lang.Cloneable
public class OfflineUnlaunchClient extends java.lang.Object implements UnlaunchClient
Offline Unlaunch client which doesn't connect to the Unlauch server over network to download feature flags, nor
does it sends any events or metrics data. By default, it will return default variation for all feature flags. Users
can specify a YAML file containing feature flags and default variations and it will return those when the feature is
evaluated.
- Author:
- umermansoor
-
Constructor Summary
Constructors Constructor Description OfflineUnlaunchClient()OfflineUnlaunchClient(java.lang.String yamlFilePath) -
Method Summary
Modifier and Type Method Description AccountDetailsaccountDetails()Returns account details for the Unlaunch project and environment the client is connected to.voidawaitUntilReady(long timeout, java.util.concurrent.TimeUnit unit)Causes the current thread to wait untilUnlaunchClientis initialized, unless the thread is interrupted, or the specified waiting time elapses.UnlaunchFeaturegetFeature(java.lang.String flagKey, java.lang.String identity)Same asUnlaunchClient.getVariation(String, String)but returns aUnlaunchFeatureobject that contains the evaluated variation (variation key) and any configuration (key, value properties or JSON) associated with the evaluated variation, defined in the Unlaunch web console.UnlaunchFeaturegetFeature(java.lang.String flagKey, java.lang.String identity, UnlaunchAttribute... attributes)Same asUnlaunchClient.getFeature(String, String)but usesattributesthat are passed as argument when evaluating the feature flag's targeting rules.java.lang.StringgetVariation(java.lang.String flagKey, java.lang.String identity)Evaluates and returns the variation (variation key) for this feature.java.lang.StringgetVariation(java.lang.String flagKey, java.lang.String identity, UnlaunchAttribute... attributes)Same asUnlaunchClient.getVariation(String, String)but usesattributesthat are passed as argument when evaluating the feature flag's targeting rules.booleanisReady()Returns true is the client is intialized and ready.voidshutdown()Closes the client by cleaning up all resources such as in memory caches, etc., stops running tasks and rejects any new requests which arrive after this method is called.
-
Constructor Details
-
OfflineUnlaunchClient
public OfflineUnlaunchClient() -
OfflineUnlaunchClient
public OfflineUnlaunchClient(java.lang.String yamlFilePath)
-
-
Method Details
-
accountDetails
Description copied from interface:UnlaunchClientReturns account details for the Unlaunch project and environment the client is connected to.- Specified by:
accountDetailsin interfaceUnlaunchClient- Returns:
AccountDetails
-
getVariation
public java.lang.String getVariation(java.lang.String flagKey, java.lang.String identity)Description copied from interface:UnlaunchClientEvaluates and returns the variation (variation key) for this feature. Variations are defined using the Unlaunch Console at https://app.unlaunch.io.This method returns "control" if:
- The flag was not found.
- There was an exception evaluation the feature flag.
- The flag was archived.
This method doesn't throw any exceptions nor does it return
nullvalue- Specified by:
getVariationin interfaceUnlaunchClient- Parameters:
flagKey- the feature flag you want to evaluate.identity- unique id of your user or a unique identifier such as request or session id, email, etc. It may be null but 'Percentage rollout' will not work because it is used to determine bucketing. If this is null and 'Percentge rollout' is enabled, we'll log exceptions in your code and also in the Unlaunch web app.- Returns:
- the evaluated variation or "control" if there was an error.
-
getVariation
public java.lang.String getVariation(java.lang.String flagKey, java.lang.String identity, UnlaunchAttribute... attributes)Description copied from interface:UnlaunchClientSame asUnlaunchClient.getVariation(String, String)but usesattributesthat are passed as argument when evaluating the feature flag's targeting rules. Targeting rules are defined on the Unlaunch web console. To understand attributes, suppose you have defined a feature flag with targeting rules to return certain variation based on user's country e.g.if country is "USA" AND subscriber is true return "on" otherwise return "off"In this example, country will be subscriber are attributes that must be passed in. If the user is from USA and is subscriber, the "on" variation will be returned. Otherwise, "off".client.getFeature( "show_bonus_pack", userId, UnlaunchAttribute.newString("country", "USA"), UnlaunchAttribute.newBoolean("sbscriber", true) );This method doesn't throw any exceptions nor does it return
nullvalue- Specified by:
getVariationin interfaceUnlaunchClient- Parameters:
flagKey- the feature flag you want to evaluate.identity- unique id of your user or a unique identifier such as request or session id, email, etc. It * may be null but 'Percentage rollout' will not work because it is used to determine bucketing. * If this is null and 'Percentge rollout' is enabled, we'll log exceptions in your code and also * in the Unlaunch web app.attributes- attributes to apply when evaluating target rules.- Returns:
- the evaluated variation or "control" if there was an error.
-
getFeature
Description copied from interface:UnlaunchClientSame asUnlaunchClient.getVariation(String, String)but returns aUnlaunchFeatureobject that contains the evaluated variation (variation key) and any configuration (key, value properties or JSON) associated with the evaluated variation, defined in the Unlaunch web console. For example, to get dynamic configuration associated with a variation, you can:UnlaunchFeature feature = client.getFeature("new_login_ui", userId); String colorHexCode = feature.getVariationConfig().getString("login_button_color", "#cd5c5c"); renderButton(colorHexCode);- Specified by:
getFeaturein interfaceUnlaunchClient- Parameters:
flagKey- the feature flag you want to evaluate.identity- unique id of your user or a unique identifier such as request or session id, email, etc. It may be null but 'Percentage rollout' will not work because it is used to determine bucketing.- Returns:
UnlaunchFeatureobject that contains evaluated variation key, configuration and evaluation reason.
-
getFeature
public UnlaunchFeature getFeature(java.lang.String flagKey, java.lang.String identity, UnlaunchAttribute... attributes)Description copied from interface:UnlaunchClientSame asUnlaunchClient.getFeature(String, String)but usesattributesthat are passed as argument when evaluating the feature flag's targeting rules. Targeting rules are defined on the Unlaunch web console. To understand attributes, suppose you have defined a feature flag with targeting rules to return certain variation based on user's country e.g.if user's country is "USA" AND device is "handheld" return "on" otherwise return "off"In this example, country will be device are attributes that must be passed in.- Specified by:
getFeaturein interfaceUnlaunchClient- Parameters:
flagKey- the feature flag you want to evaluate.identity- unique id of your user or a unique identifier such as request or session id, email, etc. It may be null but 'Percentage rollout' will not work because it is used to determine bucketing.attributes- an array of attributes to evaluate against- Returns:
UnlaunchFeatureobject that contains evaluated variation key, configuration and evaluation reason.
-
awaitUntilReady
public void awaitUntilReady(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException, java.util.concurrent.TimeoutExceptionDescription copied from interface:UnlaunchClientCauses the current thread to wait untilUnlaunchClientis initialized, unless the thread is interrupted, or the specified waiting time elapses.If the current thread:
- has its interrupted status set on entry to this method; or
- is interrupted while waiting,
then
InterruptedExceptionis thrown and the current thread's interrupted status is cleared.- Specified by:
awaitUntilReadyin interfaceUnlaunchClient- Parameters:
timeout- the maximum time to waitunit- the time unit of the timeout argument- Throws:
java.lang.InterruptedException- if the current thread is interrupted while waitingjava.util.concurrent.TimeoutException- if it times out before initialization is complete
-
isReady
public boolean isReady()Description copied from interface:UnlaunchClientReturns true is the client is intialized and ready. False otherwise.Initialized means that the client was able to download flags and data from the Unlaunch server at leasr once.
- Specified by:
isReadyin interfaceUnlaunchClient- Returns:
-
shutdown
public void shutdown()Description copied from interface:UnlaunchClientCloses the client by cleaning up all resources such as in memory caches, etc., stops running tasks and rejects any new requests which arrive after this method is called.The default behavior of this method is to block until everything has been shutdown or it encountered an error or timed out (usually a few seconds.)
- Specified by:
shutdownin interfaceUnlaunchClient
-