76
76
@ SdkPublicApi
77
77
public final class NettyNioAsyncHttpClient implements SdkAsyncHttpClient {
78
78
private static final Logger log = LoggerFactory .getLogger (NettyNioAsyncHttpClient .class );
79
+ private static final long MAX_STREAMS_ALLOWED = 4294967295L ; // unsigned 32-bit, 2^32 -1
79
80
80
81
private final SdkEventLoopGroup sdkEventLoopGroup ;
81
82
private final SdkChannelPoolMap <URI , ChannelPool > pools ;
@@ -87,7 +88,7 @@ public final class NettyNioAsyncHttpClient implements SdkAsyncHttpClient {
87
88
NettyNioAsyncHttpClient (DefaultBuilder builder , AttributeMap serviceDefaultsMap ) {
88
89
this .configuration = new NettyConfiguration (serviceDefaultsMap );
89
90
this .protocol = serviceDefaultsMap .get (SdkHttpConfigurationOption .PROTOCOL );
90
- this .maxStreams = builder .maxHttp2Streams == null ? Integer . MAX_VALUE : builder .maxHttp2Streams ;
91
+ this .maxStreams = builder .maxHttp2Streams == null ? MAX_STREAMS_ALLOWED : builder .maxHttp2Streams ;
91
92
this .sdkEventLoopGroup = eventLoopGroup (builder );
92
93
this .pools = createChannelPoolMap ();
93
94
this .sdkChannelOptions = channelOptions (builder );
@@ -106,10 +107,6 @@ public final class NettyNioAsyncHttpClient implements SdkAsyncHttpClient {
106
107
this .maxStreams = maxStreams ;
107
108
}
108
109
109
- private SdkChannelOptions channelOptions (DefaultBuilder builder ) {
110
- return builder .sdkChannelOptions ;
111
- }
112
-
113
110
@ Override
114
111
public CompletableFuture <Void > execute (AsyncExecuteRequest request ) {
115
112
RequestContext ctx = createRequestContext (request );
@@ -120,6 +117,10 @@ public static Builder builder() {
120
117
return new DefaultBuilder ();
121
118
}
122
119
120
+ private SdkChannelOptions channelOptions (DefaultBuilder builder ) {
121
+ return builder .sdkChannelOptions ;
122
+ }
123
+
123
124
private RequestContext createRequestContext (AsyncExecuteRequest request ) {
124
125
ChannelPool pool = pools .get (poolKey (request .request ()));
125
126
return new RequestContext (pool , request , configuration );
@@ -304,7 +305,7 @@ public interface Builder extends SdkAsyncHttpClient.Builder<NettyNioAsyncHttpCli
304
305
/**
305
306
* Sets the {@link SdkEventLoopGroup} to use for the Netty HTTP client. This event loop group may be shared
306
307
* across multiple HTTP clients for better resource and thread utilization. The preferred way to create
307
- * an {@link EventLoopGroup} is by using the {@link SdkEventLoopGroup#builder()})} method which will choose the
308
+ * an {@link EventLoopGroup} is by using the {@link SdkEventLoopGroup#builder()} method which will choose the
308
309
* optimal implementation per the platform.
309
310
*
310
311
* <p>The {@link EventLoopGroup} <b>MUST</b> be closed by the caller when it is ready to
@@ -348,12 +349,15 @@ public interface Builder extends SdkAsyncHttpClient.Builder<NettyNioAsyncHttpCli
348
349
Builder protocol (Protocol protocol );
349
350
350
351
/**
351
- * Add new socket channel option which will be used to create Netty Http client. This allows custom configuration
352
- * for Netty.
352
+ * Configures additional {@link ChannelOption} which will be used to create Netty Http client. This allows custom
353
+ * configuration for Netty.
354
+ *
355
+ * <p>
356
+ * If a {@link ChannelOption} was previously configured, the old value is replaced.
357
+ *
353
358
* @param channelOption {@link ChannelOption} to set
354
359
* @param value See {@link ChannelOption} to find the type of value for each option
355
360
* @return This builder for method chaining.
356
- * @see SdkEventLoopGroup.Builder
357
361
*/
358
362
Builder putChannelOption (ChannelOption channelOption , Object value );
359
363
@@ -387,12 +391,6 @@ private static final class DefaultBuilder implements Builder {
387
391
private DefaultBuilder () {
388
392
}
389
393
390
- /**
391
- * Max allowed connections per endpoint allowed in the connection pool.
392
- *
393
- * @param maxConcurrency New value for max connections per endpoint.
394
- * @return This builder for method chaining.
395
- */
396
394
@ Override
397
395
public Builder maxConcurrency (Integer maxConcurrency ) {
398
396
standardOptions .put (MAX_CONNECTIONS , maxConcurrency );
@@ -403,12 +401,6 @@ public void setMaxConcurrency(Integer maxConnectionsPerEndpoint) {
403
401
maxConcurrency (maxConnectionsPerEndpoint );
404
402
}
405
403
406
- /**
407
- * The maximum number of pending acquires allowed. Once this exceeds, acquire tries will be failed.
408
- *
409
- * @param maxPendingAcquires Max number of pending acquires
410
- * @return This builder for method chaining.
411
- */
412
404
@ Override
413
405
public Builder maxPendingConnectionAcquires (Integer maxPendingAcquires ) {
414
406
standardOptions .put (MAX_PENDING_CONNECTION_ACQUIRES , maxPendingAcquires );
@@ -419,12 +411,6 @@ public void setMaxPendingConnectionAcquires(Integer maxPendingAcquires) {
419
411
maxPendingConnectionAcquires (maxPendingAcquires );
420
412
}
421
413
422
- /**
423
- * The amount of time to wait for a read on a socket before an exception is thrown.
424
- *
425
- * @param readTimeout timeout duration
426
- * @return this builder for method chaining.
427
- */
428
414
@ Override
429
415
public Builder readTimeout (Duration readTimeout ) {
430
416
Validate .isPositive (readTimeout , "readTimeout" );
@@ -436,12 +422,6 @@ public void setReadTimeout(Duration readTimeout) {
436
422
readTimeout (readTimeout );
437
423
}
438
424
439
- /**
440
- * The amount of time to wait for a write on a socket before an exception is thrown.
441
- *
442
- * @param writeTimeout timeout duration
443
- * @return this builder for method chaining.
444
- */
445
425
@ Override
446
426
public Builder writeTimeout (Duration writeTimeout ) {
447
427
Validate .isPositive (writeTimeout , "writeTimeout" );
@@ -453,12 +433,6 @@ public void setWriteTimeout(Duration writeTimeout) {
453
433
writeTimeout (writeTimeout );
454
434
}
455
435
456
- /**
457
- * The amount of time to wait when initially establishing a connection before giving up and timing out.
458
- *
459
- * @param timeout the timeout duration
460
- * @return this builder for method chaining.
461
- */
462
436
@ Override
463
437
public Builder connectionTimeout (Duration timeout ) {
464
438
Validate .isPositive (timeout , "connectionTimeout" );
@@ -470,11 +444,6 @@ public void setConnectionTimeout(Duration connectionTimeout) {
470
444
connectionTimeout (connectionTimeout );
471
445
}
472
446
473
- /**
474
- * The amount of time to wait when acquiring a connection from the pool before giving up and timing out.
475
- * @param connectionAcquisitionTimeout the timeout duration
476
- * @return this builder for method chaining.
477
- */
478
447
@ Override
479
448
public Builder connectionAcquisitionTimeout (Duration connectionAcquisitionTimeout ) {
480
449
Validate .isPositive (connectionAcquisitionTimeout , "connectionAcquisitionTimeout" );
0 commit comments