diff --git a/.changes/next-release/feature-AWSCRTHTTPClient-588257d.json b/.changes/next-release/feature-AWSCRTHTTPClient-588257d.json new file mode 100644 index 000000000000..2b9b0d02a68c --- /dev/null +++ b/.changes/next-release/feature-AWSCRTHTTPClient-588257d.json @@ -0,0 +1,6 @@ +{ + "type": "feature", + "category": "AWS CRT HTTP Client", + "contributor": "", + "description": "Renamed `readBufferSize` -> `readBufferSizeInBytes`." +} diff --git a/.changes/next-release/removal-AWSCRTHTTPClient-79e0d39.json b/.changes/next-release/removal-AWSCRTHTTPClient-79e0d39.json new file mode 100644 index 000000000000..27fde7099a6e --- /dev/null +++ b/.changes/next-release/removal-AWSCRTHTTPClient-79e0d39.json @@ -0,0 +1,6 @@ +{ + "type": "removal", + "category": "AWS CRT HTTP Client", + "contributor": "", + "description": "Removed `tlsCipherPreference`." +} diff --git a/http-clients/aws-crt-client/src/main/java/software/amazon/awssdk/http/crt/AwsCrtAsyncHttpClient.java b/http-clients/aws-crt-client/src/main/java/software/amazon/awssdk/http/crt/AwsCrtAsyncHttpClient.java index 272a4fdf1546..08c7e89d9f4b 100644 --- a/http-clients/aws-crt-client/src/main/java/software/amazon/awssdk/http/crt/AwsCrtAsyncHttpClient.java +++ b/http-clients/aws-crt-client/src/main/java/software/amazon/awssdk/http/crt/AwsCrtAsyncHttpClient.java @@ -57,6 +57,14 @@ * Http Web Services. This client is asynchronous and uses non-blocking IO. * *

This can be created via {@link #builder()}

+ * {@snippet : + SdkAsyncHttpClient client = AwsCrtAsyncHttpClient.builder() + .maxConcurrency(100) + .connectionTimeout(Duration.ofSeconds(1)) + .connectionMaxIdleTime(Duration.ofSeconds(5)) + .build(); + * } + * * * NOTE: This is a Preview API and is subject to change so it should not be used in production. */ @@ -89,24 +97,20 @@ public final class AwsCrtAsyncHttpClient implements SdkAsyncHttpClient { private boolean isClosed = false; private AwsCrtAsyncHttpClient(DefaultBuilder builder, AttributeMap config) { - int maxConns = config.get(SdkHttpConfigurationOption.MAX_CONNECTIONS); - - Validate.isPositive(maxConns, "maxConns"); - Validate.notNull(builder.cipherPreference, "cipherPreference"); - Validate.isPositive(builder.readBufferSize, "readBufferSize"); try (ClientBootstrap clientBootstrap = new ClientBootstrap(null, null); SocketOptions clientSocketOptions = buildSocketOptions(builder, config); - TlsContextOptions clientTlsContextOptions = TlsContextOptions.createDefaultClient() // NOSONAR - .withCipherPreference(builder.cipherPreference) - .withVerifyPeer(!config.get(SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES)); + TlsContextOptions clientTlsContextOptions = + TlsContextOptions.createDefaultClient() + .withCipherPreference(TlsCipherPreference.TLS_CIPHER_SYSTEM_DEFAULT) + .withVerifyPeer(!config.get(SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES)); TlsContext clientTlsContext = new TlsContext(clientTlsContextOptions)) { this.bootstrap = registerOwnedResource(clientBootstrap); this.socketOptions = registerOwnedResource(clientSocketOptions); this.tlsContext = registerOwnedResource(clientTlsContext); - this.readBufferSize = builder.readBufferSize; - this.maxConnectionsPerEndpoint = maxConns; + this.readBufferSize = builder.readBufferSize == null ? DEFAULT_STREAM_WINDOW_SIZE : builder.readBufferSize; + this.maxConnectionsPerEndpoint = config.get(SdkHttpConfigurationOption.MAX_CONNECTIONS); this.monitoringOptions = revolveHttpMonitoringOptions(builder.connectionHealthChecksConfiguration); this.maxConnectionIdleInMilliseconds = config.get(SdkHttpConfigurationOption.CONNECTION_MAX_IDLE_TIMEOUT).toMillis(); this.proxyOptions = buildProxyOptions(builder.proxyConfiguration); @@ -317,14 +321,7 @@ public interface Builder extends SdkAsyncHttpClient.Builder - * eg: you can set a throughput threshold for a connection to be considered healthy. - * If the connection falls below this threshold for a configurable amount of time, + * You can set a throughput threshold for a connection to be considered healthy. + * If a connection falls below this threshold ({@link ConnectionHealthChecksConfiguration#minThroughputInBytesPerSecond() + * }) for the configurable amount + * of time ({@link ConnectionHealthChecksConfiguration#allowableThroughputFailureInterval()}), * then the connection is considered unhealthy and will be shut down. * * @param healthChecksConfiguration The health checks config to use @@ -367,12 +366,8 @@ public interface Builder extends SdkAsyncHttpClient.Builder - * eg: you can set a throughput threshold for a connection to be considered healthy. - * If the connection falls below this threshold for a configurable amount of time, - * then the connection is considered unhealthy and will be shut down. + * A convenience method that creates an instance of the {@link ConnectionHealthChecksConfiguration} builder, avoiding the + * need to create one manually via {@link ConnectionHealthChecksConfiguration#builder()}. * * @param healthChecksConfigurationBuilder The health checks config builder to use * @return The builder of the method chaining. @@ -382,26 +377,27 @@ Builder connectionHealthChecksConfiguration(Consumer - * By default, keepAlive is disabled and this is not required. - * tcpKeepAlive is enabled by providing this configuration and specifying - * periodic keepalive packet intervals and timeouts - * This may be required for certain connections for longer durations than default socket timeouts + * By default, tcpKeepAlive is disabled. You can enable {@code tcpKeepAlive} by providing this configuration + * and specifying periodic TCP keepalive packet intervals and timeouts. This may be required for certain connections for + * longer durations than default socket timeouts. * * @param tcpKeepAliveConfiguration The TCP keep-alive configuration to use * @return The builder of the method chaining. @@ -409,16 +405,16 @@ Builder connectionHealthChecksConfiguration(Consumer - * By default, keepAlive is disabled and this is not required. - * tcpKeepAlive is enabled by providing this configuration and specifying - * periodic keepalive packet intervals and timeouts - * This may be required for certain connections for longer durations than default socket timeouts + * A convenience method that creates an instance of the {@link TcpKeepAliveConfiguration} builder, avoiding the + * need to create one manually via {@link TcpKeepAliveConfiguration#builder()}. * * @param tcpKeepAliveConfigurationBuilder The TCP keep-alive configuration builder to use * @return The builder of the method chaining. + * @see #tcpKeepAliveConfiguration(TcpKeepAliveConfiguration) */ Builder tcpKeepAliveConfiguration(Consumer tcpKeepAliveConfigurationBuilder); @@ -430,8 +426,7 @@ Builder tcpKeepAliveConfiguration(Consumer */ private static final class DefaultBuilder implements Builder { private final AttributeMap.Builder standardOptions = AttributeMap.builder(); - private TlsCipherPreference cipherPreference = TlsCipherPreference.TLS_CIPHER_SYSTEM_DEFAULT; - private int readBufferSize = DEFAULT_STREAM_WINDOW_SIZE; + private Integer readBufferSize; private ProxyConfiguration proxyConfiguration; private ConnectionHealthChecksConfiguration connectionHealthChecksConfiguration; private TcpKeepAliveConfiguration tcpKeepAliveConfiguration; @@ -455,24 +450,15 @@ public SdkAsyncHttpClient buildWithDefaults(AttributeMap serviceDefaults) { } @Override - public Builder maxConcurrency(int maxConcurrency) { - Validate.isPositive(maxConcurrency, "maxConcurrency"); + public Builder maxConcurrency(Integer maxConcurrency) { + Validate.isPositiveOrNull(maxConcurrency, "maxConcurrency"); standardOptions.put(SdkHttpConfigurationOption.MAX_CONNECTIONS, maxConcurrency); return this; } @Override - public Builder tlsCipherPreference(TlsCipherPreference tlsCipherPreference) { - Validate.notNull(tlsCipherPreference, "cipherPreference"); - Validate.isTrue(TlsContextOptions.isCipherPreferenceSupported(tlsCipherPreference), - "TlsCipherPreference not supported on current Platform"); - this.cipherPreference = tlsCipherPreference; - return this; - } - - @Override - public Builder readBufferSize(int readBufferSize) { - Validate.isPositive(readBufferSize, "readBufferSize"); + public Builder readBufferSizeInBytes(Integer readBufferSize) { + Validate.isPositiveOrNull(readBufferSize, "readBufferSize"); this.readBufferSize = readBufferSize; return this; }