From 59d01a31257a9b775ac07bfc1d697c0cef757fe4 Mon Sep 17 00:00:00 2001 From: Volodymyr Nazarkevych <94451639+vazarkevych@users.noreply.github.com> Date: Wed, 14 Aug 2024 18:59:18 +0300 Subject: [PATCH] Release v0.9.91 (#97) * SDK version was updated * Issue #92 (#93) Co-authored-by: Bohdan Akimenko * Issue #94 (#96) Co-authored-by: Bohdan Akimenko * 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 --------- Co-authored-by: Bohdan Akimenko --- .../sdk/java/GBFeaturesRepository.java | 48 +++++++++++++------ .../java/growthbook/sdk/java/Version.java | 2 +- 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/lib/src/main/java/growthbook/sdk/java/GBFeaturesRepository.java b/lib/src/main/java/growthbook/sdk/java/GBFeaturesRepository.java index 6774801..806072f 100644 --- a/lib/src/main/java/growthbook/sdk/java/GBFeaturesRepository.java +++ b/lib/src/main/java/growthbook/sdk/java/GBFeaturesRepository.java @@ -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(); } }); } @@ -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(); @@ -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; @@ -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); + } } /** @@ -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"); + + } + } } diff --git a/lib/src/main/java/growthbook/sdk/java/Version.java b/lib/src/main/java/growthbook/sdk/java/Version.java index 1ed8bc3..69f4e02 100644 --- a/lib/src/main/java/growthbook/sdk/java/Version.java +++ b/lib/src/main/java/growthbook/sdk/java/Version.java @@ -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"; }