Class ClientContext
LDClient
when
creating components.
The getter methods in this class provide information about the initial configuration of the
client, as well as its current state. This includes properties from LDConfig
, and also
values that are computed during initialization. It is preferable for components to copy
properties from this class rather than to retain a reference to the entire LDConfig
object.
The actual implementation class may contain other properties that are only relevant to the built-in SDK components and are therefore not part of this base class; this allows the SDK to add its own context information as needed without disturbing the public API.
- Since:
- 3.3.0
-
Constructor Summary
ModifierConstructorDescriptionprotected
ClientContext
(ClientContext copy) ClientContext
(String mobileKey, IEnvironmentReporter environmentReporter, LDLogger baseLogger, LDConfig config, DataSourceUpdateSink dataSourceUpdateSink, String environmentName, boolean evaluationReasons, LDContext evaluationContext, HttpConfiguration http, boolean inBackground, Boolean previouslyInBackground, ServiceEndpoints serviceEndpoints, boolean setOffline) Constructs an instance, specifying all properties. -
Method Summary
Modifier and TypeMethodDescriptionThe base logger for the SDK.Returns the full configuration object.Returns the configured environment name.Returns the current evaluation context as of the time that this component was created.getHttp()
Returns the HTTP configuration.Returns the configured mobile key.Returns the previous background state.Returns the base service URIs used by SDK components.boolean
Returns true if evaluation reasons are enabled.boolean
Returns true if the application was in the background at the time that this component was created.boolean
Returns true if the application has specified that the SDK should be offline.protected ClientContext
setEvaluationContext
(LDContext context) Sets the evaluation context and returns a new instance ofClientContext
-
Constructor Details
-
ClientContext
public ClientContext(String mobileKey, IEnvironmentReporter environmentReporter, LDLogger baseLogger, LDConfig config, DataSourceUpdateSink dataSourceUpdateSink, String environmentName, boolean evaluationReasons, LDContext evaluationContext, HttpConfiguration http, boolean inBackground, Boolean previouslyInBackground, ServiceEndpoints serviceEndpoints, boolean setOffline) Constructs an instance, specifying all properties.- Parameters:
mobileKey
- seegetMobileKey()
environmentReporter
- seegetEnvironmentReporter()
baseLogger
- seegetBaseLogger()
config
- seegetConfig()
dataSourceUpdateSink
- seegetDataSourceUpdateSink()
environmentName
- seegetEnvironmentName()
evaluationReasons
- seeisEvaluationReasons()
evaluationContext
- seegetEvaluationContext()
http
- seegetHttp()
inBackground
- seeisInBackground()
previouslyInBackground
- seegetPreviouslyInBackground()
serviceEndpoints
- seegetServiceEndpoints()
setOffline
- seeisSetOffline()
-
ClientContext
- Parameters:
copy
- theClientContext
to copy
-
-
Method Details
-
setEvaluationContext
Sets the evaluation context and returns a new instance ofClientContext
- Parameters:
context
- to now use as the evaluation context- Returns:
- a new instance
-
getEnvironmentReporter
- Returns:
- the
IEnvironmentReporter
for this client context
-
getBaseLogger
The base logger for the SDK.- Returns:
- a logger instance
-
getConfig
Returns the full configuration object. THIS IS A TEMPORARY METHOD that will be removed prior to release-- the goal is to NOT retain the full LDConfig in these components, but until we have moved more of the config properties into subconfiguration builders, this is necessary.- Returns:
- the configuration object
-
getDataSourceUpdateSink
- Returns:
- the
DataSourceUpdateSink
-
getEnvironmentName
Returns the configured environment name.- Returns:
- the environment name
-
isEvaluationReasons
public boolean isEvaluationReasons()Returns true if evaluation reasons are enabled.- Returns:
- true if evaluation reasons are enabled
-
getHttp
Returns the HTTP configuration.- Returns:
- the HTTP configuration
-
getEvaluationContext
Returns the current evaluation context as of the time that this component was created.- Returns:
- the current evaluation context
-
isInBackground
public boolean isInBackground()Returns true if the application was in the background at the time that this component was created.- Returns:
- true if in the background
-
getMobileKey
Returns the configured mobile key.In multi-environment mode, there is a separate
ClientContext
for each environment, corresponding to theLDClient
instance for that environment.- Returns:
- the mobile key
-
getPreviouslyInBackground
Returns the previous background state.This is initially null when the SDK is initialized. It is set to
true
orfalse
when the SDK is restarting the data source due to a state change, in case the data source might need to have different behavior depending on whether the state change included a change in foreground/background state.- Returns:
true
if the application was in the background before the time that this component was created;false
if it was in the foreground; ornull
if this is the first time the component is being created during the lifetime of the SDK
-
getServiceEndpoints
Returns the base service URIs used by SDK components.- Returns:
- the service endpoint URIs
-
isSetOffline
public boolean isSetOffline()Returns true if the application has specified that the SDK should be offline.- Returns:
- true if set to be offline
-