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: ...)
      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: ...)
      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
    • initialize

      public void initialize(Boolean retryOnFailure) throws FeatureFetchException
      Throws:
      FeatureFetchException
    • shutdown

      public void shutdown()
    • builder

    • getFeaturesEndpoint

      public String getFeaturesEndpoint()
    • getEventsEndpoint

      public String getEventsEndpoint()
    • getRefreshStrategy

      public FeatureRefreshStrategy getRefreshStrategy()
    • getEncryptionKey

      @Nullable public String getEncryptionKey()
    • getSwrTtlSeconds

      public Integer getSwrTtlSeconds()
    • getExpiresAt

      public Long getExpiresAt()
    • getSavedGroupsJson

      @Nullable public String getSavedGroupsJson()