57
57
* Http Web Services. This client is asynchronous and uses non-blocking IO.
58
58
*
59
59
* <p>This can be created via {@link #builder()}</p>
60
+ * {@snippet :
61
+ SdkAsyncHttpClient client = AwsCrtAsyncHttpClient.builder()
62
+ .maxConcurrency(100)
63
+ .connectionTimeout(Duration.ofSeconds(1))
64
+ .connectionMaxIdleTime(Duration.ofSeconds(5))
65
+ .build();
66
+ * }
67
+ *
60
68
*
61
69
* <b>NOTE:</b> This is a Preview API and is subject to change so it should not be used in production.
62
70
*/
@@ -89,24 +97,20 @@ public final class AwsCrtAsyncHttpClient implements SdkAsyncHttpClient {
89
97
private boolean isClosed = false ;
90
98
91
99
private AwsCrtAsyncHttpClient (DefaultBuilder builder , AttributeMap config ) {
92
- int maxConns = config .get (SdkHttpConfigurationOption .MAX_CONNECTIONS );
93
-
94
- Validate .isPositive (maxConns , "maxConns" );
95
- Validate .notNull (builder .cipherPreference , "cipherPreference" );
96
- Validate .isPositive (builder .readBufferSize , "readBufferSize" );
97
100
98
101
try (ClientBootstrap clientBootstrap = new ClientBootstrap (null , null );
99
102
SocketOptions clientSocketOptions = buildSocketOptions (builder , config );
100
- TlsContextOptions clientTlsContextOptions = TlsContextOptions .createDefaultClient () // NOSONAR
101
- .withCipherPreference (builder .cipherPreference )
102
- .withVerifyPeer (!config .get (SdkHttpConfigurationOption .TRUST_ALL_CERTIFICATES ));
103
+ TlsContextOptions clientTlsContextOptions =
104
+ TlsContextOptions .createDefaultClient ()
105
+ .withCipherPreference (TlsCipherPreference .TLS_CIPHER_SYSTEM_DEFAULT )
106
+ .withVerifyPeer (!config .get (SdkHttpConfigurationOption .TRUST_ALL_CERTIFICATES ));
103
107
TlsContext clientTlsContext = new TlsContext (clientTlsContextOptions )) {
104
108
105
109
this .bootstrap = registerOwnedResource (clientBootstrap );
106
110
this .socketOptions = registerOwnedResource (clientSocketOptions );
107
111
this .tlsContext = registerOwnedResource (clientTlsContext );
108
- this .readBufferSize = builder .readBufferSize ;
109
- this .maxConnectionsPerEndpoint = maxConns ;
112
+ this .readBufferSize = builder .readBufferSize == null ? DEFAULT_STREAM_WINDOW_SIZE : builder . readBufferSize ;
113
+ this .maxConnectionsPerEndpoint = config . get ( SdkHttpConfigurationOption . MAX_CONNECTIONS ) ;
110
114
this .monitoringOptions = revolveHttpMonitoringOptions (builder .connectionHealthChecksConfiguration );
111
115
this .maxConnectionIdleInMilliseconds = config .get (SdkHttpConfigurationOption .CONNECTION_MAX_IDLE_TIMEOUT ).toMillis ();
112
116
this .proxyOptions = buildProxyOptions (builder .proxyConfiguration );
@@ -317,14 +321,7 @@ public interface Builder extends SdkAsyncHttpClient.Builder<AwsCrtAsyncHttpClien
317
321
* @param maxConcurrency maximum concurrency per endpoint
318
322
* @return The builder of the method chaining.
319
323
*/
320
- Builder maxConcurrency (int maxConcurrency );
321
-
322
- /**
323
- * The AWS CRT TlsCipherPreference to use for this Client
324
- * @param tlsCipherPreference The AWS Common Runtime TlsCipherPreference
325
- * @return The builder of the method chaining.
326
- */
327
- Builder tlsCipherPreference (TlsCipherPreference tlsCipherPreference );
324
+ Builder maxConcurrency (Integer maxConcurrency );
328
325
329
326
/**
330
327
* Configures the number of unread bytes that can be buffered in the
@@ -336,7 +333,7 @@ public interface Builder extends SdkAsyncHttpClient.Builder<AwsCrtAsyncHttpClien
336
333
*
337
334
* TODO: This is also used for the write buffer size. Should we rename it?
338
335
*/
339
- Builder readBufferSize ( int readBufferSize );
336
+ Builder readBufferSizeInBytes ( Integer readBufferSize );
340
337
341
338
/**
342
339
* Sets the http proxy configuration to use for this client.
@@ -357,8 +354,10 @@ public interface Builder extends SdkAsyncHttpClient.Builder<AwsCrtAsyncHttpClien
357
354
* Configure the health checks for all connections established by this client.
358
355
*
359
356
* <p>
360
- * eg: you can set a throughput threshold for a connection to be considered healthy.
361
- * If the connection falls below this threshold for a configurable amount of time,
357
+ * You can set a throughput threshold for a connection to be considered healthy.
358
+ * If a connection falls below this threshold ({@link ConnectionHealthChecksConfiguration#minThroughputInBytesPerSecond()
359
+ * }) for the configurable amount
360
+ * of time ({@link ConnectionHealthChecksConfiguration#allowableThroughputFailureInterval()}),
362
361
* then the connection is considered unhealthy and will be shut down.
363
362
*
364
363
* @param healthChecksConfiguration The health checks config to use
@@ -367,12 +366,8 @@ public interface Builder extends SdkAsyncHttpClient.Builder<AwsCrtAsyncHttpClien
367
366
Builder connectionHealthChecksConfiguration (ConnectionHealthChecksConfiguration healthChecksConfiguration );
368
367
369
368
/**
370
- * A convenience method to configure the health checks for all connections established by this client.
371
- *
372
- * <p>
373
- * eg: you can set a throughput threshold for a connection to be considered healthy.
374
- * If the connection falls below this threshold for a configurable amount of time,
375
- * then the connection is considered unhealthy and will be shut down.
369
+ * A convenience method that creates an instance of the {@link ConnectionHealthChecksConfiguration} builder, avoiding the
370
+ * need to create one manually via {@link ConnectionHealthChecksConfiguration#builder()}.
376
371
*
377
372
* @param healthChecksConfigurationBuilder The health checks config builder to use
378
373
* @return The builder of the method chaining.
@@ -382,43 +377,44 @@ Builder connectionHealthChecksConfiguration(Consumer<ConnectionHealthChecksConfi
382
377
healthChecksConfigurationBuilder );
383
378
384
379
/**
385
- * The amount of time to wait when initially establishing a connection before giving up and timing out. The maximum
386
- * possible value, in ms, is the value of {@link Integer#MAX_VALUE}, any longer duration will be reduced to the maximum
387
- * possible value. If not specified, the connection timeout duration will be set to value defined in
388
- * {@link AwsCrtAsyncHttpClient#CRT_SDK_DEFAULT_CONNECTION_TIMEOUT}.
380
+ * Configure the maximum amount of time that a connection should be allowed to remain open while idle.
381
+ * @param connectionMaxIdleTime the maximum amount of connection idle time
382
+ * @return The builder of the method chaining.
389
383
*/
390
384
Builder connectionMaxIdleTime (Duration connectionMaxIdleTime );
391
385
392
386
/**
393
- * Configure connection socket timeout
387
+ * The amount of time to wait when initially establishing a connection before giving up and timing out.
388
+ * @param connectionTimeout timeout
389
+ * @return The builder of the method chaining.
394
390
*/
395
391
Builder connectionTimeout (Duration connectionTimeout );
396
392
397
393
/**
398
- * Configure whether to enable TCP Keep-alive and relevant configuration for all connections established by this client.
394
+ * Configure whether to enable {@code tcpKeepAlive} and relevant configuration for all connections established by this
395
+ * client.
399
396
*
400
397
* <p>
401
- * By default, keepAlive is disabled and this is not required.
402
- * tcpKeepAlive is enabled by providing this configuration and specifying
403
- * periodic keepalive packet intervals and timeouts
404
- * This may be required for certain connections for longer durations than default socket timeouts
398
+ * By default, tcpKeepAlive is disabled. You can enable {@code tcpKeepAlive} by providing this configuration
399
+ * and specifying periodic TCP keepalive packet intervals and timeouts. This may be required for certain connections for
400
+ * longer durations than default socket timeouts.
405
401
*
406
402
* @param tcpKeepAliveConfiguration The TCP keep-alive configuration to use
407
403
* @return The builder of the method chaining.
408
404
*/
409
405
Builder tcpKeepAliveConfiguration (TcpKeepAliveConfiguration tcpKeepAliveConfiguration );
410
406
411
407
/**
412
- * Configure whether to enable TCP Keep-alive and relevant configuration for all connections established by this client.
408
+ * Configure whether to enable {@code tcpKeepAlive} and relevant configuration for all connections established by this
409
+ * client.
413
410
*
414
411
* <p>
415
- * By default, keepAlive is disabled and this is not required.
416
- * tcpKeepAlive is enabled by providing this configuration and specifying
417
- * periodic keepalive packet intervals and timeouts
418
- * This may be required for certain connections for longer durations than default socket timeouts
412
+ * A convenience method that creates an instance of the {@link TcpKeepAliveConfiguration} builder, avoiding the
413
+ * need to create one manually via {@link TcpKeepAliveConfiguration#builder()}.
419
414
*
420
415
* @param tcpKeepAliveConfigurationBuilder The TCP keep-alive configuration builder to use
421
416
* @return The builder of the method chaining.
417
+ * @see #tcpKeepAliveConfiguration(TcpKeepAliveConfiguration)
422
418
*/
423
419
Builder tcpKeepAliveConfiguration (Consumer <TcpKeepAliveConfiguration .Builder >
424
420
tcpKeepAliveConfigurationBuilder );
@@ -430,8 +426,7 @@ Builder tcpKeepAliveConfiguration(Consumer<TcpKeepAliveConfiguration.Builder>
430
426
*/
431
427
private static final class DefaultBuilder implements Builder {
432
428
private final AttributeMap .Builder standardOptions = AttributeMap .builder ();
433
- private TlsCipherPreference cipherPreference = TlsCipherPreference .TLS_CIPHER_SYSTEM_DEFAULT ;
434
- private int readBufferSize = DEFAULT_STREAM_WINDOW_SIZE ;
429
+ private Integer readBufferSize ;
435
430
private ProxyConfiguration proxyConfiguration ;
436
431
private ConnectionHealthChecksConfiguration connectionHealthChecksConfiguration ;
437
432
private TcpKeepAliveConfiguration tcpKeepAliveConfiguration ;
@@ -455,24 +450,15 @@ public SdkAsyncHttpClient buildWithDefaults(AttributeMap serviceDefaults) {
455
450
}
456
451
457
452
@ Override
458
- public Builder maxConcurrency (int maxConcurrency ) {
459
- Validate .isPositive (maxConcurrency , "maxConcurrency" );
453
+ public Builder maxConcurrency (Integer maxConcurrency ) {
454
+ Validate .isPositiveOrNull (maxConcurrency , "maxConcurrency" );
460
455
standardOptions .put (SdkHttpConfigurationOption .MAX_CONNECTIONS , maxConcurrency );
461
456
return this ;
462
457
}
463
458
464
459
@ Override
465
- public Builder tlsCipherPreference (TlsCipherPreference tlsCipherPreference ) {
466
- Validate .notNull (tlsCipherPreference , "cipherPreference" );
467
- Validate .isTrue (TlsContextOptions .isCipherPreferenceSupported (tlsCipherPreference ),
468
- "TlsCipherPreference not supported on current Platform" );
469
- this .cipherPreference = tlsCipherPreference ;
470
- return this ;
471
- }
472
-
473
- @ Override
474
- public Builder readBufferSize (int readBufferSize ) {
475
- Validate .isPositive (readBufferSize , "readBufferSize" );
460
+ public Builder readBufferSizeInBytes (Integer readBufferSize ) {
461
+ Validate .isPositiveOrNull (readBufferSize , "readBufferSize" );
476
462
this .readBufferSize = readBufferSize ;
477
463
return this ;
478
464
}
0 commit comments