Skip to content

Commit f664574

Browse files
committed
minimal change. Update pom.xml
1 parent 41132f7 commit f664574

File tree

10 files changed

+96
-113
lines changed

10 files changed

+96
-113
lines changed

httpclient5-websocket/src/main/java/org/apache/hc/client5/http/websocket/client/WebSocketClientBuilder.java

Lines changed: 30 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -41,29 +41,26 @@
4141
import org.apache.hc.core5.http.config.Http1Config;
4242
import org.apache.hc.core5.http.impl.Http1StreamListener;
4343
import org.apache.hc.core5.http.impl.HttpProcessors;
44+
import org.apache.hc.core5.http.impl.bootstrap.AsyncRequesterBootstrap;
4445
import 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;
4746
import org.apache.hc.core5.http.nio.ssl.BasicClientTlsStrategy;
4847
import org.apache.hc.core5.http.nio.ssl.TlsStrategy;
4948
import org.apache.hc.core5.http.protocol.HttpProcessor;
5049
import org.apache.hc.core5.http2.config.H2Config;
50+
import org.apache.hc.core5.http2.impl.H2Processors;
5151
import org.apache.hc.core5.http2.impl.nio.bootstrap.H2MultiplexingRequester;
5252
import org.apache.hc.core5.http2.impl.nio.bootstrap.H2MultiplexingRequesterBootstrap;
53-
import org.apache.hc.core5.http2.impl.H2Processors;
5453
import org.apache.hc.core5.pool.ConnPoolListener;
5554
import org.apache.hc.core5.pool.DefaultDisposalCallback;
5655
import org.apache.hc.core5.pool.LaxConnPool;
5756
import org.apache.hc.core5.pool.ManagedConnPool;
5857
import org.apache.hc.core5.pool.PoolConcurrencyPolicy;
5958
import org.apache.hc.core5.pool.PoolReusePolicy;
6059
import org.apache.hc.core5.pool.StrictConnPool;
61-
import org.apache.hc.core5.reactor.IOEventHandlerFactory;
6260
import org.apache.hc.core5.reactor.IOReactorConfig;
6361
import org.apache.hc.core5.reactor.IOReactorMetricsListener;
6462
import org.apache.hc.core5.reactor.IOSession;
6563
import org.apache.hc.core5.reactor.IOSessionListener;
66-
import org.apache.hc.core5.reactor.IOWorkerSelector;
6764
import 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)

httpclient5-websocket/src/main/java/org/apache/hc/client5/http/websocket/client/impl/InternalWebSocketClientBase.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
package org.apache.hc.client5.http.websocket.client.impl;
2828

2929
import java.net.URI;
30+
import java.nio.ByteBuffer;
31+
import java.nio.CharBuffer;
3032
import java.util.concurrent.CancellationException;
3133
import java.util.concurrent.CompletableFuture;
3234
import java.util.concurrent.CompletionException;
@@ -115,22 +117,22 @@ public void onOpen(final WebSocket webSocket) {
115117
}
116118

117119
@Override
118-
public void onText(final java.nio.CharBuffer data, final boolean last) {
120+
public void onText(final CharBuffer data, final boolean last) {
119121
listener.onText(data, last);
120122
}
121123

122124
@Override
123-
public void onBinary(final java.nio.ByteBuffer data, final boolean last) {
125+
public void onBinary(final ByteBuffer data, final boolean last) {
124126
listener.onBinary(data, last);
125127
}
126128

127129
@Override
128-
public void onPing(final java.nio.ByteBuffer data) {
130+
public void onPing(final ByteBuffer data) {
129131
listener.onPing(data);
130132
}
131133

132134
@Override
133-
public void onPong(final java.nio.ByteBuffer data) {
135+
public void onPong(final ByteBuffer data) {
134136
listener.onPong(data);
135137
}
136138

httpclient5-websocket/src/test/java/org/apache/hc/client5/http/websocket/client/WebSocketClientBuilderTest.java

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,12 @@
2626
*/
2727
package org.apache.hc.client5.http.websocket.client;
2828

29+
import java.nio.charset.StandardCharsets;
30+
2931
import org.apache.hc.client5.http.impl.DefaultClientConnectionReuseStrategy;
3032
import org.apache.hc.client5.http.websocket.api.WebSocketClientConfig;
3133
import org.apache.hc.core5.http.HttpConnection;
34+
import org.apache.hc.core5.http.HttpHost;
3235
import org.apache.hc.core5.http.HttpRequest;
3336
import org.apache.hc.core5.http.HttpResponse;
3437
import org.apache.hc.core5.http.config.CharCodingConfig;
@@ -45,7 +48,6 @@
4548
import org.apache.hc.core5.reactor.IOReactorMetricsListener;
4649
import org.apache.hc.core5.reactor.IOSession;
4750
import org.apache.hc.core5.reactor.IOSessionListener;
48-
import org.apache.hc.core5.reactor.IOWorkerSelector;
4951
import org.apache.hc.core5.util.Timeout;
5052
import org.junit.jupiter.api.Assertions;
5153
import org.junit.jupiter.api.Test;
@@ -58,7 +60,7 @@ void buildWithCustomSettingsUsesLaxPool() throws Exception {
5860
.defaultConfig(WebSocketClientConfig.custom().enableHttp2(true).build())
5961
.setIOReactorConfig(IOReactorConfig.custom().setIoThreadCount(1).build())
6062
.setHttp1Config(Http1Config.custom().setMaxHeaderCount(64).build())
61-
.setCharCodingConfig(CharCodingConfig.custom().setCharset(java.nio.charset.StandardCharsets.UTF_8).build())
63+
.setCharCodingConfig(CharCodingConfig.custom().setCharset(StandardCharsets.UTF_8).build())
6264
.setHttpProcessor(HttpProcessors.client())
6365
.setConnectionReuseStrategy(new DefaultClientConnectionReuseStrategy())
6466
.setDefaultMaxPerRoute(2)
@@ -69,13 +71,13 @@ void buildWithCustomSettingsUsesLaxPool() throws Exception {
6971
.setTlsStrategy(new BasicClientTlsStrategy())
7072
.setTlsHandshakeTimeout(Timeout.ofSeconds(3))
7173
.setIOSessionDecorator(ioSession -> ioSession)
72-
.setExceptionCallback(exception -> { })
74+
.setExceptionCallback(exception -> {
75+
})
7376
.setIOSessionListener(new NoopSessionListener())
7477
.setStreamListener(new NoopStreamListener())
7578
.setConnPoolListener(new NoopConnPoolListener())
7679
.setThreadFactory(r -> new Thread(r, "ws-test"))
7780
.setReactorMetricsListener(new NoopMetricsListener())
78-
.setWorkerSelector(new NoopWorkerSelector())
7981
.setMaxPendingCommandsPerConnection(5)
8082
.build();
8183

@@ -134,15 +136,15 @@ public void onExchangeComplete(final HttpConnection connection, final boolean ke
134136
}
135137
}
136138

137-
private static final class NoopConnPoolListener implements ConnPoolListener<org.apache.hc.core5.http.HttpHost> {
139+
private static final class NoopConnPoolListener implements ConnPoolListener<HttpHost> {
138140
@Override
139-
public void onLease(final org.apache.hc.core5.http.HttpHost route,
140-
final ConnPoolStats<org.apache.hc.core5.http.HttpHost> connPoolStats) {
141+
public void onLease(final HttpHost route,
142+
final ConnPoolStats<HttpHost> connPoolStats) {
141143
}
142144

143145
@Override
144-
public void onRelease(final org.apache.hc.core5.http.HttpHost route,
145-
final ConnPoolStats<org.apache.hc.core5.http.HttpHost> connPoolStats) {
146+
public void onRelease(final HttpHost route,
147+
final ConnPoolStats<HttpHost> connPoolStats) {
146148
}
147149
}
148150

@@ -163,11 +165,4 @@ public void onResourceStarvationDetected() {
163165
public void onQueueWaitTime(final long averageWaitTimeMillis) {
164166
}
165167
}
166-
167-
private static final class NoopWorkerSelector implements IOWorkerSelector {
168-
@Override
169-
public int select(final org.apache.hc.core5.reactor.IOWorkerStats[] dispatchers) {
170-
return 0;
171-
}
172-
}
173168
}

httpclient5-websocket/src/test/java/org/apache/hc/client5/http/websocket/client/impl/WebSocketClientImplTest.java

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@
2929
import java.net.URI;
3030
import java.nio.ByteBuffer;
3131
import java.util.Collections;
32+
import java.util.List;
3233
import java.util.Set;
3334
import java.util.concurrent.CompletableFuture;
3435
import java.util.concurrent.CountDownLatch;
36+
import java.util.concurrent.Future;
3537
import java.util.concurrent.TimeUnit;
3638
import java.util.function.Supplier;
3739

@@ -44,16 +46,15 @@
4446
import org.apache.hc.core5.http.impl.DefaultAddressResolver;
4547
import org.apache.hc.core5.http.impl.bootstrap.HttpAsyncRequester;
4648
import org.apache.hc.core5.http.protocol.HttpContext;
49+
import org.apache.hc.core5.http2.impl.nio.bootstrap.H2MultiplexingRequester;
4750
import org.apache.hc.core5.io.CloseMode;
4851
import org.apache.hc.core5.pool.ManagedConnPool;
4952
import org.apache.hc.core5.pool.PoolEntry;
5053
import org.apache.hc.core5.pool.PoolStats;
51-
import org.apache.hc.core5.reactor.IOEventHandlerFactory;
5254
import org.apache.hc.core5.reactor.IOReactorConfig;
5355
import org.apache.hc.core5.reactor.IOSession;
5456
import org.apache.hc.core5.util.TimeValue;
5557
import org.apache.hc.core5.util.Timeout;
56-
import org.apache.hc.core5.http2.impl.nio.bootstrap.H2MultiplexingRequester;
5758
import org.junit.jupiter.api.Assertions;
5859
import org.junit.jupiter.api.Test;
5960

@@ -103,7 +104,8 @@ void internalClientFallsBackToH1OnH2Failure() throws Exception {
103104
boolean closed = false;
104105
try {
105106
final WebSocketClientConfig cfg = WebSocketClientConfig.custom().enableHttp2(true).build();
106-
final WebSocket ws = client.connect(URI.create("ws://localhost"), new WebSocketListener() { }, cfg, null)
107+
final WebSocket ws = client.connect(URI.create("ws://localhost"), new WebSocketListener() {
108+
}, cfg, null)
107109
.get(1, TimeUnit.SECONDS);
108110

109111
Assertions.assertNotNull(ws);
@@ -130,7 +132,8 @@ void internalClientUsesH2WhenAvailable() throws Exception {
130132
boolean closed = false;
131133
try {
132134
final WebSocketClientConfig cfg = WebSocketClientConfig.custom().enableHttp2(true).build();
133-
final WebSocket ws = client.connect(URI.create("ws://localhost"), new WebSocketListener() { }, cfg, null)
135+
final WebSocket ws = client.connect(URI.create("ws://localhost"), new WebSocketListener() {
136+
}, cfg, null)
134137
.get(1, TimeUnit.SECONDS);
135138

136139
Assertions.assertNotNull(ws);
@@ -157,7 +160,8 @@ void internalClientUsesH1WhenH2Disabled() throws Exception {
157160
boolean closed = false;
158161
try {
159162
final WebSocketClientConfig cfg = WebSocketClientConfig.custom().enableHttp2(false).build();
160-
final WebSocket ws = client.connect(URI.create("ws://localhost"), new WebSocketListener() { }, cfg, null)
163+
final WebSocket ws = client.connect(URI.create("ws://localhost"), new WebSocketListener() {
164+
}, cfg, null)
161165
.get(1, TimeUnit.SECONDS);
162166

163167
Assertions.assertNotNull(ws);
@@ -205,7 +209,7 @@ protected WebSocketProtocolStrategy newH1Protocol(
205209
}
206210

207211
@Override
208-
protected WebSocketProtocolStrategy newH2Protocol(final org.apache.hc.core5.http2.impl.nio.bootstrap.H2MultiplexingRequester requester) {
212+
protected WebSocketProtocolStrategy newH2Protocol(final H2MultiplexingRequester requester) {
209213
return new DelegatingProtocol(() -> h2);
210214
}
211215
}
@@ -239,7 +243,7 @@ private static final class StubProtocol implements WebSocketProtocolStrategy {
239243

240244
@Override
241245
public CompletableFuture<WebSocket> connect(final URI uri, final WebSocketListener listener,
242-
final WebSocketClientConfig cfg, final HttpContext context) {
246+
final WebSocketClientConfig cfg, final HttpContext context) {
243247
calls++;
244248
if (failWith != null) {
245249
final CompletableFuture<WebSocket> f = new CompletableFuture<>();
@@ -277,12 +281,12 @@ public boolean sendBinary(final ByteBuffer data, final boolean finalFragment) {
277281
}
278282

279283
@Override
280-
public boolean sendTextBatch(final java.util.List<CharSequence> fragments, final boolean finalFragment) {
284+
public boolean sendTextBatch(final List<CharSequence> fragments, final boolean finalFragment) {
281285
return true;
282286
}
283287

284288
@Override
285-
public boolean sendBinaryBatch(final java.util.List<ByteBuffer> fragments, final boolean finalFragment) {
289+
public boolean sendBinaryBatch(final List<ByteBuffer> fragments, final boolean finalFragment) {
286290
return true;
287291
}
288292

@@ -302,8 +306,10 @@ private static final class NoopH2Requester extends H2MultiplexingRequester {
302306
DefaultAddressResolver.INSTANCE,
303307
null,
304308
null,
305-
null,
306-
0);
309+
null
310+
// ,
311+
// 0
312+
);
307313
}
308314

309315
@Override
@@ -330,16 +336,16 @@ private static final class TestRequester extends HttpAsyncRequester {
330336

331337
TestRequester(final ManagedConnPool<HttpHost, IOSession> pool) {
332338
super(IOReactorConfig.DEFAULT,
333-
(IOEventHandlerFactory) (ioSession, attachment) -> null,
334-
(org.apache.hc.core5.function.Decorator<IOSession>) null,
335-
(org.apache.hc.core5.function.Callback<Exception>) null,
336-
(org.apache.hc.core5.reactor.IOSessionListener) null,
339+
(ioSession, attachment) -> null,
340+
null,
341+
null,
342+
null,
337343
pool,
338-
(org.apache.hc.core5.http.nio.ssl.TlsStrategy) null,
339-
(Timeout) null,
340-
(org.apache.hc.core5.reactor.IOReactorMetricsListener) null,
341-
(org.apache.hc.core5.reactor.IOWorkerSelector) null,
342-
0);
344+
null,
345+
null,
346+
null,
347+
null
348+
);
343349
}
344350

345351
@Override
@@ -364,7 +370,7 @@ public void close(final CloseMode closeMode) {
364370

365371
private static final class StubConnPool implements ManagedConnPool<HttpHost, IOSession> {
366372
@Override
367-
public java.util.concurrent.Future<PoolEntry<HttpHost, IOSession>> lease(
373+
public Future<PoolEntry<HttpHost, IOSession>> lease(
368374
final HttpHost route, final Object state, final Timeout requestTimeout,
369375
final FutureCallback<PoolEntry<HttpHost, IOSession>> callback) {
370376
return CompletableFuture.completedFuture(null);

0 commit comments

Comments
 (0)