@@ -114,6 +114,7 @@ public class AsyncHttpClientConfig {
114
114
protected int spdyInitialWindowSize ;
115
115
protected int spdyMaxConcurrentStreams ;
116
116
protected boolean rfc6265CookieEncoding ;
117
+ protected boolean asyncConnectMode ;
117
118
118
119
protected AsyncHttpClientConfig () {
119
120
}
@@ -153,7 +154,8 @@ private AsyncHttpClientConfig(int maxTotalConnections,
153
154
boolean spdyEnabled ,
154
155
int spdyInitialWindowSize ,
155
156
int spdyMaxConcurrentStreams ,
156
- boolean rfc6265CookieEncoding ) {
157
+ boolean rfc6265CookieEncoding ,
158
+ boolean asyncConnectMode ) {
157
159
158
160
this .maxTotalConnections = maxTotalConnections ;
159
161
this .maxConnectionPerHost = maxConnectionPerHost ;
@@ -197,6 +199,7 @@ private AsyncHttpClientConfig(int maxTotalConnections,
197
199
this .spdyInitialWindowSize = spdyInitialWindowSize ;
198
200
this .spdyMaxConcurrentStreams = spdyMaxConcurrentStreams ;
199
201
this .rfc6265CookieEncoding = rfc6265CookieEncoding ;
202
+ this .asyncConnectMode = asyncConnectMode ;
200
203
}
201
204
202
205
/**
@@ -567,6 +570,16 @@ public boolean isRfc6265CookieEncoding() {
567
570
return rfc6265CookieEncoding ;
568
571
}
569
572
573
+ /**
574
+ * @return <code>true</code> if the underlying provider should make new connections asynchronously or not. By default
575
+ * new connections are made synchronously.
576
+ *
577
+ * @since 2.0.0
578
+ */
579
+ public boolean isAsyncConnectMode () {
580
+ return asyncConnectMode ;
581
+ }
582
+
570
583
/**
571
584
* Builder for an {@link AsyncHttpClient}
572
585
*/
@@ -609,6 +622,7 @@ public static class Builder {
609
622
private int spdyInitialWindowSize = 10 * 1024 * 1024 ;
610
623
private int spdyMaxConcurrentStreams = 100 ;
611
624
private boolean rfc6265CookieEncoding ;
625
+ private boolean asyncConnectMode ;
612
626
613
627
public Builder () {
614
628
}
@@ -1121,6 +1135,21 @@ public Builder setRfc6265CookieEncoding(boolean rfc6265CookieEncoding) {
1121
1135
return this ;
1122
1136
}
1123
1137
1138
+ /**
1139
+ * Configures how the underlying providers make new connections. By default,
1140
+ * connections will be made synchronously.
1141
+ *
1142
+ * @param asyncConnectMode pass <code>true</code> to enable async connect mode.
1143
+ *
1144
+ * @return this
1145
+ *
1146
+ * @since 2.0.0
1147
+ */
1148
+ public Builder setAsyncConnectMode (boolean asyncConnectMode ) {
1149
+ this .asyncConnectMode = asyncConnectMode ;
1150
+ return this ;
1151
+ }
1152
+
1124
1153
/**
1125
1154
* Create a config builder with values taken from the given prototype configuration.
1126
1155
*
@@ -1166,6 +1195,7 @@ public Builder(AsyncHttpClientConfig prototype) {
1166
1195
strict302Handling = prototype .isStrict302Handling ();
1167
1196
useRelativeURIsWithSSLProxies = prototype .isUseRelativeURIsWithSSLProxies ();
1168
1197
rfc6265CookieEncoding = prototype .isRfc6265CookieEncoding ();
1198
+ asyncConnectMode = prototype .isAsyncConnectMode ();
1169
1199
}
1170
1200
1171
1201
/**
@@ -1184,16 +1214,18 @@ public Thread newThread(Runnable r) {
1184
1214
}
1185
1215
});
1186
1216
}
1187
-
1188
- if (applicationThreadPool == null ) {
1189
- applicationThreadPool = Executors .newCachedThreadPool (new ThreadFactory () {
1190
- public Thread newThread (Runnable r ) {
1191
- Thread t = new Thread (r , "AsyncHttpClient-Callback" );
1192
- t .setDaemon (true );
1193
- return t ;
1194
- }
1195
- });
1196
- }
1217
+
1218
+ if (applicationThreadPool == null ) {
1219
+ applicationThreadPool =
1220
+ Executors .newCachedThreadPool (new ThreadFactory () {
1221
+ public Thread newThread (Runnable r ) {
1222
+ Thread t = new Thread (r ,
1223
+ "AsyncHttpClient-Callback" );
1224
+ t .setDaemon (true );
1225
+ return t ;
1226
+ }
1227
+ });
1228
+ }
1197
1229
1198
1230
if (applicationThreadPool .isShutdown ()) {
1199
1231
throw new IllegalStateException ("ExecutorServices closed" );
@@ -1239,7 +1271,8 @@ public Thread newThread(Runnable r) {
1239
1271
spdyEnabled ,
1240
1272
spdyInitialWindowSize ,
1241
1273
spdyMaxConcurrentStreams ,
1242
- rfc6265CookieEncoding );
1274
+ rfc6265CookieEncoding ,
1275
+ asyncConnectMode );
1243
1276
}
1244
1277
}
1245
1278
}
0 commit comments