Package growthbook.sdk.java.repository
Class GBFeaturesRepository
java.lang.Object
growthbook.sdk.java.repository.GBFeaturesRepository
- All Implemented Interfaces:
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
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionGBFeaturesRepository
(String apiHost, String clientKey, String encryptionKey, FeatureRefreshStrategy refreshStrategy, Integer swrTtlSeconds) Deprecated.GBFeaturesRepository
(String apiHost, String clientKey, String encryptionKey, FeatureRefreshStrategy refreshStrategy, Integer swrTtlSeconds, RequestBodyForRemoteEval requestBodyForRemoteEval) New constructor that support payload for remote evalGBFeaturesRepository
(String apiHost, String clientKey, String encryptionKey, FeatureRefreshStrategy refreshStrategy, Integer swrTtlSeconds, Boolean isCacheDisabled) GBFeaturesRepository
(String apiHost, String clientKey, String decryptionKey, FeatureRefreshStrategy refreshStrategy, Integer swrTtlSeconds, okhttp3.OkHttpClient okHttpClient, Boolean isCacheDisabled, RequestBodyForRemoteEval requestBodyForRemoteEval) Create a new GBFeaturesRepositoryGBFeaturesRepository
(String apiHost, String clientKey, String encryptionKey, FeatureRefreshStrategy refreshStrategy, Integer swrTtlSeconds, okhttp3.OkHttpClient okHttpClient, String decryptionKey, Boolean isCacheDisabled, RequestBodyForRemoteEval requestBodyForRemoteEval) New constructor that explicitly supports decryptionKey. -
Method Summary
Modifier and TypeMethodDescriptionbuilder()
void
Clears the feature refresh callbacksvoid
Performs a network request to fetch the features from the GrowthBook API with the provided endpoint.void
fetchForRemoteEval
(RequestBodyForRemoteEval requestBodyForRemoteEval) CachingManger allows to cache features data to fileThe key used to decrypt encrypted features from the APIDeprecated.Endpoint for SSE requestSeconds after that cache is expiredEndpoint for GET requestRequired implementation to get the featuresJsonFlag to know whether GBFeatureRepository is initializedStrategy for building urlEndpoint for POST requestRequest body for that be sent with POST request for remote eval featureAllows you to get the saved groups JSON from the providedgetFeaturesEndpoint()
.The standard cache TTL to use (60 seconds)void
void
initialize
(Boolean retryOnFailure) 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.void
setCachingManager
(CachingManager cachingManager) void
shutdown()
-
Field Details
-
FILE_PATH_FOR_CACHE
- See Also:
-
EMPTY_JSON_OBJECT_STRING
- See Also:
-
-
Constructor Details
-
GBFeaturesRepository
@Deprecated public GBFeaturesRepository(@Nullable String apiHost, String clientKey, @Deprecated @Nullable String encryptionKey, @Nullable FeatureRefreshStrategy refreshStrategy, @Nullable Integer swrTtlSeconds) Deprecated.Create a new GBFeaturesRepository- Parameters:
apiHost
- The GrowthBook API host (default: ...)clientKey
- Your client ID, e.g. sdk-abc123encryptionKey
- optional key for decrypting encrypted payloadswrTtlSeconds
- How often the cache should be invalidated when usingFeatureRefreshStrategy.STALE_WHILE_REVALIDATE
(default: 60)
-
GBFeaturesRepository
public GBFeaturesRepository(@Nullable String apiHost, String clientKey, @Deprecated @Nullable String encryptionKey, @Nullable FeatureRefreshStrategy refreshStrategy, @Nullable Integer swrTtlSeconds, @Nullable RequestBodyForRemoteEval requestBodyForRemoteEval) New constructor that support payload for remote eval- Parameters:
apiHost
- The GrowthBook API host (default: ...)clientKey
- Your client ID, e.g. sdk-abc123encryptionKey
- optional key for decrypting encrypted payloadrefreshStrategy
- Strategy for building urlswrTtlSeconds
- How often the cache should be invalidated when usingFeatureRefreshStrategy.STALE_WHILE_REVALIDATE
(default: 60)requestBodyForRemoteEval
- Payload that would be sent with POST request when repository configure with Remote evalStrategyFeatureRefreshStrategy.REMOTE_EVAL_STRATEGY
(default: 60)
-
GBFeaturesRepository
public GBFeaturesRepository(@Nullable String apiHost, String clientKey, @Deprecated @Nullable String encryptionKey, @Nullable FeatureRefreshStrategy refreshStrategy, @Nullable Integer swrTtlSeconds, @Nullable Boolean isCacheDisabled) -
GBFeaturesRepository
public GBFeaturesRepository(@Nullable String apiHost, String clientKey, @Deprecated @Nullable String encryptionKey, @Nullable FeatureRefreshStrategy refreshStrategy, @Nullable Integer swrTtlSeconds, @Nullable okhttp3.OkHttpClient okHttpClient, @Nullable String decryptionKey, @Nullable Boolean isCacheDisabled, @Nullable RequestBodyForRemoteEval requestBodyForRemoteEval) New constructor that explicitly supports decryptionKey. -
GBFeaturesRepository
public GBFeaturesRepository(@Nullable String apiHost, String clientKey, @Nullable String decryptionKey, @Nullable FeatureRefreshStrategy refreshStrategy, @Nullable Integer swrTtlSeconds, @Nullable okhttp3.OkHttpClient okHttpClient, @Nullable Boolean isCacheDisabled, @Nullable RequestBodyForRemoteEval requestBodyForRemoteEval) Create a new GBFeaturesRepository- Parameters:
apiHost
- The GrowthBook API host (default: ...)clientKey
- Your client ID, e.g. sdk-abc123decryptionKey
- optional key for decrypting encrypted payloadswrTtlSeconds
- How often the cache should be invalidated when usingFeatureRefreshStrategy.STALE_WHILE_REVALIDATE
(default: 60)okHttpClient
- HTTP client (optional)isCacheDisabled
- Parameter to disable or enable caching in projectrequestBodyForRemoteEval
- Payload that would be sent with POST request when repository configure with Remote evalStrategyFeatureRefreshStrategy.REMOTE_EVAL_STRATEGY
-
-
Method Details
-
setCachingManager
-
getEncryptionKey
Deprecated. -
getFeaturesJson
Description copied from interface:IGBFeaturesRepository
Required implementation to get the featuresJson- Specified by:
getFeaturesJson
in interfaceIGBFeaturesRepository
- Returns:
- feature data JSON in a type of String. Handle refresh strategy
-
onFeaturesRefresh
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 interfaceIGBFeaturesRepository
- 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 interfaceIGBFeaturesRepository
-
initialize
- Specified by:
initialize
in interfaceIGBFeaturesRepository
- Throws:
FeatureFetchException
-
initialize
- Specified by:
initialize
in interfaceIGBFeaturesRepository
- Throws:
FeatureFetchException
-
fetchFeatures
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
Endpoint for GET request -
getEventsEndpoint
Endpoint for SSE request -
getRefreshStrategy
Strategy for building url -
getDecryptionKey
The key used to decrypt encrypted features from the API -
getSwrTtlSeconds
The standard cache TTL to use (60 seconds) -
getExpiresAt
Seconds after that cache is expired -
getInitialized
Flag to know whether GBFeatureRepository is initialized -
getSavedGroupsJson
Allows you to get the saved groups JSON from the providedgetFeaturesEndpoint()
. You must callinitialize()
before calling this method or your saved groups would not have loaded. -
getCachingManager
CachingManger allows to cache features data to file -
getRequestBodyForRemoteEval
Request body for that be sent with POST request for remote eval feature -
getRemoteEvalEndPoint
Endpoint for POST request
-