71
71
72
72
import com .arangodb .ArangoDBException ;
73
73
import com .arangodb .entity .ErrorEntity ;
74
+ import com .arangodb .internal .ArangoDBConstants ;
74
75
import com .arangodb .internal .util .CURLLogger ;
75
76
import com .arangodb .internal .util .IOUtils ;
76
77
import com .arangodb .internal .velocystream .Host ;
@@ -101,7 +102,7 @@ public static class Builder {
101
102
private Boolean useSsl ;
102
103
private SSLContext sslContext ;
103
104
// private Integer chunksize;
104
- // private Integer maxConnections;
105
+ private Integer maxConnections ;
105
106
106
107
public Builder (final HostHandler hostHandler ) {
107
108
super ();
@@ -138,13 +139,13 @@ public Builder sslContext(final SSLContext sslContext) {
138
139
// return this;
139
140
// }
140
141
//
141
- // public Builder maxConnections(final Integer maxConnections) {
142
- // this.maxConnections = maxConnections;
143
- // return this;
144
- // }
142
+ public Builder maxConnections (final Integer maxConnections ) {
143
+ this .maxConnections = maxConnections ;
144
+ return this ;
145
+ }
145
146
146
147
public HttpCommunication build (final ArangoSerialization util ) {
147
- return new HttpCommunication (timeout , user , password , useSsl , sslContext , util , hostHandler ,
148
+ return new HttpCommunication (timeout , user , password , useSsl , sslContext , util , hostHandler , maxConnections ,
148
149
HttpContentType .JSON );
149
150
}
150
151
}
@@ -165,7 +166,7 @@ public HttpCommunication build(final ArangoSerialization util) {
165
166
166
167
private HttpCommunication (final Integer timeout , final String user , final String password , final Boolean useSsl ,
167
168
final SSLContext sslContext , final ArangoSerialization util , final HostHandler hostHandler ,
168
- final HttpContentType contentType ) {
169
+ final Integer maxConnections , final HttpContentType contentType ) {
169
170
super ();
170
171
this .user = user ;
171
172
this .password = password ;
@@ -185,8 +186,10 @@ private HttpCommunication(final Integer timeout, final String user, final String
185
186
a .register ("http" , new PlainConnectionSocketFactory ());
186
187
}
187
188
cm = new PoolingHttpClientConnectionManager (a .build ());
188
- cm .setDefaultMaxPerRoute (20 );// TODO configurable
189
- cm .setMaxTotal (20 );// TODO configurable
189
+ final int connections = maxConnections != null ? Math .max (1 , maxConnections )
190
+ : ArangoDBConstants .MAX_CONNECTIONS_HTTP_DEFAULT ;
191
+ cm .setDefaultMaxPerRoute (connections );
192
+ cm .setMaxTotal (connections );
190
193
191
194
final RequestConfig .Builder custom = RequestConfig .custom ();
192
195
// if (configure.getConnectionTimeout() >= 0) {
0 commit comments