Skip to content
This repository was archived by the owner on May 30, 2024. It is now read-only.

Commit 8fc4b4e

Browse files
authored
Merge pull request #13 from launchdarkly/pk/ch4021/shutdown-fully
Faster shutdown. Add equals() and hashCode() to LDUser
2 parents acd7428 + ad5e63c commit 8fc4b4e

File tree

5 files changed

+57
-3
lines changed

5 files changed

+57
-3
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
version=2.2.5
1+
version=2.2.6-SNAPSHOT
22
ossrhUsername=
33
ossrhPassword=

scripts/release.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,14 @@ echo "Starting java-client release."
1313

1414
VERSION=$1
1515

16-
#Update version in gradle.properties file:
16+
# Update version in gradle.properties file:
1717
sed -i.bak "s/^version.*$/version=${VERSION}/" gradle.properties
1818
rm -f gradle.properties.bak
19+
20+
# Update version in README.md:
21+
sed -i.bak "s/<version>.*<\/version>/<version>${VERSION}<\/version>/" README.md
22+
rm -f README.md.bak
23+
1924
./gradlew clean test install sourcesJar javadocJar uploadArchives closeAndReleaseRepository
2025
./gradlew publishGhPages
2126
echo "Finished java-client release."

src/main/java/com/launchdarkly/client/LDClient.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,18 @@ public void close() throws IOException {
377377
if (this.updateProcessor != null) {
378378
this.updateProcessor.close();
379379
}
380+
if (this.config.httpClient != null) {
381+
if (this.config.httpClient.dispatcher() != null && this.config.httpClient.dispatcher().executorService() != null) {
382+
this.config.httpClient.dispatcher().cancelAll();
383+
this.config.httpClient.dispatcher().executorService().shutdownNow();
384+
}
385+
if (this.config.httpClient.connectionPool() != null) {
386+
this.config.httpClient.connectionPool().evictAll();
387+
}
388+
if (this.config.httpClient.cache() != null) {
389+
this.config.httpClient.cache().close();
390+
}
391+
}
380392
}
381393

382394
/**

src/main/java/com/launchdarkly/client/LDConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ protected LDConfig(Builder builder) {
9090

9191
OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder()
9292
.cache(cache)
93-
.connectionPool(new ConnectionPool(5, 5, TimeUnit.MINUTES))
93+
.connectionPool(new ConnectionPool(5, 5, TimeUnit.SECONDS))
9494
.connectTimeout(connectTimeoutMillis, TimeUnit.MILLISECONDS)
9595
.readTimeout(socketTimeoutMillis, TimeUnit.MILLISECONDS)
9696
.writeTimeout(socketTimeoutMillis, TimeUnit.MILLISECONDS)

src/main/java/com/launchdarkly/client/LDUser.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,43 @@ JsonElement getCustom(String key) {
126126
}
127127
return null;
128128
}
129+
130+
@Override
131+
public boolean equals(Object o) {
132+
if (this == o) return true;
133+
if (o == null || getClass() != o.getClass()) return false;
134+
135+
LDUser ldUser = (LDUser) o;
136+
137+
if (key != null ? !key.equals(ldUser.key) : ldUser.key != null) return false;
138+
if (secondary != null ? !secondary.equals(ldUser.secondary) : ldUser.secondary != null) return false;
139+
if (ip != null ? !ip.equals(ldUser.ip) : ldUser.ip != null) return false;
140+
if (email != null ? !email.equals(ldUser.email) : ldUser.email != null) return false;
141+
if (name != null ? !name.equals(ldUser.name) : ldUser.name != null) return false;
142+
if (avatar != null ? !avatar.equals(ldUser.avatar) : ldUser.avatar != null) return false;
143+
if (firstName != null ? !firstName.equals(ldUser.firstName) : ldUser.firstName != null) return false;
144+
if (lastName != null ? !lastName.equals(ldUser.lastName) : ldUser.lastName != null) return false;
145+
if (anonymous != null ? !anonymous.equals(ldUser.anonymous) : ldUser.anonymous != null) return false;
146+
if (country != null ? !country.equals(ldUser.country) : ldUser.country != null) return false;
147+
return custom != null ? custom.equals(ldUser.custom) : ldUser.custom == null;
148+
}
149+
150+
@Override
151+
public int hashCode() {
152+
int result = key != null ? key.hashCode() : 0;
153+
result = 31 * result + (secondary != null ? secondary.hashCode() : 0);
154+
result = 31 * result + (ip != null ? ip.hashCode() : 0);
155+
result = 31 * result + (email != null ? email.hashCode() : 0);
156+
result = 31 * result + (name != null ? name.hashCode() : 0);
157+
result = 31 * result + (avatar != null ? avatar.hashCode() : 0);
158+
result = 31 * result + (firstName != null ? firstName.hashCode() : 0);
159+
result = 31 * result + (lastName != null ? lastName.hashCode() : 0);
160+
result = 31 * result + (anonymous != null ? anonymous.hashCode() : 0);
161+
result = 31 * result + (country != null ? country.hashCode() : 0);
162+
result = 31 * result + (custom != null ? custom.hashCode() : 0);
163+
return result;
164+
}
165+
129166
/**
130167
* A <a href="http://en.wikipedia.org/wiki/Builder_pattern">builder</a> that helps construct {@link LDUser} objects. Builder
131168
* calls can be chained, enabling the following pattern:

0 commit comments

Comments
 (0)