Skip to content

Commit

Permalink
configs pool
Browse files Browse the repository at this point in the history
  • Loading branch information
otaviojava committed Jul 12, 2018
1 parent 8449c7a commit 172d769
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
Expand Up @@ -23,6 +23,7 @@
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.cache.CacheConfig;
import org.apache.http.impl.client.cache.CachingHttpClients;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;

class CouchDBHttpConfiguration {

Expand All @@ -31,8 +32,6 @@ class CouchDBHttpConfiguration {
private final int maxConnections;
private final int connectionTimeout;
private final int socketTimeout;
private final int proxyPort;
private final String proxy;
private final boolean enableSSL;

private final String username;
Expand All @@ -46,17 +45,15 @@ class CouchDBHttpConfiguration {


CouchDBHttpConfiguration(String host, int port, int maxConnections,
int connectionTimeout, int socketTimeout, int proxyPort,
String proxy, boolean enableSSL, String username, String password,
int connectionTimeout, int socketTimeout,
boolean enableSSL, String username, String password,
boolean compression, int maxObjectSizeBytes,
int maxCacheEntries) {
this.host = host;
this.port = port;
this.maxConnections = maxConnections;
this.connectionTimeout = connectionTimeout;
this.socketTimeout = socketTimeout;
this.proxyPort = proxyPort;
this.proxy = proxy;
this.enableSSL = enableSSL;
this.username = username;
this.password = password;
Expand Down Expand Up @@ -96,8 +93,13 @@ private CloseableHttpClient getHttpClient() {
.setSocketTimeout(socketTimeout)
.setContentCompressionEnabled(compression)
.build();

PoolingHttpClientConnectionManager pool = new PoolingHttpClientConnectionManager();
pool.setMaxTotal(maxConnections);

HttpClientBuilder builder = CachingHttpClients.custom()
.setCacheConfig(cacheConfig)
.setConnectionManager(pool)
.setDefaultRequestConfig(requestConfig);

if (username != null) {
Expand Down
Expand Up @@ -21,8 +21,6 @@ class CouchDBHttpConfigurationBuilder {
private int maxConnections = 20;
private int connectionTimeout = 1000;
private int socketTimeout = 10000;
private int proxyPort = -1;
private String proxy = null;
private boolean enableSSL = false;

private String username;
Expand Down Expand Up @@ -52,11 +50,6 @@ public CouchDBHttpConfigurationBuilder withSocketTimeout(int socketTimeout) {
return this;
}

public CouchDBHttpConfigurationBuilder withProxyPort(int proxyPort) {
this.proxyPort = proxyPort;
return this;
}

public CouchDBHttpConfigurationBuilder withMaxObjectSizeBytes(int maxObjectSizeBytes) {
this.maxObjectSizeBytes = maxObjectSizeBytes;
return this;
Expand All @@ -67,10 +60,6 @@ public CouchDBHttpConfigurationBuilder withMaxCacheEntries(int maxCacheEntries)
return this;
}

public CouchDBHttpConfigurationBuilder withProxy(String proxy) {
this.proxy = proxy;
return this;
}

public CouchDBHttpConfigurationBuilder withCompression(boolean compression) {
this.compression = compression;
Expand Down Expand Up @@ -99,7 +88,7 @@ public CouchDBHttpConfigurationBuilder withEnableSSL(boolean enableSSL) {

public CouchDBHttpConfiguration build() {
return new CouchDBHttpConfiguration(host, port, maxConnections, connectionTimeout,
socketTimeout, proxyPort, proxy, enableSSL, username, password,
socketTimeout, enableSSL, username, password,
compression,
maxObjectSizeBytes, maxCacheEntries);
}
Expand Down

0 comments on commit 172d769

Please sign in to comment.