Interface LDClientInterface

  • All Superinterfaces:
    java.lang.AutoCloseable, java.io.Closeable
    All Known Implementing Classes:
    LDClient

    public interface LDClientInterface
    extends java.io.Closeable
    The interface for the LaunchDarkly SDK client.

    To obtain a client instance, use LDClient methods such as LDClient.init(Application, LDConfig, LDUser).

    • Method Detail

      • isInitialized

        boolean isInitialized()
        Checks whether the client is ready to return feature flag values. This is true if either the client has successfully connected to LaunchDarkly and received feature flags, or the client has been put into offline mode (in which case it will return only default flag values).
        Returns:
        true if the client is initialized or offline
      • isOffline

        boolean isOffline()
        Checks whether the client has been put into offline mode. This is true only if setOffline() was called, or if the configuration had LDConfig.Builder.offline(boolean) set to true, not if the client is simply offline due to a loss of network connectivity.
        Returns:
        true if the client is in offline mode
      • setOffline

        void setOffline()
        Shuts down any network connections maintained by the client and puts the client in offline mode, preventing the client from opening new network connections until setOnline() is called.

        Note: The client automatically monitors the device's network connectivity and app foreground status, so calling setOffline() or setOnline() is normally unnecessary in most situations.

      • setOnline

        void setOnline()
        Restores network connectivity for the client, if the client was previously in offline mode. This operation may be throttled if it is called too frequently.

        Note: The client automatically monitors the device's network connectivity and app foreground status, so calling setOffline() or setOnline() is normally unnecessary in most situations.

      • trackMetric

        void trackMetric​(java.lang.String eventName,
                         LDValue data,
                         double metricValue)
        Tracks that a user performed an event, and provides an additional numeric value for custom metrics.
        Parameters:
        eventName - the name of the event
        data - an LDValue containing additional data associated with the event; if not applicable, you may pass either null or LDValue.ofNull()
        metricValue - A numeric value used by the LaunchDarkly experimentation feature in numeric custom metrics. This field will also be returned as part of the custom event for Data Export.
      • trackData

        void trackData​(java.lang.String eventName,
                       LDValue data)
        Tracks that a user performed an event, and provides additional custom data.
        Parameters:
        eventName - the name of the event
        data - an LDValue containing additional data associated with the event
      • track

        void track​(java.lang.String eventName)
        Tracks that a user performed an event.
        Parameters:
        eventName - the name of the event
      • identify

        java.util.concurrent.Future<java.lang.Void> identify​(LDUser user)
        Sets the current user, retrieves flags for that user, then sends an Identify Event to LaunchDarkly. The 5 most recent users' flag settings are kept locally.
        Parameters:
        user - The user for evaluation and event reporting
        Returns:
        Future whose success indicates this user's flag settings have been stored locally and are ready for evaluation.
      • flush

        void flush()
        Sends all pending events to LaunchDarkly.
      • allFlags

        java.util.Map<java.lang.String,​LDValue> allFlags()
        Returns a map of all feature flags for the current user. No events are sent to LaunchDarkly.
        Returns:
        a map of all feature flags
      • boolVariation

        boolean boolVariation​(java.lang.String flagKey,
                              boolean defaultValue)
        Returns the flag value for the current user. Returns defaultValue when one of the following occurs:
        1. Flag is missing
        2. The flag is not of a boolean type
        3. Any other error
        Parameters:
        flagKey - key for the flag to evaluate
        defaultValue - default value in case of errors evaluating the flag
        Returns:
        value of the flag or the default value
      • boolVariationDetail

        EvaluationDetail<java.lang.Boolean> boolVariationDetail​(java.lang.String flagKey,
                                                                boolean defaultValue)
        Returns the flag value for the current user, along with information about how it was calculated. Note that this will only work if you have set evaluationReasons to true with LDConfig.Builder.evaluationReasons(boolean). Otherwise, the reason property of the result will be null.
        Parameters:
        flagKey - key for the flag to evaluate
        defaultValue - default value in case of errors evaluating the flag (see boolVariation(String, boolean))
        Returns:
        an EvaluationDetail object containing the value and other information.
        Since:
        2.7.0
      • intVariation

        int intVariation​(java.lang.String flagKey,
                         int defaultValue)
        Returns the flag value for the current user. Returns defaultValue when one of the following occurs:
        1. Flag is missing
        2. The flag is not of a numeric type
        3. Any other error
        Parameters:
        flagKey - key for the flag to evaluate
        defaultValue - default value in case of errors evaluating the flag
        Returns:
        value of the flag or the default value
      • intVariationDetail

        EvaluationDetail<java.lang.Integer> intVariationDetail​(java.lang.String flagKey,
                                                               int defaultValue)
        Returns the flag value for the current user, along with information about how it was calculated. Note that this will only work if you have set evaluationReasons to true with LDConfig.Builder.evaluationReasons(boolean). Otherwise, the reason property of the result will be null.
        Parameters:
        flagKey - key for the flag to evaluate
        defaultValue - default value in case of errors evaluating the flag (see intVariation(String, int))
        Returns:
        an EvaluationDetail object containing the value and other information.
        Since:
        2.7.0
      • doubleVariation

        double doubleVariation​(java.lang.String flagKey,
                               double defaultValue)
        Returns the flag value for the current user. Returns defaultValue when one of the following occurs:
        1. Flag is missing
        2. The flag is not of a numeric type
        3. Any other error
        Parameters:
        flagKey - key for the flag to evaluate
        defaultValue - default value in case of errors evaluating the flag
        Returns:
        value of the flag or the default value
      • doubleVariationDetail

        EvaluationDetail<java.lang.Double> doubleVariationDetail​(java.lang.String flagKey,
                                                                 double defaultValue)
        Returns the flag value for the current user, along with information about how it was calculated. Note that this will only work if you have set evaluationReasons to true with LDConfig.Builder.evaluationReasons(boolean). Otherwise, the reason property of the result will be null.
        Parameters:
        flagKey - key for the flag to evaluate
        defaultValue - default value in case of errors evaluating the flag (see doubleVariation(String, double))
        Returns:
        an EvaluationDetail object containing the value and other information.
      • stringVariation

        java.lang.String stringVariation​(java.lang.String flagKey,
                                         java.lang.String defaultValue)
        Returns the flag value for the current user. Returns default when one of the following occurs:
        1. Flag is missing
        2. The flag is not of a string type
        3. Any other error
        Parameters:
        flagKey - key for the flag to evaluate
        defaultValue - default value in case of errors evaluating the flag
        Returns:
        value of the flag or the default value
      • stringVariationDetail

        EvaluationDetail<java.lang.String> stringVariationDetail​(java.lang.String flagKey,
                                                                 java.lang.String defaultValue)
        Returns the flag value for the current user, along with information about how it was calculated. Note that this will only work if you have set evaluationReasons to true with LDConfig.Builder.evaluationReasons(boolean). Otherwise, the reason property of the result will be null.
        Parameters:
        flagKey - key for the flag to evaluate
        defaultValue - default value in case of errors evaluating the flag (see stringVariation(String, String))
        Returns:
        an EvaluationDetail object containing the value and other information.
        Since:
        2.7.0
      • jsonValueVariation

        LDValue jsonValueVariation​(java.lang.String flagKey,
                                   LDValue defaultValue)
        Returns the flag value for the current user. Returns defualtValue when one of the following occurs:
        1. Flag is missing
        2. Any other error
        Parameters:
        flagKey - key for the flag to evaluate
        defaultValue - default value in case of errors evaluating the flag
        Returns:
        value of the flag or the default value. Result will never be null, but may be LDValue#ofNull()
      • jsonValueVariationDetail

        EvaluationDetail<LDValue> jsonValueVariationDetail​(java.lang.String flagKey,
                                                           LDValue defaultValue)
        Returns the flag value for the current user, along with information about how it was calculated. Note that this will only work if you have set evaluationReasons to true with LDConfig.Builder.evaluationReasons(boolean). Otherwise, the reason property of the result will be null.
        Parameters:
        flagKey - key for the flag to evaluate
        defaultValue - default value in case of errors evaluating the flag (see jsonValueVariation(String, LDValue))
        Returns:
        an EvaluationDetail object containing the value and other information.
      • getConnectionInformation

        ConnectionInformation getConnectionInformation()
        Gets a ConnectionInformation object from the client representing the current state of the clients connection.
        Returns:
        An object representing the status of the connection to LaunchDarkly.
      • unregisterStatusListener

        void unregisterStatusListener​(LDStatusListener LDStatusListener)
        Unregisters a LDStatusListener so it will no longer be called on connection status updates.
        Parameters:
        LDStatusListener - the listener to be removed
      • registerStatusListener

        void registerStatusListener​(LDStatusListener LDStatusListener)
        Registers a LDStatusListener to be called on connection status updates.
        Parameters:
        LDStatusListener - the listener to be called on a connection status update
      • registerAllFlagsListener

        void registerAllFlagsListener​(LDAllFlagsListener allFlagsListener)
        Registers a LDAllFlagsListener to be called when a flag update is processed by the SDK.
        Parameters:
        allFlagsListener - the listener to be called with a list of flag keys on a flag update
      • unregisterAllFlagsListener

        void unregisterAllFlagsListener​(LDAllFlagsListener allFlagsListener)
        Unregisters a LDAllFlagsListener so it will no longer be called on flag updates.
        Parameters:
        allFlagsListener - the listener to be removed
      • getVersion

        java.lang.String getVersion()
        Returns the version of the SDK, for instance "2.7.0".
        Returns:
        the version string
        Since:
        2.7.0