Interface Status.DataUpdateStatusProvider

Enclosing class:
Status

public static interface Status.DataUpdateStatusProvider
An interface to query the status of a DataSynchronizer With the build-in implementation, this might be useful if you want to use SDK without waiting for it to initialize
  • Method Details

    • getState

      Status.State getState()
      Returns the current status of the DataSynchronizer

      All of the DataSynchronizer implementations are guaranteed to update this status whenever they successfully initialize, encounter an error, or recover after an error.

      For a custom implementation, it is the responsibility of the data source to report its status via Status.DataUpdater; if it does not do so, the status will always be reported as Status.StateType.INITIALIZING.

      Returns:
      the latest status; will never be null
    • waitFor

      boolean waitFor(Status.StateType state, Duration timeout) throws InterruptedException
      A method for waiting for a desired connection state after bootstrapping

      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 Status.StateType.OFF , 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 use SDK without waiting for it to initialize, and then wait for initialization at a later time or on a different point:

      
           FBConfig config = new FBConfig.Builder()
               .startWait(Duration.ZERO)
               .build();
           FBClient client = new FBClient(sdkKey, config);
      
           // later, when you want to wait for initialization to finish:
           boolean inited = client.getDataUpdateStatusProvider().waitFor(StateType.OK, Duration.ofSeconds(15))
           if (!inited) {
               // do whatever is appropriate if initialization has timed out
           }
       
      Parameters:
      state - the desired connection state (normally this would be Status.StateType.OK)
      timeout - the maximum amount of time to wait-- or Duration.ZERO to block indefinitely (unless the thread is explicitly interrupted)
      Returns:
      true if the connection is now in the desired state; false if it timed out, or if the state changed to 2 and that was not the desired state
      Throws:
      InterruptedException - if Thread.interrupt() was called on this thread while blocked
    • waitForOKState

      boolean waitForOKState(Duration timeout) throws InterruptedException
      Parameters:
      timeout - the maximum amount of time to wait-- or Duration.ZERO to block indefinitely (unless the thread is explicitly interrupted)
      Returns:
      true if the connection is now in Status.StateType.OK; false if it timed out, or if the state changed to Status.StateType.OFF and that was not the desired state
      Throws:
      InterruptedException - throws an InterruptedException