Class GBFeaturesRepository

java.lang.Object
growthbook.sdk.java.GBFeaturesRepository

public class GBFeaturesRepository extends Object
This class can be created with its `builder()` or constructor. It will fetch the features from the endpoint provided. Initialize with initialize() Get the features JSON with getFeaturesJson(). You would provide the features JSON when creating the GBContext
  • Constructor Details

    • GBFeaturesRepository

      public GBFeaturesRepository(@Nullable String apiHost, String clientKey, @Nullable String encryptionKey, @Nullable FeatureRefreshStrategy refreshStrategy, @Nullable Integer swrTtlSeconds)
      Create a new GBFeaturesRepository
      Parameters:
      apiHost - The GrowthBook API host (default: https://cdn.growthbook.io)
      clientKey - Your client ID, e.g. sdk-abc123
      encryptionKey - optional key for decrypting encrypted payload
      swrTtlSeconds - How often the cache should be invalidated when using FeatureRefreshStrategy.STALE_WHILE_REVALIDATE (default: 60)
    • GBFeaturesRepository

      public GBFeaturesRepository(@Nullable String apiHost, String clientKey, @Nullable String encryptionKey, @Nullable FeatureRefreshStrategy refreshStrategy, @Nullable Integer swrTtlSeconds, @Nullable okhttp3.OkHttpClient okHttpClient)
      Create a new GBFeaturesRepository
      Parameters:
      apiHost - The GrowthBook API host (default: https://cdn.growthbook.io)
      clientKey - Your client ID, e.g. sdk-abc123
      encryptionKey - optional key for decrypting encrypted payload
      swrTtlSeconds - How often the cache should be invalidated when using FeatureRefreshStrategy.STALE_WHILE_REVALIDATE (default: 60)
      okHttpClient - HTTP client (optional)
  • Method Details

    • getFeaturesJson

      public String getFeaturesJson()
    • onFeaturesRefresh

      public void onFeaturesRefresh(FeatureRefreshCallback callback)
      Subscribe to feature refresh events This callback is called when the features are successfully refreshed or there is an error when refreshing. This is called even if the features have not changed.
      Parameters:
      callback - This callback will be called when features are refreshed
    • clearCallbacks

      public void clearCallbacks()
    • initialize

      public void initialize() throws FeatureFetchException
      Throws:
      FeatureFetchException