Package growthbook.sdk.java.repository
Class NativeJavaGbFeatureRepository
java.lang.Object
growthbook.sdk.java.repository.NativeJavaGbFeatureRepository
- 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()
.
Get the savedGroups JSON with getSavedGroupsJson()
.
You would provide the features JSON when creating the GBContext
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionNativeJavaGbFeatureRepository
(String apiHost, String clientKey, String encryptionKey, FeatureRefreshStrategy refreshStrategy, Integer swrTtlSeconds, Boolean isCacheDisabled, RequestBodyForRemoteEval requestBodyForRemoteEval) Create a new GBFeaturesRepository -
Method Summary
Modifier and TypeMethodDescriptionbuilder()
void
Clears the feature refresh callbacksvoid
The key used to decrypt encrypted features from the APIEndpoint for SSE requestSeconds after that cache is expiredEndpoint for GET requestMethod for getting Feature from API call once if it STALE_WHILE_REVALIDATE or be updated if SERVER_SENT_EVENTS strategyStrategy for building urlEndpoint for POST requestRequest body that be sent with POST request for remote eval featureGet method for saved Group jsonThe standard cache TTL to use (60 seconds)void
Method for initializeNativeJavaGbFeatureRepository
.void
initialize
(Boolean retryOnFailure) Method for initializeNativeJavaGbFeatureRepository
.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
onRefreshFailed
(Throwable throwable) void
onRefreshSuccess
(String featuresJson)
-
Field Details
-
FILE_PATH_FOR_CACHE
- See Also:
-
EMPTY_JSON_OBJECT_STRING
- See Also:
-
-
Constructor Details
-
NativeJavaGbFeatureRepository
public NativeJavaGbFeatureRepository(@Nullable String apiHost, String clientKey, @Nullable String encryptionKey, @Nullable FeatureRefreshStrategy refreshStrategy, @Nullable Integer swrTtlSeconds, @Nullable Boolean isCacheDisabled, @Nullable RequestBodyForRemoteEval requestBodyForRemoteEval) 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)requestBodyForRemoteEval
- Payload that would be sent with POST request when repository configure with Remote evalStrategyFeatureRefreshStrategy.REMOTE_EVAL_STRATEGY
-
-
Method Details
-
initialize
Method for initializeNativeJavaGbFeatureRepository
. Depends onFeatureRefreshStrategy
connection would be established for SSE or for just GET request- Specified by:
initialize
in interfaceIGBFeaturesRepository
- Throws:
FeatureFetchException
- while initialize function
-
getSavedGroupsJson
Get method for saved Group json- Returns:
- saved Group Json in format of String type
-
initialize
Method for initializeNativeJavaGbFeatureRepository
. Depends onFeatureRefreshStrategy
connection would be established for SSE or for just GET request- Specified by:
initialize
in interfaceIGBFeaturesRepository
- Parameters:
retryOnFailure
- : Boolean argument that responsible whether SSE connection need to be reconnected- Throws:
FeatureFetchException
- during fetchFeatures function
-
getFeaturesJson
Method for getting Feature from API call once if it STALE_WHILE_REVALIDATE or be updated if SERVER_SENT_EVENTS strategy- Specified by:
getFeaturesJson
in interfaceIGBFeaturesRepository
- Returns:
- Feature Json in format of String
-
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()Clears the feature refresh callbacks- Specified by:
clearCallbacks
in interfaceIGBFeaturesRepository
-
fetchFeatures
- Throws:
FeatureFetchException
-
onRefreshSuccess
-
onRefreshFailed
-
builder
-
getFeaturesEndpoint
Endpoint for GET request -
getRemoteEvalEndPoint
Endpoint for POST request -
getEventsEndpoint
Endpoint for SSE request -
getRefreshStrategy
Strategy for building url -
getEncryptionKey
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 -
getRequestBodyForRemoteEval
Request body that be sent with POST request for remote eval feature
-