New upstream version 2.5.0
Emmanuel Bourg
5 years ago
262 | 262 | or |
263 | 263 | |
264 | 264 | ```java |
265 | Request propFindRequest = new RequestBuilder("PROPFIND").setUrl("http://host:port).build(); | |
266 | Response response = c.executeRequest(propFindRequest, new AsyncHandler(){...}).get(); | |
265 | Request propFindRequest = new RequestBuilder("PROPFIND").setUrl("http://host:port").build(); | |
266 | Response response = c.executeRequest(propFindRequest, new AsyncHandler() { | |
267 | // ... | |
268 | }).get(); | |
267 | 269 | ``` |
268 | 270 | |
269 | 271 | ## More |
1 | 1 | <parent> |
2 | 2 | <groupId>org.asynchttpclient</groupId> |
3 | 3 | <artifactId>async-http-client-project</artifactId> |
4 | <version>2.4.9</version> | |
4 | <version>2.5.0</version> | |
5 | 5 | </parent> |
6 | 6 | <modelVersion>4.0.0</modelVersion> |
7 | 7 | <artifactId>async-http-client</artifactId> |
27 | 27 | import org.asynchttpclient.filter.ResponseFilter; |
28 | 28 | import org.asynchttpclient.netty.EagerResponseBodyPart; |
29 | 29 | import org.asynchttpclient.netty.LazyResponseBodyPart; |
30 | import org.asynchttpclient.netty.channel.ConnectionSemaphoreFactory; | |
30 | 31 | import org.asynchttpclient.proxy.ProxyServer; |
31 | 32 | import org.asynchttpclient.proxy.ProxyServerSelector; |
32 | 33 | |
291 | 292 | ResponseBodyPartFactory getResponseBodyPartFactory(); |
292 | 293 | |
293 | 294 | ChannelPool getChannelPool(); |
295 | ||
296 | ConnectionSemaphoreFactory getConnectionSemaphoreFactory(); | |
294 | 297 | |
295 | 298 | Timer getNettyTimer(); |
296 | 299 |
29 | 29 | import org.asynchttpclient.filter.IOExceptionFilter; |
30 | 30 | import org.asynchttpclient.filter.RequestFilter; |
31 | 31 | import org.asynchttpclient.filter.ResponseFilter; |
32 | import org.asynchttpclient.netty.channel.ConnectionSemaphoreFactory; | |
32 | 33 | import org.asynchttpclient.proxy.ProxyServer; |
33 | 34 | import org.asynchttpclient.proxy.ProxyServerSelector; |
34 | 35 | import org.asynchttpclient.util.ProxyUtils; |
83 | 84 | private final int maxConnections; |
84 | 85 | private final int maxConnectionsPerHost; |
85 | 86 | private final ChannelPool channelPool; |
87 | private final ConnectionSemaphoreFactory connectionSemaphoreFactory; | |
86 | 88 | private final KeepAliveStrategy keepAliveStrategy; |
87 | 89 | |
88 | 90 | // ssl |
161 | 163 | int maxConnections, |
162 | 164 | int maxConnectionsPerHost, |
163 | 165 | ChannelPool channelPool, |
166 | ConnectionSemaphoreFactory connectionSemaphoreFactory, | |
164 | 167 | KeepAliveStrategy keepAliveStrategy, |
165 | 168 | |
166 | 169 | // ssl |
247 | 250 | this.maxConnections = maxConnections; |
248 | 251 | this.maxConnectionsPerHost = maxConnectionsPerHost; |
249 | 252 | this.channelPool = channelPool; |
253 | this.connectionSemaphoreFactory = connectionSemaphoreFactory; | |
250 | 254 | this.keepAliveStrategy = keepAliveStrategy; |
251 | 255 | |
252 | 256 | // ssl |
443 | 447 | @Override |
444 | 448 | public ChannelPool getChannelPool() { |
445 | 449 | return channelPool; |
450 | } | |
451 | ||
452 | @Override | |
453 | public ConnectionSemaphoreFactory getConnectionSemaphoreFactory() { | |
454 | return connectionSemaphoreFactory; | |
446 | 455 | } |
447 | 456 | |
448 | 457 | @Override |
687 | 696 | private int maxConnections = defaultMaxConnections(); |
688 | 697 | private int maxConnectionsPerHost = defaultMaxConnectionsPerHost(); |
689 | 698 | private ChannelPool channelPool; |
699 | private ConnectionSemaphoreFactory connectionSemaphoreFactory; | |
690 | 700 | private KeepAliveStrategy keepAliveStrategy = new DefaultKeepAliveStrategy(); |
691 | 701 | |
692 | 702 | // ssl |
767 | 777 | maxConnections = config.getMaxConnections(); |
768 | 778 | maxConnectionsPerHost = config.getMaxConnectionsPerHost(); |
769 | 779 | channelPool = config.getChannelPool(); |
780 | connectionSemaphoreFactory = config.getConnectionSemaphoreFactory(); | |
770 | 781 | keepAliveStrategy = config.getKeepAliveStrategy(); |
771 | 782 | |
772 | 783 | // ssl |
980 | 991 | |
981 | 992 | public Builder setChannelPool(ChannelPool channelPool) { |
982 | 993 | this.channelPool = channelPool; |
994 | return this; | |
995 | } | |
996 | ||
997 | public Builder setConnectionSemaphoreFactory(ConnectionSemaphoreFactory connectionSemaphoreFactory) { | |
998 | this.connectionSemaphoreFactory = connectionSemaphoreFactory; | |
983 | 999 | return this; |
984 | 1000 | } |
985 | 1001 | |
1232 | 1248 | maxConnections, |
1233 | 1249 | maxConnectionsPerHost, |
1234 | 1250 | channelPool, |
1251 | connectionSemaphoreFactory, | |
1235 | 1252 | keepAliveStrategy, |
1236 | 1253 | useOpenSsl, |
1237 | 1254 | useInsecureTrustManager, |
333 | 333 | return sslHandler; |
334 | 334 | } |
335 | 335 | |
336 | public void updatePipelineForHttpTunneling(ChannelPipeline pipeline, Uri requestUri) { | |
336 | public Future<Channel> updatePipelineForHttpTunneling(ChannelPipeline pipeline, Uri requestUri) { | |
337 | ||
338 | Future<Channel> whenHanshaked = null; | |
339 | ||
337 | 340 | if (pipeline.get(HTTP_CLIENT_CODEC) != null) |
338 | 341 | pipeline.remove(HTTP_CLIENT_CODEC); |
339 | 342 | |
340 | 343 | if (requestUri.isSecured()) { |
341 | 344 | if (!isSslHandlerConfigured(pipeline)) { |
342 | pipeline.addBefore(AHC_HTTP_HANDLER, SSL_HANDLER, createSslHandler(requestUri.getHost(), requestUri.getExplicitPort())); | |
345 | SslHandler sslHandler = createSslHandler(requestUri.getHost(), requestUri.getExplicitPort()); | |
346 | whenHanshaked = sslHandler.handshakeFuture(); | |
347 | pipeline.addBefore(AHC_HTTP_HANDLER, SSL_HANDLER, sslHandler); | |
343 | 348 | } |
344 | 349 | pipeline.addAfter(SSL_HANDLER, HTTP_CLIENT_CODEC, newHttpClientCodec()); |
345 | 350 | |
351 | 356 | pipeline.addAfter(AHC_HTTP_HANDLER, AHC_WS_HANDLER, wsHandler); |
352 | 357 | pipeline.remove(AHC_HTTP_HANDLER); |
353 | 358 | } |
359 | return whenHanshaked; | |
354 | 360 | } |
355 | 361 | |
356 | 362 | public SslHandler addSslHandler(ChannelPipeline pipeline, Uri uri, String virtualHost, boolean hasSocksProxyHandler) { |
0 | 0 | /* |
1 | * Copyright (c) 2017 AsyncHttpClient Project. All rights reserved. | |
1 | * Copyright (c) 2018 AsyncHttpClient Project. All rights reserved. | |
2 | 2 | * |
3 | 3 | * This program is licensed to you under the Apache License Version 2.0, |
4 | 4 | * and you may not use this file except in compliance with the Apache License Version 2.0. |
12 | 12 | */ |
13 | 13 | package org.asynchttpclient.netty.channel; |
14 | 14 | |
15 | import org.asynchttpclient.AsyncHttpClientConfig; | |
16 | import org.asynchttpclient.exception.TooManyConnectionsException; | |
17 | import org.asynchttpclient.exception.TooManyConnectionsPerHostException; | |
18 | ||
19 | 15 | import java.io.IOException; |
20 | import java.util.concurrent.ConcurrentHashMap; | |
21 | ||
22 | import static org.asynchttpclient.util.ThrowableUtil.unknownStackTrace; | |
23 | 16 | |
24 | 17 | /** |
25 | * Max connections and max-per-host connections limiter. | |
26 | * | |
27 | * @author Stepan Koltsov | |
18 | * Connections limiter. | |
28 | 19 | */ |
29 | public class ConnectionSemaphore { | |
20 | public interface ConnectionSemaphore { | |
30 | 21 | |
31 | private final NonBlockingSemaphoreLike freeChannels; | |
32 | private final int maxConnectionsPerHost; | |
33 | private final ConcurrentHashMap<Object, NonBlockingSemaphore> freeChannelsPerHost = new ConcurrentHashMap<>(); | |
34 | private final IOException tooManyConnections; | |
35 | private final IOException tooManyConnectionsPerHost; | |
22 | void acquireChannelLock(Object partitionKey) throws IOException; | |
36 | 23 | |
37 | private ConnectionSemaphore(AsyncHttpClientConfig config) { | |
38 | tooManyConnections = unknownStackTrace(new TooManyConnectionsException(config.getMaxConnections()), ConnectionSemaphore.class, "acquireChannelLock"); | |
39 | tooManyConnectionsPerHost = unknownStackTrace(new TooManyConnectionsPerHostException(config.getMaxConnectionsPerHost()), ConnectionSemaphore.class, "acquireChannelLock"); | |
40 | int maxTotalConnections = config.getMaxConnections(); | |
41 | maxConnectionsPerHost = config.getMaxConnectionsPerHost(); | |
24 | void releaseChannelLock(Object partitionKey); | |
42 | 25 | |
43 | freeChannels = maxTotalConnections > 0 ? | |
44 | new NonBlockingSemaphore(config.getMaxConnections()) : | |
45 | NonBlockingSemaphoreInfinite.INSTANCE; | |
46 | } | |
47 | ||
48 | public static ConnectionSemaphore newConnectionSemaphore(AsyncHttpClientConfig config) { | |
49 | return config.getMaxConnections() > 0 || config.getMaxConnectionsPerHost() > 0 ? new ConnectionSemaphore(config) : null; | |
50 | } | |
51 | ||
52 | private boolean tryAcquireGlobal() { | |
53 | return freeChannels.tryAcquire(); | |
54 | } | |
55 | ||
56 | private NonBlockingSemaphoreLike getFreeConnectionsForHost(Object partitionKey) { | |
57 | return maxConnectionsPerHost > 0 ? | |
58 | freeChannelsPerHost.computeIfAbsent(partitionKey, pk -> new NonBlockingSemaphore(maxConnectionsPerHost)) : | |
59 | NonBlockingSemaphoreInfinite.INSTANCE; | |
60 | } | |
61 | ||
62 | private boolean tryAcquirePerHost(Object partitionKey) { | |
63 | return getFreeConnectionsForHost(partitionKey).tryAcquire(); | |
64 | } | |
65 | ||
66 | public void acquireChannelLock(Object partitionKey) throws IOException { | |
67 | if (!tryAcquireGlobal()) | |
68 | throw tooManyConnections; | |
69 | if (!tryAcquirePerHost(partitionKey)) { | |
70 | freeChannels.release(); | |
71 | ||
72 | throw tooManyConnectionsPerHost; | |
73 | } | |
74 | } | |
75 | ||
76 | public void releaseChannelLock(Object partitionKey) { | |
77 | freeChannels.release(); | |
78 | getFreeConnectionsForHost(partitionKey).release(); | |
79 | } | |
80 | 26 | } |
+22
-0
0 | /* | |
1 | * Copyright (c) 2018 AsyncHttpClient Project. All rights reserved. | |
2 | * | |
3 | * This program is licensed to you under the Apache License Version 2.0, | |
4 | * and you may not use this file except in compliance with the Apache License Version 2.0. | |
5 | * You may obtain a copy of the Apache License Version 2.0 at | |
6 | * http://www.apache.org/licenses/LICENSE-2.0. | |
7 | * | |
8 | * Unless required by applicable law or agreed to in writing, | |
9 | * software distributed under the Apache License Version 2.0 is distributed on an | |
10 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
11 | * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. | |
12 | */ | |
13 | package org.asynchttpclient.netty.channel; | |
14 | ||
15 | import org.asynchttpclient.AsyncHttpClientConfig; | |
16 | ||
17 | public interface ConnectionSemaphoreFactory { | |
18 | ||
19 | ConnectionSemaphore newConnectionSemaphore(AsyncHttpClientConfig config); | |
20 | ||
21 | } |
+30
-0
0 | /* | |
1 | * Copyright (c) 2018 AsyncHttpClient Project. All rights reserved. | |
2 | * | |
3 | * This program is licensed to you under the Apache License Version 2.0, | |
4 | * and you may not use this file except in compliance with the Apache License Version 2.0. | |
5 | * You may obtain a copy of the Apache License Version 2.0 at | |
6 | * http://www.apache.org/licenses/LICENSE-2.0. | |
7 | * | |
8 | * Unless required by applicable law or agreed to in writing, | |
9 | * software distributed under the Apache License Version 2.0 is distributed on an | |
10 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
11 | * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. | |
12 | */ | |
13 | package org.asynchttpclient.netty.channel; | |
14 | ||
15 | import org.asynchttpclient.AsyncHttpClientConfig; | |
16 | ||
17 | public class DefaultConnectionSemaphoreFactory implements ConnectionSemaphoreFactory { | |
18 | ||
19 | public ConnectionSemaphore newConnectionSemaphore(AsyncHttpClientConfig config) { | |
20 | ConnectionSemaphore semaphore = new NoopConnectionSemaphore(); | |
21 | if (config.getMaxConnections() > 0) { | |
22 | semaphore = new MaxConnectionSemaphore(config.getMaxConnections()); | |
23 | } | |
24 | if (config.getMaxConnectionsPerHost() > 0) { | |
25 | semaphore = new PerHostConnectionSemaphore(config.getMaxConnectionsPerHost(), semaphore); | |
26 | } | |
27 | return semaphore; | |
28 | } | |
29 | } |
0 | /* | |
1 | * Copyright (c) 2018 AsyncHttpClient Project. All rights reserved. | |
2 | * | |
3 | * This program is licensed to you under the Apache License Version 2.0, | |
4 | * and you may not use this file except in compliance with the Apache License Version 2.0. | |
5 | * You may obtain a copy of the Apache License Version 2.0 at | |
6 | * http://www.apache.org/licenses/LICENSE-2.0. | |
7 | * | |
8 | * Unless required by applicable law or agreed to in writing, | |
9 | * software distributed under the Apache License Version 2.0 is distributed on an | |
10 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
11 | * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. | |
12 | */ | |
13 | package org.asynchttpclient.netty.channel; | |
14 | ||
15 | import org.asynchttpclient.exception.TooManyConnectionsException; | |
16 | ||
17 | import java.io.IOException; | |
18 | ||
19 | import static org.asynchttpclient.util.ThrowableUtil.unknownStackTrace; | |
20 | ||
21 | /** | |
22 | * Max connections limiter. | |
23 | * | |
24 | * @author Stepan Koltsov | |
25 | */ | |
26 | public class MaxConnectionSemaphore implements ConnectionSemaphore { | |
27 | ||
28 | private final NonBlockingSemaphoreLike freeChannels; | |
29 | private final IOException tooManyConnections; | |
30 | ||
31 | MaxConnectionSemaphore(int maxConnections) { | |
32 | tooManyConnections = unknownStackTrace(new TooManyConnectionsException(maxConnections), MaxConnectionSemaphore.class, "acquireChannelLock"); | |
33 | freeChannels = maxConnections > 0 ? new NonBlockingSemaphore(maxConnections) : NonBlockingSemaphoreInfinite.INSTANCE; | |
34 | } | |
35 | ||
36 | @Override | |
37 | public void acquireChannelLock(Object partitionKey) throws IOException { | |
38 | if (!freeChannels.tryAcquire()) | |
39 | throw tooManyConnections; | |
40 | } | |
41 | ||
42 | @Override | |
43 | public void releaseChannelLock(Object partitionKey) { | |
44 | freeChannels.release(); | |
45 | } | |
46 | } |
+30
-0
0 | /* | |
1 | * Copyright (c) 2018 AsyncHttpClient Project. All rights reserved. | |
2 | * | |
3 | * This program is licensed to you under the Apache License Version 2.0, | |
4 | * and you may not use this file except in compliance with the Apache License Version 2.0. | |
5 | * You may obtain a copy of the Apache License Version 2.0 at | |
6 | * http://www.apache.org/licenses/LICENSE-2.0. | |
7 | * | |
8 | * Unless required by applicable law or agreed to in writing, | |
9 | * software distributed under the Apache License Version 2.0 is distributed on an | |
10 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
11 | * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. | |
12 | */ | |
13 | package org.asynchttpclient.netty.channel; | |
14 | ||
15 | import java.io.IOException; | |
16 | ||
17 | /** | |
18 | * No-op implementation of {@link ConnectionSemaphore}. | |
19 | */ | |
20 | public class NoopConnectionSemaphore implements ConnectionSemaphore { | |
21 | ||
22 | @Override | |
23 | public void acquireChannelLock(Object partitionKey) throws IOException { | |
24 | } | |
25 | ||
26 | @Override | |
27 | public void releaseChannelLock(Object partitionKey) { | |
28 | } | |
29 | } |
+61
-0
0 | /* | |
1 | * Copyright (c) 2018 AsyncHttpClient Project. All rights reserved. | |
2 | * | |
3 | * This program is licensed to you under the Apache License Version 2.0, | |
4 | * and you may not use this file except in compliance with the Apache License Version 2.0. | |
5 | * You may obtain a copy of the Apache License Version 2.0 at | |
6 | * http://www.apache.org/licenses/LICENSE-2.0. | |
7 | * | |
8 | * Unless required by applicable law or agreed to in writing, | |
9 | * software distributed under the Apache License Version 2.0 is distributed on an | |
10 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
11 | * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. | |
12 | */ | |
13 | package org.asynchttpclient.netty.channel; | |
14 | ||
15 | import org.asynchttpclient.exception.TooManyConnectionsPerHostException; | |
16 | ||
17 | import java.io.IOException; | |
18 | import java.util.concurrent.ConcurrentHashMap; | |
19 | ||
20 | import static org.asynchttpclient.util.ThrowableUtil.unknownStackTrace; | |
21 | ||
22 | /** | |
23 | * Max per-host connections limiter. | |
24 | */ | |
25 | public class PerHostConnectionSemaphore implements ConnectionSemaphore { | |
26 | ||
27 | private final ConnectionSemaphore globalSemaphore; | |
28 | ||
29 | private final ConcurrentHashMap<Object, NonBlockingSemaphore> freeChannelsPerHost = new ConcurrentHashMap<>(); | |
30 | private final int maxConnectionsPerHost; | |
31 | private final IOException tooManyConnectionsPerHost; | |
32 | ||
33 | PerHostConnectionSemaphore(int maxConnectionsPerHost, ConnectionSemaphore globalSemaphore) { | |
34 | this.globalSemaphore = globalSemaphore; | |
35 | tooManyConnectionsPerHost = unknownStackTrace(new TooManyConnectionsPerHostException(maxConnectionsPerHost), PerHostConnectionSemaphore.class, "acquireChannelLock"); | |
36 | this.maxConnectionsPerHost = maxConnectionsPerHost; | |
37 | } | |
38 | ||
39 | @Override | |
40 | public void acquireChannelLock(Object partitionKey) throws IOException { | |
41 | globalSemaphore.acquireChannelLock(partitionKey); | |
42 | ||
43 | if (!getFreeConnectionsForHost(partitionKey).tryAcquire()) { | |
44 | globalSemaphore.releaseChannelLock(partitionKey); | |
45 | throw tooManyConnectionsPerHost; | |
46 | } | |
47 | } | |
48 | ||
49 | @Override | |
50 | public void releaseChannelLock(Object partitionKey) { | |
51 | globalSemaphore.releaseChannelLock(partitionKey); | |
52 | getFreeConnectionsForHost(partitionKey).release(); | |
53 | } | |
54 | ||
55 | private NonBlockingSemaphoreLike getFreeConnectionsForHost(Object partitionKey) { | |
56 | return maxConnectionsPerHost > 0 ? | |
57 | freeChannelsPerHost.computeIfAbsent(partitionKey, pk -> new NonBlockingSemaphore(maxConnectionsPerHost)) : | |
58 | NonBlockingSemaphoreInfinite.INSTANCE; | |
59 | } | |
60 | } |
+9
-2
13 | 13 | package org.asynchttpclient.netty.handler.intercept; |
14 | 14 | |
15 | 15 | import io.netty.channel.Channel; |
16 | import io.netty.util.concurrent.Future; | |
16 | 17 | import org.asynchttpclient.Request; |
17 | 18 | import org.asynchttpclient.RequestBuilder; |
18 | 19 | import org.asynchttpclient.netty.NettyResponseFuture; |
46 | 47 | Uri requestUri = request.getUri(); |
47 | 48 | LOGGER.debug("Connecting to proxy {} for scheme {}", proxyServer, requestUri.getScheme()); |
48 | 49 | |
49 | channelManager.updatePipelineForHttpTunneling(channel.pipeline(), requestUri); | |
50 | Future<Channel> whenHandshaked = channelManager.updatePipelineForHttpTunneling(channel.pipeline(), requestUri); | |
51 | ||
50 | 52 | future.setReuseChannel(true); |
51 | 53 | future.setConnectAllowed(false); |
52 | requestSender.drainChannelAndExecuteNextRequest(channel, future, new RequestBuilder(future.getTargetRequest()).build()); | |
54 | Request targetRequest = new RequestBuilder(future.getTargetRequest()).build(); | |
55 | if (whenHandshaked == null) { | |
56 | requestSender.drainChannelAndExecuteNextRequest(channel, future, targetRequest); | |
57 | } else { | |
58 | requestSender.drainChannelAndExecuteNextRequest(channel, future, targetRequest, whenHandshaked); | |
59 | } | |
53 | 60 | |
54 | 61 | return true; |
55 | 62 | } |
74 | 74 | AsyncHttpClientState clientState) { |
75 | 75 | this.config = config; |
76 | 76 | this.channelManager = channelManager; |
77 | this.connectionSemaphore = ConnectionSemaphore.newConnectionSemaphore(config); | |
77 | this.connectionSemaphore = config.getConnectionSemaphoreFactory() == null | |
78 | ? new DefaultConnectionSemaphoreFactory().newConnectionSemaphore(config) | |
79 | : config.getConnectionSemaphoreFactory().newConnectionSemaphore(config); | |
78 | 80 | this.nettyTimer = nettyTimer; |
79 | 81 | this.clientState = clientState; |
80 | 82 | requestFactory = new NettyRequestFactory(config); |
459 | 461 | |
460 | 462 | public void abort(Channel channel, NettyResponseFuture<?> future, Throwable t) { |
461 | 463 | |
462 | if (channel != null) { | |
464 | if (channel != null && channel.isActive()) { | |
463 | 465 | channelManager.closeChannel(channel); |
464 | 466 | } |
465 | 467 | |
603 | 605 | return clientState.isClosed(); |
604 | 606 | } |
605 | 607 | |
606 | public void drainChannelAndExecuteNextRequest(final Channel channel, final NettyResponseFuture<?> future, | |
608 | public void drainChannelAndExecuteNextRequest(final Channel channel, | |
609 | final NettyResponseFuture<?> future, | |
607 | 610 | Request nextRequest) { |
608 | 611 | Channels.setAttribute(channel, new OnLastHttpContentCallback(future) { |
609 | 612 | @Override |
612 | 615 | } |
613 | 616 | }); |
614 | 617 | } |
618 | ||
619 | public void drainChannelAndExecuteNextRequest(final Channel channel, | |
620 | final NettyResponseFuture<?> future, | |
621 | Request nextRequest, | |
622 | Future<Channel> whenHandshaked) { | |
623 | Channels.setAttribute(channel, new OnLastHttpContentCallback(future) { | |
624 | @Override | |
625 | public void call() { | |
626 | whenHandshaked.addListener(f -> { | |
627 | if (f.isSuccess()) { | |
628 | sendNextRequest(nextRequest, future); | |
629 | } else { | |
630 | future.abort(f.cause()); | |
631 | } | |
632 | } | |
633 | ); | |
634 | } | |
635 | }); | |
636 | } | |
637 | ||
615 | 638 | } |
1 | 1 | <parent> |
2 | 2 | <groupId>org.asynchttpclient</groupId> |
3 | 3 | <artifactId>async-http-client-project</artifactId> |
4 | <version>2.4.9</version> | |
4 | <version>2.5.0</version> | |
5 | 5 | </parent> |
6 | 6 | <modelVersion>4.0.0</modelVersion> |
7 | 7 | <artifactId>async-http-client-example</artifactId> |
1 | 1 | <parent> |
2 | 2 | <groupId>org.asynchttpclient</groupId> |
3 | 3 | <artifactId>async-http-client-extras-parent</artifactId> |
4 | <version>2.4.9</version> | |
4 | <version>2.5.0</version> | |
5 | 5 | </parent> |
6 | 6 | <modelVersion>4.0.0</modelVersion> |
7 | 7 | <artifactId>async-http-client-extras-guava</artifactId> |
17 | 17 | <parent> |
18 | 18 | <artifactId>async-http-client-extras-parent</artifactId> |
19 | 19 | <groupId>org.asynchttpclient</groupId> |
20 | <version>2.4.9</version> | |
20 | <version>2.5.0</version> | |
21 | 21 | </parent> |
22 | 22 | <artifactId>async-http-client-extras-jdeferred</artifactId> |
23 | 23 | <name>Asynchronous Http Client JDeferred Extras</name> |
1 | 1 | <parent> |
2 | 2 | <groupId>org.asynchttpclient</groupId> |
3 | 3 | <artifactId>async-http-client-project</artifactId> |
4 | <version>2.4.9</version> | |
4 | <version>2.5.0</version> | |
5 | 5 | </parent> |
6 | 6 | <modelVersion>4.0.0</modelVersion> |
7 | 7 | <artifactId>async-http-client-extras-parent</artifactId> |
1 | 1 | <parent> |
2 | 2 | <groupId>org.asynchttpclient</groupId> |
3 | 3 | <artifactId>async-http-client-extras-parent</artifactId> |
4 | <version>2.4.9</version> | |
4 | <version>2.5.0</version> | |
5 | 5 | </parent> |
6 | 6 | <modelVersion>4.0.0</modelVersion> |
7 | 7 | <artifactId>async-http-client-extras-registry</artifactId> |
3 | 3 | <parent> |
4 | 4 | <artifactId>async-http-client-extras-parent</artifactId> |
5 | 5 | <groupId>org.asynchttpclient</groupId> |
6 | <version>2.4.9</version> | |
6 | <version>2.5.0</version> | |
7 | 7 | </parent> |
8 | 8 | |
9 | 9 | <artifactId>async-http-client-extras-retrofit2</artifactId> |
2 | 2 | <parent> |
3 | 3 | <artifactId>async-http-client-extras-parent</artifactId> |
4 | 4 | <groupId>org.asynchttpclient</groupId> |
5 | <version>2.4.9</version> | |
5 | <version>2.5.0</version> | |
6 | 6 | </parent> |
7 | 7 | <artifactId>async-http-client-extras-rxjava</artifactId> |
8 | 8 | <name>Asynchronous Http Client RxJava Extras</name> |
2 | 2 | <parent> |
3 | 3 | <artifactId>async-http-client-extras-parent</artifactId> |
4 | 4 | <groupId>org.asynchttpclient</groupId> |
5 | <version>2.4.9</version> | |
5 | <version>2.5.0</version> | |
6 | 6 | </parent> |
7 | 7 | <artifactId>async-http-client-extras-rxjava2</artifactId> |
8 | 8 | <name>Asynchronous Http Client RxJava2 Extras</name> |
2 | 2 | <parent> |
3 | 3 | <artifactId>async-http-client-extras-parent</artifactId> |
4 | 4 | <groupId>org.asynchttpclient</groupId> |
5 | <version>2.4.9</version> | |
5 | <version>2.5.0</version> | |
6 | 6 | </parent> |
7 | 7 | <artifactId>async-http-client-extras-simple</artifactId> |
8 | 8 | <name>Asynchronous Http Simple Client</name> |
3 | 3 | <parent> |
4 | 4 | <artifactId>async-http-client-extras-parent</artifactId> |
5 | 5 | <groupId>org.asynchttpclient</groupId> |
6 | <version>2.4.9</version> | |
6 | <version>2.5.0</version> | |
7 | 7 | </parent> |
8 | 8 | |
9 | 9 | <artifactId>async-http-client-extras-typesafe-config</artifactId> |
+6
-0
30 | 30 | import org.asynchttpclient.filter.IOExceptionFilter; |
31 | 31 | import org.asynchttpclient.filter.RequestFilter; |
32 | 32 | import org.asynchttpclient.filter.ResponseFilter; |
33 | import org.asynchttpclient.netty.channel.ConnectionSemaphoreFactory; | |
33 | 34 | import org.asynchttpclient.proxy.ProxyServerSelector; |
34 | 35 | |
35 | 36 | import java.util.*; |
323 | 324 | } |
324 | 325 | |
325 | 326 | @Override |
327 | public ConnectionSemaphoreFactory getConnectionSemaphoreFactory() { | |
328 | return null; | |
329 | } | |
330 | ||
331 | @Override | |
326 | 332 | public Timer getNettyTimer() { |
327 | 333 | return null; |
328 | 334 | } |
1 | 1 | <parent> |
2 | 2 | <groupId>org.asynchttpclient</groupId> |
3 | 3 | <artifactId>async-http-client-project</artifactId> |
4 | <version>2.4.9</version> | |
4 | <version>2.5.0</version> | |
5 | 5 | </parent> |
6 | 6 | <modelVersion>4.0.0</modelVersion> |
7 | 7 | <artifactId>async-http-client-netty-utils</artifactId> |
8 | 8 | <groupId>org.asynchttpclient</groupId> |
9 | 9 | <artifactId>async-http-client-project</artifactId> |
10 | 10 | <name>Asynchronous Http Client Project</name> |
11 | <version>2.4.9</version> | |
11 | <version>2.5.0</version> | |
12 | 12 | <packaging>pom</packaging> |
13 | 13 | <description> |
14 | 14 | The Async Http Client (AHC) library's purpose is to allow Java |