Skip to content

Commit

Permalink
Release v0.9.91 (#97)
Browse files Browse the repository at this point in the history
* SDK version was updated

* Issue #92 (#93)

Co-authored-by: Bohdan Akimenko <bohdan.akimenko@kevychsolutions.com>

* Issue #94 (#96)

Co-authored-by: Bohdan Akimenko <bohdan.akimenko@kevychsolutions.com>

* close sse response, cancel call on failure, fix savedGroups logic to avoid polluting in logs, add shutdown method to GbFeatureRepository (#98)

Co-authored-by: Bohdan Akimenko <bohdan.akimenko@kevychsolutions.com>

---------

Co-authored-by: Bohdan Akimenko <bohdan.akimenko@kevychsolutions.com>
  • Loading branch information
vazarkevych and Bohdan-Kim authored Aug 14, 2024
1 parent a40b088 commit 59d01a3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 16 deletions.
48 changes: 33 additions & 15 deletions lib/src/main/java/growthbook/sdk/java/GBFeaturesRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -296,11 +296,12 @@ public void onFailure(@NotNull EventSource eventSource, @Nullable Throwable t, @
@Override
public void onFailure(@NotNull Call call, @NotNull IOException e) {
log.error("SSE connection failed: {}", e.getMessage(), e);
call.cancel();
}

@Override
public void onResponse(@NotNull Call call, @NotNull Response response) {
// We don't do anything with this response
response.close();
}
});
}
Expand Down Expand Up @@ -382,14 +383,9 @@ private void onResponseJson(String responseJsonString) throws FeatureFetchExcept
"encryptionKey provided but endpoint not encrypted"
);
}
if (encryptedSavedGroupsJsonElement == null) {
log.error(
"FeatureFetchException: CONFIGURATION_ERROR encryptedSavedGroupsJsonElement fetch error code: "
+ "encryptionKey provided but endpoint not encrypted");
}

String encryptedFeaturesJson = encryptedFeaturesJsonElement.getAsString();
String encryptedSavedGroupsJson = null;
String encryptedSavedGroupsJson;
if (encryptedSavedGroupsJsonElement != null) {
encryptedSavedGroupsJson = encryptedSavedGroupsJsonElement.getAsString();
refreshedSavedGroups = DecryptionUtils.decrypt(encryptedSavedGroupsJson, this.encryptionKey).trim();
Expand All @@ -412,15 +408,11 @@ private void onResponseJson(String responseJsonString) throws FeatureFetchExcept
);
}

if (savedGroupsJsonElement == null) {
log.error(
"FeatureFetchException: CONFIGURATION_ERROR savedGroupsJsonElement fetch error code: "
+ "No features found");

if (savedGroupsJsonElement != null) {
refreshedSavedGroups = savedGroupsJsonElement.toString().trim();
}

refreshedFeatures = featuresJsonElement.toString().trim();
refreshedSavedGroups = savedGroupsJsonElement != null ? savedGroupsJsonElement.toString().trim() : null;
}

this.featuresJson = refreshedFeatures;
Expand All @@ -439,11 +431,15 @@ private void onResponseJson(String responseJsonString) throws FeatureFetchExcept
}

private void onRefreshSuccess(String featuresJson) {
this.refreshCallbacks.forEach(featureRefreshCallback -> featureRefreshCallback.onRefresh(featuresJson));
for (FeatureRefreshCallback callback: this.refreshCallbacks) {
callback.onRefresh(featuresJson);
}
}

private void onRefreshFailed(Throwable throwable) {
this.refreshCallbacks.forEach(featureRefreshCallback -> featureRefreshCallback.onError(throwable));
for (FeatureRefreshCallback callback: this.refreshCallbacks) {
callback.onError(throwable);
}
}

/**
Expand Down Expand Up @@ -515,4 +511,26 @@ public void onOpen(@NotNull EventSource eventSource, @NotNull Response response)
super.onOpen(eventSource, response);
}
}

public void shutdown() {
if (this.sseEventSource != null) {
this.sseEventSource.cancel();
this.sseEventSource = null;
log.info("SseEventSource cancel");
}
if (this.sseHttpClient != null) {
this.sseHttpClient.dispatcher().cancelAll();
this.sseHttpClient.connectionPool().evictAll();
if (this.sseHttpClient.cache() != null) {
try {
this.sseHttpClient.cache().close();
} catch (IOException e) {
log.error(e.getMessage(), e);
}
}
this.sseHttpClient = null;
log.info("SseHttpClient shutdown");

}
}
}
2 changes: 1 addition & 1 deletion lib/src/main/java/growthbook/sdk/java/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
public class Version {
private Version() {}

static final String SDK_VERSION = "0.9.9";
static final String SDK_VERSION = "0.9.91";
}

0 comments on commit 59d01a3

Please sign in to comment.