4141import org .apache .hc .core5 .http .config .Http1Config ;
4242import org .apache .hc .core5 .http .impl .Http1StreamListener ;
4343import org .apache .hc .core5 .http .impl .HttpProcessors ;
44+ import org .apache .hc .core5 .http .impl .bootstrap .AsyncRequesterBootstrap ;
4445import org .apache .hc .core5 .http .impl .bootstrap .HttpAsyncRequester ;
45- import org .apache .hc .core5 .http .impl .nio .ClientHttp1IOEventHandlerFactory ;
46- import org .apache .hc .core5 .http .impl .nio .ClientHttp1StreamDuplexerFactory ;
4746import org .apache .hc .core5 .http .nio .ssl .BasicClientTlsStrategy ;
4847import org .apache .hc .core5 .http .nio .ssl .TlsStrategy ;
4948import org .apache .hc .core5 .http .protocol .HttpProcessor ;
5049import org .apache .hc .core5 .http2 .config .H2Config ;
50+ import org .apache .hc .core5 .http2 .impl .H2Processors ;
5151import org .apache .hc .core5 .http2 .impl .nio .bootstrap .H2MultiplexingRequester ;
5252import org .apache .hc .core5 .http2 .impl .nio .bootstrap .H2MultiplexingRequesterBootstrap ;
53- import org .apache .hc .core5 .http2 .impl .H2Processors ;
5453import org .apache .hc .core5 .pool .ConnPoolListener ;
5554import org .apache .hc .core5 .pool .DefaultDisposalCallback ;
5655import org .apache .hc .core5 .pool .LaxConnPool ;
5756import org .apache .hc .core5 .pool .ManagedConnPool ;
5857import org .apache .hc .core5 .pool .PoolConcurrencyPolicy ;
5958import org .apache .hc .core5 .pool .PoolReusePolicy ;
6059import org .apache .hc .core5 .pool .StrictConnPool ;
61- import org .apache .hc .core5 .reactor .IOEventHandlerFactory ;
6260import org .apache .hc .core5 .reactor .IOReactorConfig ;
6361import org .apache .hc .core5 .reactor .IOReactorMetricsListener ;
6462import org .apache .hc .core5 .reactor .IOSession ;
6563import org .apache .hc .core5 .reactor .IOSessionListener ;
66- import org .apache .hc .core5 .reactor .IOWorkerSelector ;
6764import org .apache .hc .core5 .util .Timeout ;
6865
6966/**
@@ -107,7 +104,7 @@ public final class WebSocketClientBuilder {
107104
108105 // Optional listeners for reactor metrics and worker selection.
109106 private IOReactorMetricsListener reactorMetricsListener ;
110- private IOWorkerSelector workerSelector ;
107+ @ SuppressWarnings ( "unused" )
111108 private int maxPendingCommandsPerConnection ;
112109
113110 private WebSocketClientConfig defaultConfig = WebSocketClientConfig .custom ().build ();
@@ -264,7 +261,7 @@ public WebSocketClientBuilder setPoolConcurrencyPolicy(final PoolConcurrencyPoli
264261 * Sets the maximum number of pending commands per connection.
265262 *
266263 * @param maxPendingCommandsPerConnection maximum pending commands; values < 0
267- * cause the default of {@code 0} to be used.
264+ * cause the default of {@code 0} to be used.
268265 * @return this builder.
269266 */
270267 public WebSocketClientBuilder setMaxPendingCommandsPerConnection (final int maxPendingCommandsPerConnection ) {
@@ -378,18 +375,6 @@ public WebSocketClientBuilder setReactorMetricsListener(
378375 return this ;
379376 }
380377
381- /**
382- * Sets a worker selector for assigning I/O sessions to worker threads.
383- *
384- * @param workerSelector worker selector, or {@code null} for the default
385- * strategy.
386- * @return this builder.
387- */
388- public WebSocketClientBuilder setWorkerSelector (final IOWorkerSelector workerSelector ) {
389- this .workerSelector = workerSelector ;
390- return this ;
391- }
392-
393378 /**
394379 * Builds a new {@link CloseableWebSocketClient} instance using the
395380 * current builder configuration.
@@ -401,12 +386,8 @@ public WebSocketClientBuilder setWorkerSelector(final IOWorkerSelector workerSel
401386 */
402387 public CloseableWebSocketClient build () {
403388
404- final PoolConcurrencyPolicy conc = poolConcurrencyPolicy != null
405- ? poolConcurrencyPolicy
406- : PoolConcurrencyPolicy .STRICT ;
407- final PoolReusePolicy reuse = poolReusePolicy != null
408- ? poolReusePolicy
409- : PoolReusePolicy .LIFO ;
389+ final PoolConcurrencyPolicy conc = poolConcurrencyPolicy != null ? poolConcurrencyPolicy : PoolConcurrencyPolicy .STRICT ;
390+ final PoolReusePolicy reuse = poolReusePolicy != null ? poolReusePolicy : PoolReusePolicy .LIFO ;
410391 final Timeout ttl = timeToLive != null ? timeToLive : Timeout .DISABLED ;
411392
412393 final ManagedConnPool <HttpHost , IOSession > connPool ;
@@ -424,35 +405,34 @@ public CloseableWebSocketClient build() {
424405 final HttpProcessor proc = httpProcessor != null ? httpProcessor : HttpProcessors .client ();
425406 final Http1Config h1 = http1Config != null ? http1Config : Http1Config .DEFAULT ;
426407 final CharCodingConfig coding = charCodingConfig != null ? charCodingConfig : CharCodingConfig .DEFAULT ;
427-
428- final ConnectionReuseStrategy reuseStrategyCopy = connStrategy != null
429- ? connStrategy
430- : new DefaultClientConnectionReuseStrategy ();
431-
432- final ClientHttp1StreamDuplexerFactory duplexerFactory =
433- new ClientHttp1StreamDuplexerFactory (
434- proc , h1 , coding , reuseStrategyCopy , null , null , streamListener );
408+ final ConnectionReuseStrategy reuseStrategyCopy = connStrategy != null ? connStrategy : new DefaultClientConnectionReuseStrategy ();
435409
436410 final TlsStrategy tls = tlsStrategy != null ? tlsStrategy : new BasicClientTlsStrategy ();
437- final IOEventHandlerFactory iohFactory =
438- new ClientHttp1IOEventHandlerFactory (duplexerFactory , tls , handshakeTimeout );
439411
440412 final IOReactorMetricsListener metricsListener = reactorMetricsListener != null ? reactorMetricsListener : null ;
441- final IOWorkerSelector selector = workerSelector != null ? workerSelector : null ;
442-
443- final HttpAsyncRequester requester = new HttpAsyncRequester (
444- ioReactorConfig != null ? ioReactorConfig : IOReactorConfig .DEFAULT ,
445- iohFactory ,
446- ioSessionDecorator ,
447- exceptionCallback != null ? exceptionCallback : WsLoggingExceptionCallback .INSTANCE ,
448- sessionListener ,
449- connPool ,
450- tls ,
451- handshakeTimeout ,
452- metricsListener ,
453- selector ,
454- Math .max (maxPendingCommandsPerConnection , 0 )
455- );
413+
414+ final HttpAsyncRequester requester = AsyncRequesterBootstrap .bootstrap ()
415+ .setIOReactorConfig (ioReactorConfig != null ? ioReactorConfig : IOReactorConfig .DEFAULT )
416+ .setHttpProcessor (proc )
417+ .setHttp1Config (h1 )
418+ .setCharCodingConfig (coding )
419+ .setConnectionReuseStrategy (reuseStrategyCopy )
420+ .setPoolConcurrencyPolicy (conc )
421+ .setPoolReusePolicy (reuse )
422+ .setDefaultMaxPerRoute (defaultMaxPerRoute > 0 ? defaultMaxPerRoute : 20 )
423+ .setMaxTotal (maxTotal > 0 ? maxTotal : 50 )
424+ .setTimeToLive (ttl )
425+ .setTlsStrategy (tls )
426+ .setTlsHandshakeTimeout (handshakeTimeout )
427+ .setIOSessionDecorator (ioSessionDecorator )
428+ .setExceptionCallback (exceptionCallback != null ? exceptionCallback : WsLoggingExceptionCallback .INSTANCE )
429+ .setIOSessionListener (sessionListener )
430+ .setIOReactorMetricsListener (metricsListener )
431+ .setStreamListener (streamListener )
432+ .setConnPoolListener (connPoolListener )
433+ // version 5.5 of the core
434+ // .setMaxPendingCommandsPerConnection(Math.max(maxPendingCommandsPerConnection, 0))
435+ .create ();
456436
457437 final H2MultiplexingRequester h2Requester = H2MultiplexingRequesterBootstrap .bootstrap ()
458438 .setIOReactorConfig (ioReactorConfig != null ? ioReactorConfig : IOReactorConfig .DEFAULT )
0 commit comments