Class GBFeaturesRepository

java.lang.Object
growthbook.sdk.java.repository.GBFeaturesRepository
All Implemented Interfaces:
IGBFeaturesRepository

public class GBFeaturesRepository extends Object implements IGBFeaturesRepository
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
  • Field Details

  • Constructor Details

  • Method Details

    • setCacheManager

      public void setCacheManager(GbCacheManager cacheManager)
    • getEncryptionKey

      @Deprecated @Nullable public String getEncryptionKey()
      Deprecated.
    • getFeaturesJson

      public String getFeaturesJson()
      Description copied from interface: IGBFeaturesRepository
      Required implementation to get the featuresJson
      Specified by:
      getFeaturesJson in interface IGBFeaturesRepository
      Returns:
      feature data JSON in a type of String. Handle refresh strategy
    • getParsedFeatures

      public Map<String,Feature<?>> getParsedFeatures()
    • 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.
      Specified by:
      onFeaturesRefresh in interface IGBFeaturesRepository
      Parameters:
      callback - This callback will be called when features are refreshed
    • clearCallbacks

      public void clearCallbacks()
      Description copied from interface: IGBFeaturesRepository
      Clears the feature refresh callbacks
      Specified by:
      clearCallbacks in interface IGBFeaturesRepository
    • initialize

      public void initialize() throws FeatureFetchException
      Specified by:
      initialize in interface IGBFeaturesRepository
      Throws:
      FeatureFetchException
    • initialize

      public void initialize(Boolean retryOnFailure) throws FeatureFetchException
      Specified by:
      initialize in interface IGBFeaturesRepository
      Throws:
      FeatureFetchException
    • fetchFeatures

      public void fetchFeatures() throws FeatureFetchException
      Performs a network request to fetch the features from the GrowthBook API with the provided endpoint. If an encryptionKey is provided, it is assumed the features endpoint is using encrypted features. This method will attempt to decrypt the encrypted features with the provided encryptionKey.
      Throws:
      FeatureFetchException
    • shutdown

      public void shutdown()
    • fetchForRemoteEval

      public void fetchForRemoteEval(RequestBodyForRemoteEval requestBodyForRemoteEval) throws FeatureFetchException
      Throws:
      FeatureFetchException
    • builder

    • getFeaturesEndpoint

      public String getFeaturesEndpoint()
      Endpoint for GET request
    • getEventsEndpoint

      public String getEventsEndpoint()
      Endpoint for SSE request
    • getRefreshStrategy

      public FeatureRefreshStrategy getRefreshStrategy()
      Strategy for building url
    • getDecryptionKey

      @Nullable public String getDecryptionKey()
      The key used to decrypt encrypted features from the API
    • getSwrTtlSeconds

      public Integer getSwrTtlSeconds()
      The standard cache TTL to use (60 seconds)
    • getExpiresAt

      public Long getExpiresAt()
      Seconds after that cache is expired
    • getInitialized

      public Boolean getInitialized()
      Flag to know whether GBFeatureRepository is initialized
    • getSavedGroupsJson

      @Nullable public String getSavedGroupsJson()
      Allows you to get the saved groups JSON from the provided getFeaturesEndpoint(). You must call initialize() before calling this method or your saved groups would not have loaded.
    • getParsedSavedGroups

      public com.google.gson.JsonObject getParsedSavedGroups()
    • getCacheManager

      public GbCacheManager getCacheManager()
      CachingManger allows to cache features data to file
    • getRequestBodyForRemoteEval

      @Nullable public RequestBodyForRemoteEval getRequestBodyForRemoteEval()
      Request body for that be sent with POST request for remote eval feature
    • getRemoteEvalEndPoint

      public String getRemoteEvalEndPoint()
      Endpoint for POST request