Class GrowthBookClient

java.lang.Object
growthbook.sdk.java.multiusermode.GrowthBookClient

public class GrowthBookClient extends Object
  • Constructor Details

    • GrowthBookClient

      public GrowthBookClient()
    • GrowthBookClient

      public GrowthBookClient(Options opts)
  • Method Details

    • getDiagnostics

      public Diagnostics getDiagnostics()
      Returns a read-only snapshot of the current SDK state.
      Returns:
      diagnostics snapshot
    • initialize

      public boolean initialize()
    • setGlobalAttributes

      public void setGlobalAttributes(String attributes)
    • setGlobalForceFeatures

      public void setGlobalForceFeatures(Map<String,Object> forceFeatures)
    • setGlobalForceVariations

      public void setGlobalForceVariations(Map<String,Integer> forceVariations)
    • refreshFeature

      @Deprecated public void refreshFeature()
      Deprecated.
    • refreshFeatures

      public void refreshFeatures()
    • refreshFeatures

      public void refreshFeatures(RefreshMode refreshMode)
      Refreshes features using the provided refresh mode.
      Parameters:
      refreshMode - refresh behavior to use
    • refreshForRemoteEval

      public void refreshForRemoteEval(RequestBodyForRemoteEval requestBodyForRemoteEval)
    • preloadRemoteEval

      public boolean preloadRemoteEval(UserContext userContext)
    • evalFeature

      public <ValueType> FeatureResult<ValueType> evalFeature(String key, Class<ValueType> valueTypeClass, UserContext userContext)
    • isOn

      public Boolean isOn(String featureKey, UserContext userContext)
    • isOff

      public Boolean isOff(String featureKey, UserContext userContext)
    • getFeatureValue

      public <ValueType> ValueType getFeatureValue(String featureKey, ValueType defaultValue, Class<ValueType> gsonDeserializableClass, UserContext userContext)
    • getFeature

      public <T> FeatureResult<T> getFeature(FeatureKey<T> featureKey, UserContext userContext)
      Evaluate a feature for a user using a type-safe FeatureKey instead of a raw string key.

      As with evalFeature(String, Class, UserContext), the returned result's FeatureResult.getValue() is the raw evaluated value (a boxed primitive, or a Map/List for object and array features); it is not deserialized into the key's value type. To obtain a deserialized instance of a complex type, use getFeatureValue(FeatureKey, Object, UserContext).

      Type Parameters:
      T - feature value type carried by the key
      Parameters:
      featureKey - typed feature key, e.g. Features.NEW_HOME
      userContext - user context
      Returns:
      the feature result
    • isOn

      public Boolean isOn(FeatureKey<?> featureKey, UserContext userContext)
      Checks whether the feature identified by the typed key evaluates to on for a user.
      Parameters:
      featureKey - typed feature key
      userContext - user context
      Returns:
      true when the feature is on
    • isOff

      public Boolean isOff(FeatureKey<?> featureKey, UserContext userContext)
      Checks whether the feature identified by the typed key evaluates to off for a user.
      Parameters:
      featureKey - typed feature key
      userContext - user context
      Returns:
      true when the feature is off
    • getFeatureValue

      public <T> T getFeatureValue(FeatureKey<T> featureKey, T defaultValue, UserContext userContext)
      Get a feature value using a typed key, inferring the deserialization class from the key.
      Type Parameters:
      T - feature value type carried by the key
      Parameters:
      featureKey - typed feature key
      defaultValue - value to return when the feature is missing or invalid
      userContext - user context
      Returns:
      the found value or defaultValue
    • getBooleanFeature

      public Boolean getBooleanFeature(FeatureKey<Boolean> featureKey, UserContext userContext)
      Get a boolean feature value, defaulting to false when missing or falsy.
      Parameters:
      featureKey - typed boolean feature key
      userContext - user context
      Returns:
      the found value or false
    • getBooleanFeature

      public Boolean getBooleanFeature(FeatureKey<Boolean> featureKey, Boolean defaultValue, UserContext userContext)
      Get a boolean feature value.
      Parameters:
      featureKey - typed boolean feature key
      defaultValue - value to return when the feature is missing or invalid
      userContext - user context
      Returns:
      the found value or defaultValue
    • getStringFeature

      public String getStringFeature(FeatureKey<String> featureKey, String defaultValue, UserContext userContext)
      Get a string feature value.
      Parameters:
      featureKey - typed string feature key
      defaultValue - value to return when the feature is missing or invalid
      userContext - user context
      Returns:
      the found value or defaultValue
    • getIntegerFeature

      public Integer getIntegerFeature(FeatureKey<Integer> featureKey, Integer defaultValue, UserContext userContext)
      Get an integer feature value.
      Parameters:
      featureKey - typed integer feature key
      defaultValue - value to return when the feature is missing or invalid
      userContext - user context
      Returns:
      the found value or defaultValue
    • getDoubleFeature

      public Double getDoubleFeature(FeatureKey<Double> featureKey, Double defaultValue, UserContext userContext)
      Get a double feature value.
      Parameters:
      featureKey - typed double feature key
      defaultValue - value to return when the feature is missing or invalid
      userContext - user context
      Returns:
      the found value or defaultValue
    • getFloatFeature

      public Float getFloatFeature(FeatureKey<Float> featureKey, Float defaultValue, UserContext userContext)
      Get a float feature value.
      Parameters:
      featureKey - typed float feature key
      defaultValue - value to return when the feature is missing or invalid
      userContext - user context
      Returns:
      the found value or defaultValue
    • run

      public <ValueType> ExperimentResult<ValueType> run(Experiment<ValueType> experiment, UserContext userContext)
    • subscribe

      public void subscribe(ExperimentRunCallback callback)
    • shutdown

      public void shutdown()