From 39535bd145383dfed664f1754449c855a102e4b8 Mon Sep 17 00:00:00 2001 From: Patrick Kaeding Date: Thu, 8 Jun 2017 14:18:17 -0700 Subject: [PATCH 1/4] [WIP] attempt to shutdown OKHTTP when shutting down ldclient --- src/main/java/com/launchdarkly/client/LDClient.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/java/com/launchdarkly/client/LDClient.java b/src/main/java/com/launchdarkly/client/LDClient.java index 33c32246e..238a5a8d0 100644 --- a/src/main/java/com/launchdarkly/client/LDClient.java +++ b/src/main/java/com/launchdarkly/client/LDClient.java @@ -377,6 +377,17 @@ public void close() throws IOException { if (this.updateProcessor != null) { this.updateProcessor.close(); } + if (this.config.httpClient != null) { + if (this.config.httpClient.dispatcher() != null && this.config.httpClient.dispatcher().executorService() != null) { + this.config.httpClient.dispatcher().executorService().shutdown(); + } + if (this.config.httpClient.connectionPool() != null) { + this.config.httpClient.connectionPool().evictAll(); + } + if (this.config.httpClient.cache() != null) { + this.config.httpClient.cache().close(); + } + } } /** From 4af9bfe7710ff74e0974b4f3d5e1c7687c500fe1 Mon Sep 17 00:00:00 2001 From: Dan Richelson Date: Fri, 16 Jun 2017 10:00:42 -0700 Subject: [PATCH 2/4] Add equals() and hashCode() methods to LDUser --- .../java/com/launchdarkly/client/LDUser.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/main/java/com/launchdarkly/client/LDUser.java b/src/main/java/com/launchdarkly/client/LDUser.java index 270d9a978..b97fd11cc 100644 --- a/src/main/java/com/launchdarkly/client/LDUser.java +++ b/src/main/java/com/launchdarkly/client/LDUser.java @@ -126,6 +126,43 @@ JsonElement getCustom(String key) { } return null; } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + LDUser ldUser = (LDUser) o; + + if (key != null ? !key.equals(ldUser.key) : ldUser.key != null) return false; + if (secondary != null ? !secondary.equals(ldUser.secondary) : ldUser.secondary != null) return false; + if (ip != null ? !ip.equals(ldUser.ip) : ldUser.ip != null) return false; + if (email != null ? !email.equals(ldUser.email) : ldUser.email != null) return false; + if (name != null ? !name.equals(ldUser.name) : ldUser.name != null) return false; + if (avatar != null ? !avatar.equals(ldUser.avatar) : ldUser.avatar != null) return false; + if (firstName != null ? !firstName.equals(ldUser.firstName) : ldUser.firstName != null) return false; + if (lastName != null ? !lastName.equals(ldUser.lastName) : ldUser.lastName != null) return false; + if (anonymous != null ? !anonymous.equals(ldUser.anonymous) : ldUser.anonymous != null) return false; + if (country != null ? !country.equals(ldUser.country) : ldUser.country != null) return false; + return custom != null ? custom.equals(ldUser.custom) : ldUser.custom == null; + } + + @Override + public int hashCode() { + int result = key != null ? key.hashCode() : 0; + result = 31 * result + (secondary != null ? secondary.hashCode() : 0); + result = 31 * result + (ip != null ? ip.hashCode() : 0); + result = 31 * result + (email != null ? email.hashCode() : 0); + result = 31 * result + (name != null ? name.hashCode() : 0); + result = 31 * result + (avatar != null ? avatar.hashCode() : 0); + result = 31 * result + (firstName != null ? firstName.hashCode() : 0); + result = 31 * result + (lastName != null ? lastName.hashCode() : 0); + result = 31 * result + (anonymous != null ? anonymous.hashCode() : 0); + result = 31 * result + (country != null ? country.hashCode() : 0); + result = 31 * result + (custom != null ? custom.hashCode() : 0); + return result; + } + /** * A builder that helps construct {@link LDUser} objects. Builder * calls can be chained, enabling the following pattern: From 825472beacdb023ce585b14fc978623cbdf9a5d9 Mon Sep 17 00:00:00 2001 From: Dan Richelson Date: Fri, 16 Jun 2017 10:02:54 -0700 Subject: [PATCH 3/4] Enable faster shutdown of okhttp and okio resources. --- gradle.properties | 2 +- src/main/java/com/launchdarkly/client/LDClient.java | 3 ++- src/main/java/com/launchdarkly/client/LDConfig.java | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/gradle.properties b/gradle.properties index 519f60f34..39e97c031 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ -version=2.2.5 +version=2.2.6-SNAPSHOT ossrhUsername= ossrhPassword= \ No newline at end of file diff --git a/src/main/java/com/launchdarkly/client/LDClient.java b/src/main/java/com/launchdarkly/client/LDClient.java index 238a5a8d0..32ea62932 100644 --- a/src/main/java/com/launchdarkly/client/LDClient.java +++ b/src/main/java/com/launchdarkly/client/LDClient.java @@ -379,7 +379,8 @@ public void close() throws IOException { } if (this.config.httpClient != null) { if (this.config.httpClient.dispatcher() != null && this.config.httpClient.dispatcher().executorService() != null) { - this.config.httpClient.dispatcher().executorService().shutdown(); + this.config.httpClient.dispatcher().cancelAll(); + this.config.httpClient.dispatcher().executorService().shutdownNow(); } if (this.config.httpClient.connectionPool() != null) { this.config.httpClient.connectionPool().evictAll(); diff --git a/src/main/java/com/launchdarkly/client/LDConfig.java b/src/main/java/com/launchdarkly/client/LDConfig.java index 7be4cf2ff..1fd86d43e 100644 --- a/src/main/java/com/launchdarkly/client/LDConfig.java +++ b/src/main/java/com/launchdarkly/client/LDConfig.java @@ -90,7 +90,7 @@ protected LDConfig(Builder builder) { OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder() .cache(cache) - .connectionPool(new ConnectionPool(5, 5, TimeUnit.MINUTES)) + .connectionPool(new ConnectionPool(5, 5, TimeUnit.SECONDS)) .connectTimeout(connectTimeoutMillis, TimeUnit.MILLISECONDS) .readTimeout(socketTimeoutMillis, TimeUnit.MILLISECONDS) .writeTimeout(socketTimeoutMillis, TimeUnit.MILLISECONDS) From ad5e63c31ef68bf154aefe41945e99e443a17191 Mon Sep 17 00:00:00 2001 From: Dan Richelson Date: Fri, 16 Jun 2017 10:03:12 -0700 Subject: [PATCH 4/4] Update version in readme when releasing --- scripts/release.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scripts/release.sh b/scripts/release.sh index c70884cc0..97da2e48e 100755 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -13,9 +13,14 @@ echo "Starting java-client release." VERSION=$1 -#Update version in gradle.properties file: +# Update version in gradle.properties file: sed -i.bak "s/^version.*$/version=${VERSION}/" gradle.properties rm -f gradle.properties.bak + +# Update version in README.md: +sed -i.bak "s/.*<\/version>/${VERSION}<\/version>/" README.md +rm -f README.md.bak + ./gradlew clean test install sourcesJar javadocJar uploadArchives closeAndReleaseRepository ./gradlew publishGhPages echo "Finished java-client release."