public interface DataSourceStatusProvider
An implementation of this interface is returned by LDClientInterface.getDataSourceStatusProvider()
.
Application code never needs to implement this interface.
Modifier and Type | Interface and Description |
---|---|
static class |
DataSourceStatusProvider.ErrorInfo
A description of an error condition that the data source encountered.
|
static class |
DataSourceStatusProvider.ErrorKind
An enumeration describing the general type of an error reported in
DataSourceStatusProvider.ErrorInfo . |
static class |
DataSourceStatusProvider.State
An enumeration of possible values for
DataSourceStatusProvider.Status.getState() . |
static class |
DataSourceStatusProvider.Status
Information about the data source's status and about the last status change.
|
static interface |
DataSourceStatusProvider.StatusListener
Interface for receiving status change notifications.
|
Modifier and Type | Method and Description |
---|---|
void |
addStatusListener(DataSourceStatusProvider.StatusListener listener)
Subscribes for notifications of status changes.
|
DataSourceStatusProvider.Status |
getStatus()
Returns the current status of the data source.
|
void |
removeStatusListener(DataSourceStatusProvider.StatusListener listener)
Unsubscribes from notifications of status changes.
|
boolean |
waitFor(DataSourceStatusProvider.State desiredState,
java.time.Duration timeout)
A synchronous method for waiting for a desired connection state.
|
DataSourceStatusProvider.Status getStatus()
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 push
status updates to the SDK; if it does not do so, the status will always be reported as
DataSourceStatusProvider.State.INITIALIZING
.
void addStatusListener(DataSourceStatusProvider.StatusListener listener)
The listener will be notified whenever any property of the status has changed. See DataSourceStatusProvider.Status
for an
explanation of the meaning of each property and what could cause it to change.
Notifications will be dispatched on a worker thread. It is the listener's responsibility to return as soon as possible so as not to block subsequent notifications.
listener
- the listener to addvoid removeStatusListener(DataSourceStatusProvider.StatusListener listener)
listener
- the listener to remove; if no such listener was added, this does nothingboolean waitFor(DataSourceStatusProvider.State desiredState, java.time.Duration timeout) throws java.lang.InterruptedException
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
DataSourceStatusProvider.State.OFF
(since that is a permanent condition), 3. the specified timeout elapses, or 4.
the current thread is deliberately interrupted with Thread.interrupt()
.
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
LDConfig config = new LDConfig.Builder().startWait(Duration.ZERO).build();
client = new LDClient(sdkKey, config);
// later, possibly on another thread:
boolean inited = client.getDataSourceStatusProvider().waitFor(
DataSourceStatusProvider.State.VALID, Duration.ofSeconds(10));
if (!inited) {
// do whatever is appropriate if initialization has timed out
}
desiredState
- the desired connection state (normally this would be DataSourceStatusProvider.State.VALID
)timeout
- the maximum amount of time to wait-- or Duration.ZERO
to block indefinitely
(unless the thread is explicitly interrupted)DataSourceStatusProvider.State.OFF
and that was not the desired statejava.lang.InterruptedException
- if Thread.interrupt()
was called on this thread while blocked