@@ -108,6 +108,7 @@ public class AsyncHttpClientConfig {
108
108
protected HostnameVerifier hostnameVerifier ;
109
109
protected int ioThreadMultiplier ;
110
110
protected boolean strict302Handling ;
111
+ protected int maxConnectionLifeTimeInMs ;
111
112
112
113
protected AsyncHttpClientConfig () {
113
114
}
@@ -119,6 +120,7 @@ private AsyncHttpClientConfig(int maxTotalConnections,
119
120
int idleConnectionInPoolTimeoutInMs ,
120
121
int idleConnectionTimeoutInMs ,
121
122
int requestTimeoutInMs ,
123
+ int connectionMaxLifeTimeInMs ,
122
124
boolean redirectEnabled ,
123
125
int maxDefaultRedirects ,
124
126
boolean compressionEnabled ,
@@ -150,6 +152,7 @@ private AsyncHttpClientConfig(int maxTotalConnections,
150
152
this .idleConnectionInPoolTimeoutInMs = idleConnectionInPoolTimeoutInMs ;
151
153
this .idleConnectionTimeoutInMs = idleConnectionTimeoutInMs ;
152
154
this .requestTimeoutInMs = requestTimeoutInMs ;
155
+ this .maxConnectionLifeTimeInMs = connectionMaxLifeTimeInMs ;
153
156
this .redirectEnabled = redirectEnabled ;
154
157
this .maxDefaultRedirects = maxDefaultRedirects ;
155
158
this .compressionEnabled = compressionEnabled ;
@@ -500,6 +503,15 @@ public boolean isStrict302Handling() {
500
503
return strict302Handling ;
501
504
}
502
505
506
+ /**
507
+ * Return the maximum time in millisecond an {@link com.ning.http.client.AsyncHttpClient} will keep connection in the pool, or -1 to keep connection while possible.
508
+ *
509
+ * @return the maximum time in millisecond an {@link com.ning.http.client.AsyncHttpClient} will keep connection in the pool, or -1 to keep connection while possible.
510
+ */
511
+ public int getMaxConnectionLifeTimeInMs () {
512
+ return maxConnectionLifeTimeInMs ;
513
+ }
514
+
503
515
/**
504
516
* Builder for an {@link AsyncHttpClient}
505
517
*/
@@ -511,6 +523,7 @@ public static class Builder {
511
523
private int defaultIdleConnectionInPoolTimeoutInMs = Integer .getInteger (ASYNC_CLIENT + "defaultIdleConnectionInPoolTimeoutInMS" , 60 * 1000 );
512
524
private int defaultIdleConnectionTimeoutInMs = Integer .getInteger (ASYNC_CLIENT + "defaultIdleConnectionTimeoutInMS" , 60 * 1000 );
513
525
private int defaultRequestTimeoutInMs = Integer .getInteger (ASYNC_CLIENT + "defaultRequestTimeoutInMS" , 60 * 1000 );
526
+ private int defaultMaxConnectionLifeTimeInMs = Integer .getInteger (ASYNC_CLIENT + "defaultMaxConnectionLifeTimeInMs" , -1 );
514
527
private boolean redirectEnabled = Boolean .getBoolean (ASYNC_CLIENT + "defaultRedirectsEnabled" );
515
528
private int maxDefaultRedirects = Integer .getInteger (ASYNC_CLIENT + "defaultMaxRedirects" , 5 );
516
529
private boolean compressionEnabled = Boolean .getBoolean (ASYNC_CLIENT + "compressionEnabled" );
@@ -980,6 +993,17 @@ public Builder setStrict302Handling(final boolean strict302Handling) {
980
993
return this ;
981
994
}
982
995
996
+ /**
997
+ * Set the maximum time in millisecond connection can be added to the pool for further reuse
998
+ *
999
+ * @param maxConnectionLifeTimeInMs the maximum time in millisecond connection can be added to the pool for further reuse
1000
+ * @return a {@link Builder}
1001
+ */
1002
+ public Builder setMaxConnectionLifeTimeInMs (int maxConnectionLifeTimeInMs ) {
1003
+ this .defaultMaxConnectionLifeTimeInMs = maxConnectionLifeTimeInMs ;
1004
+ return this ;
1005
+ }
1006
+
983
1007
/**
984
1008
* Create a config builder with values taken from the given prototype configuration.
985
1009
*
@@ -993,6 +1017,7 @@ public Builder(AsyncHttpClientConfig prototype) {
993
1017
defaultIdleConnectionInPoolTimeoutInMs = prototype .getIdleConnectionInPoolTimeoutInMs ();
994
1018
defaultIdleConnectionTimeoutInMs = prototype .getIdleConnectionTimeoutInMs ();
995
1019
defaultMaxConnectionPerHost = prototype .getMaxConnectionPerHost ();
1020
+ defaultMaxConnectionLifeTimeInMs = prototype .getMaxConnectionLifeTimeInMs ();
996
1021
maxDefaultRedirects = prototype .getMaxRedirects ();
997
1022
defaultMaxTotalConnections = prototype .getMaxTotalConnections ();
998
1023
proxyServer = prototype .getProxyServer ();
@@ -1046,6 +1071,7 @@ public AsyncHttpClientConfig build() {
1046
1071
defaultIdleConnectionInPoolTimeoutInMs ,
1047
1072
defaultIdleConnectionTimeoutInMs ,
1048
1073
defaultRequestTimeoutInMs ,
1074
+ defaultMaxConnectionLifeTimeInMs ,
1049
1075
redirectEnabled ,
1050
1076
maxDefaultRedirects ,
1051
1077
compressionEnabled ,
0 commit comments