Skip to content
This repository has been archived by the owner on Sep 28, 2021. It is now read-only.

Commit

Permalink
Close down okhttp dispatcher executor
Browse files Browse the repository at this point in the history
  • Loading branch information
rouzwawi committed Jul 22, 2016
1 parent d2756bd commit 06d7e83
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
1 change: 0 additions & 1 deletion modules/jetty-http-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
<dependency>
<groupId>com.squareup.okhttp</groupId>
<artifactId>okhttp</artifactId>
<version>2.5.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
4 changes: 4 additions & 0 deletions modules/okhttp-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
<groupId>com.squareup.okhttp</groupId>
<artifactId>okhttp</artifactId>
</dependency>
<dependency>
<groupId>com.spotify</groupId>
<artifactId>apollo-extra</artifactId>
</dependency>

<dependency>
<groupId>junit</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@
*/
package com.spotify.apollo.http.client;

import com.google.common.io.Closer;
import com.google.inject.Inject;
import com.google.inject.Provider;

import com.spotify.apollo.concurrent.ExecutorServiceCloser;
import com.squareup.okhttp.ConnectionPool;
import com.squareup.okhttp.OkHttpClient;
import com.typesafe.config.Config;
Expand All @@ -33,10 +36,12 @@
class OkHttpClientProvider implements Provider<OkHttpClient> {

private final OkHttpClientConfig config;
private final Closer closer;

@Inject
OkHttpClientProvider(Config config) {
OkHttpClientProvider(Config config, Closer closer) {
this.config = new OkHttpClientConfig(config);
this.closer = closer;
}

@Override
Expand Down Expand Up @@ -66,6 +71,8 @@ public OkHttpClient get() {
config.maxAsyncRequestsPerHost().ifPresent(
max -> client.getDispatcher().setMaxRequestsPerHost(max));

closer.register(ExecutorServiceCloser.of(client.getDispatcher().getExecutorService()));

return client;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*/
package com.spotify.apollo.http.client;

import com.google.common.io.Closer;

import com.squareup.okhttp.OkHttpClient;
import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
Expand All @@ -31,7 +33,8 @@ public class OkHttpClientProviderTest {

private static OkHttpClient buildClient(final String str) {
final Config config = ConfigFactory.parseString(str);
final OkHttpClientProvider provider = new OkHttpClientProvider(config);
final Closer closer = Closer.create();
final OkHttpClientProvider provider = new OkHttpClientProvider(config, closer);
return provider.get();
}

Expand Down

0 comments on commit 06d7e83

Please sign in to comment.