19
19
import static java .util .stream .Collectors .mapping ;
20
20
import static java .util .stream .Collectors .toList ;
21
21
import static software .amazon .awssdk .http .SdkHttpConfigurationOption .CONNECTION_ACQUIRE_TIMEOUT ;
22
+ import static software .amazon .awssdk .http .SdkHttpConfigurationOption .CONNECTION_MAX_IDLE_TIMEOUT ;
22
23
import static software .amazon .awssdk .http .SdkHttpConfigurationOption .CONNECTION_TIMEOUT ;
24
+ import static software .amazon .awssdk .http .SdkHttpConfigurationOption .CONNECTION_TIME_TO_LIVE ;
23
25
import static software .amazon .awssdk .http .SdkHttpConfigurationOption .GLOBAL_HTTP_DEFAULTS ;
24
26
import static software .amazon .awssdk .http .SdkHttpConfigurationOption .MAX_CONNECTIONS ;
25
27
import static software .amazon .awssdk .http .SdkHttpConfigurationOption .READ_TIMEOUT ;
@@ -134,7 +136,7 @@ private ConnectionManagerAwareHttpClient createClient(ApacheHttpClient.DefaultBu
134
136
builder .setRequestExecutor (new HttpRequestExecutor ())
135
137
// SDK handles decompression
136
138
.disableContentCompression ()
137
- .setKeepAliveStrategy (buildKeepAliveStrategy (configuration ))
139
+ .setKeepAliveStrategy (buildKeepAliveStrategy (standardOptions ))
138
140
.disableRedirectHandling ()
139
141
.disableAutomaticRetries ()
140
142
.setUserAgent ("" ) // SDK will set the user agent header in the pipeline. Don't let Apache waste time
@@ -144,7 +146,7 @@ private ConnectionManagerAwareHttpClient createClient(ApacheHttpClient.DefaultBu
144
146
145
147
if (useIdleConnectionReaper (configuration )) {
146
148
IdleConnectionReaper .getInstance ().registerConnectionManager (
147
- cm , connectionMaxIdleTime ( configuration ).toMillis ());
149
+ cm , resolvedOptions . get ( SdkHttpConfigurationOption . CONNECTION_MAX_IDLE_TIMEOUT ).toMillis ());
148
150
}
149
151
150
152
return new ApacheSdkHttpClient (builder .build (), cm );
@@ -167,16 +169,11 @@ private void addProxyConfig(HttpClientBuilder builder,
167
169
}
168
170
}
169
171
170
- private ConnectionKeepAliveStrategy buildKeepAliveStrategy (ApacheHttpClient . DefaultBuilder configuration ) {
171
- long maxIdle = connectionMaxIdleTime ( configuration ).toMillis ();
172
+ private ConnectionKeepAliveStrategy buildKeepAliveStrategy (AttributeMap standardOptions ) {
173
+ long maxIdle = standardOptions . get ( SdkHttpConfigurationOption . CONNECTION_MAX_IDLE_TIMEOUT ).toMillis ();
172
174
return maxIdle > 0 ? new SdkConnectionKeepAliveStrategy (maxIdle ) : null ;
173
175
}
174
176
175
- private Duration connectionMaxIdleTime (DefaultBuilder configuration ) {
176
- return Optional .ofNullable (configuration .connectionMaxIdleTime )
177
- .orElse (DefaultConfiguration .MAX_IDLE_CONNECTION_TIME );
178
- }
179
-
180
177
private boolean useIdleConnectionReaper (DefaultBuilder configuration ) {
181
178
return Boolean .TRUE .equals (configuration .useIdleConnectionReaper );
182
179
}
@@ -336,7 +333,7 @@ public interface Builder extends SdkHttpClient.Builder<ApacheHttpClient.Builder>
336
333
* Configure whether the idle connections in the connection pool should be closed asynchronously.
337
334
* <p>
338
335
* When enabled, connections left idling for longer than {@link #connectionMaxIdleTime(Duration)} will be
339
- * closed. If no value is set, the default value of {@link DefaultConfiguration#MAX_IDLE_CONNECTION_TIME} is used .
336
+ * closed. This will not close connections currently in use. By default, this is enabled .
340
337
*/
341
338
Builder useIdleConnectionReaper (Boolean useConnectionReaper );
342
339
}
@@ -346,8 +343,6 @@ private static final class DefaultBuilder implements Builder {
346
343
private ProxyConfiguration proxyConfiguration = ProxyConfiguration .builder ().build ();
347
344
private InetAddress localAddress ;
348
345
private Boolean expectContinueEnabled ;
349
- private Duration connectionTimeToLive ;
350
- private Duration connectionMaxIdleTime ;
351
346
private Boolean useIdleConnectionReaper ;
352
347
353
348
private DefaultBuilder () {
@@ -431,7 +426,7 @@ public void setExpectContinueEnabled(Boolean useExpectContinue) {
431
426
432
427
@ Override
433
428
public Builder connectionTimeToLive (Duration connectionTimeToLive ) {
434
- this . connectionTimeToLive = connectionTimeToLive ;
429
+ standardOptions . put ( CONNECTION_TIME_TO_LIVE , connectionTimeToLive ) ;
435
430
return this ;
436
431
}
437
432
@@ -441,7 +436,7 @@ public void setConnectionTimeToLive(Duration connectionTimeToLive) {
441
436
442
437
@ Override
443
438
public Builder connectionMaxIdleTime (Duration maxIdleConnectionTimeout ) {
444
- this . connectionMaxIdleTime = maxIdleConnectionTimeout ;
439
+ standardOptions . put ( CONNECTION_MAX_IDLE_TIMEOUT , maxIdleConnectionTimeout ) ;
445
440
return this ;
446
441
}
447
442
@@ -478,9 +473,7 @@ public HttpClientConnectionManager create(ApacheHttpClient.DefaultBuilder config
478
473
null ,
479
474
DefaultSchemePortResolver .INSTANCE ,
480
475
null ,
481
- Optional .ofNullable (configuration .connectionTimeToLive )
482
- .orElse (DefaultConfiguration .CONNECTION_POOL_TTL )
483
- .toMillis (),
476
+ standardOptions .get (SdkHttpConfigurationOption .CONNECTION_TIME_TO_LIVE ).toMillis (),
484
477
TimeUnit .MILLISECONDS );
485
478
486
479
cm .setDefaultMaxPerRoute (standardOptions .get (SdkHttpConfigurationOption .MAX_CONNECTIONS ));
0 commit comments