Interface IDataSourceStatusProvider
An interface for querying the status of the SDK's data source.
Namespace: LaunchDarkly.Sdk.Client.Interfaces
Assembly: LaunchDarkly.ClientSdk.dll
Syntax
public interface IDataSourceStatusProvider
Remarks
The data source is the component that receives updates to feature flag data. Normally this is a streaming connection, but it could be polling or test data depending on your configuration.
An implementation of this interface is returned by DataSourceStatusProvider. Application code never needs to implement this interface.
Properties
| Edit this page View SourceStatus
The current status of the data source.
Declaration
DataSourceStatus Status { get; }
Property Value
Type | Description |
---|---|
DataSourceStatus |
Remarks
All of the built-in data source implementations are guaranteed to update this status whenever they successfully initialize, encounter an error, or recover after an error.
For a custom data source implementation, it is the responsibility of the data source to report its status via IDataSourceUpdateSink; if it does not do so, the status will always be reported as Initializing.
Methods
| Edit this page View SourceWaitFor(DataSourceState, TimeSpan)
A synchronous method for waiting for a desired connection state.
Declaration
bool WaitFor(DataSourceState desiredState, TimeSpan timeout)
Parameters
Type | Name | Description |
---|---|---|
DataSourceState | desiredState | the desired connection state (normally this would be Valid) |
TimeSpan | timeout | the maximum amount of time to wait-- or Zero to block indefinitely |
Returns
Type | Description |
---|---|
bool | true if the connection is now in the desired state; false if it timed out, or if the state changed to Shutdown and that was not the desired state |
Remarks
If the current state is already desiredState
when this method is called, it immediately
returns. Otherwise, it blocks until 1. the state has become desiredState
, 2. the state
has become Shutdown (since that is a permanent condition), or 3. the specified
timeout elapses.
A scenario in which this might be useful is if you want to create the LdClient without waiting for it to initialize, and then wait for initialization at a later time or on a different thread:
// create the client but do not wait
var config = Configuration.Builder("my-sdk-key").StartWaitTime(TimeSpan.Zero).Build();
var client = new LDClient(config);
// later, possibly on another thread:
var inited = client.DataSourceStatusProvider.WaitFor(DataSourceState.Valid,
TimeSpan.FromSeconds(10));
if (!inited) {
// do whatever is appropriate if initialization has timed out
}
See Also
| Edit this page View SourceWaitForAsync(DataSourceState, TimeSpan)
An asynchronous method for waiting for a desired connection state.
Declaration
Task<bool> WaitForAsync(DataSourceState desiredState, TimeSpan timeout)
Parameters
Type | Name | Description |
---|---|---|
DataSourceState | desiredState | the desired connection state (normally this would be Valid) |
TimeSpan | timeout | the maximum amount of time to wait-- or Zero to block indefinitely |
Returns
Type | Description |
---|---|
Task<bool> | true if the connection is now in the desired state; false if it timed out, or if the state changed to Shutdown and that was not the desired state |
Remarks
This method behaves identically to WaitFor(DataSourceState, TimeSpan) except that it is asynchronous. The following example is the asynchronous equivalent of the example code shown for WaitFor(DataSourceState, TimeSpan):
// create the client but do not wait
var config = Configuration.Builder("my-sdk-key").StartWaitTime(TimeSpan.Zero).Build();
var client = new LDClient(config);
// later, possibly on another thread:
var inited = await client.DataSourceStatusProvider.WaitFor(DataSourceState.Valid,
TimeSpan.FromSeconds(10));
if (!inited) {
// do whatever is appropriate if initialization has timed out
}
See Also
Events
| Edit this page View SourceStatusChanged
An event for receiving notifications of status changes.
Declaration
event EventHandler<DataSourceStatus> StatusChanged
Event Type
Type | Description |
---|---|
EventHandler<DataSourceStatus> |
Remarks
Any handlers attached to this event will be notified whenever any property of the status has changed. See DataSourceStatusfor an explanation of the meaning of each property and what could cause it to change.
Notifications will be dispatched either on the main thread (on mobile platforms) or in a background task (on all other platforms). It is the listener's responsibility to return as soon as possible so as not to block subsequent notifications.