You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2017/03/01 10:01:14 UTC
svn commit: r1784890 - in /httpcomponents/httpcore/trunk:
httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/
httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/bootstrap/
httpcore5-testing/src/main/java/org/apache/hc/core5/testing/...
Author: olegk
Date: Wed Mar 1 10:01:13 2017
New Revision: 1784890
URL: http://svn.apache.org/viewvc?rev=1784890&view=rev
Log:
Reworked async client side APIs
Added:
httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/ClientSessionEndpoint.java (contents, props changed)
- copied, changed from r1784127, httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/ClientSessionEndpoint.java
httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/AsyncClientEndpoint.java (contents, props changed)
- copied, changed from r1784127, httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/PooledClientEndpoint.java
Removed:
httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/ClientSessionEndpoint.java
httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/PooledClientEndpoint.java
Modified:
httpcomponents/httpcore/trunk/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2MultiStreamExecutionExample.java
httpcomponents/httpcore/trunk/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2RequestExecutionExample.java
httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/bootstrap/H2RequesterBootstrap.java
httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/Http1TestClient.java
httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http2/Http2TestClient.java
httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/compatibility/http2/Http2CompatibilityTest.java
httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/http/Http1IntegrationTest.java
httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/http2/Http2IntegrationTest.java
httpcomponents/httpcore/trunk/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncPipelinedRequestExecutionExample.java
httpcomponents/httpcore/trunk/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncRequestExecutionExample.java
httpcomponents/httpcore/trunk/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncReverseProxyExample.java
httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequesterBootstrap.java
httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncRequester.java
httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/PoolEntryHolder.java
Modified: httpcomponents/httpcore/trunk/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2MultiStreamExecutionExample.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2MultiStreamExecutionExample.java?rev=1784890&r1=1784889&r2=1784890&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2MultiStreamExecutionExample.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2MultiStreamExecutionExample.java Wed Mar 1 10:01:13 2017
@@ -38,7 +38,7 @@ import org.apache.hc.core5.http.HttpHost
import org.apache.hc.core5.http.HttpResponse;
import org.apache.hc.core5.http.Message;
import org.apache.hc.core5.http.impl.bootstrap.HttpAsyncRequester;
-import org.apache.hc.core5.http.impl.bootstrap.PooledClientEndpoint;
+import org.apache.hc.core5.http.nio.AsyncClientEndpoint;
import org.apache.hc.core5.http.nio.BasicRequestProducer;
import org.apache.hc.core5.http.nio.BasicResponseConsumer;
import org.apache.hc.core5.http.nio.entity.StringAsyncEntityConsumer;
@@ -107,8 +107,8 @@ public class Http2MultiStreamExecutionEx
HttpHost target = new HttpHost("http2bin.org");
String[] requestUris = new String[] {"/", "/ip", "/user-agent", "/headers"};
- Future<PooledClientEndpoint> future = requester.connect(target, 5, TimeUnit.SECONDS);
- PooledClientEndpoint clientEndpoint = future.get();
+ Future<AsyncClientEndpoint> future = requester.connect(target, 5, TimeUnit.SECONDS);
+ AsyncClientEndpoint clientEndpoint = future.get();
final CountDownLatch latch = new CountDownLatch(requestUris.length);
for (final String requestUri: requestUris) {
Modified: httpcomponents/httpcore/trunk/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2RequestExecutionExample.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2RequestExecutionExample.java?rev=1784890&r1=1784889&r2=1784890&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2RequestExecutionExample.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2RequestExecutionExample.java Wed Mar 1 10:01:13 2017
@@ -38,7 +38,7 @@ import org.apache.hc.core5.http.HttpHost
import org.apache.hc.core5.http.HttpResponse;
import org.apache.hc.core5.http.Message;
import org.apache.hc.core5.http.impl.bootstrap.HttpAsyncRequester;
-import org.apache.hc.core5.http.impl.bootstrap.PooledClientEndpoint;
+import org.apache.hc.core5.http.nio.AsyncClientEndpoint;
import org.apache.hc.core5.http.nio.BasicRequestProducer;
import org.apache.hc.core5.http.nio.BasicResponseConsumer;
import org.apache.hc.core5.http.nio.entity.StringAsyncEntityConsumer;
@@ -109,8 +109,8 @@ public class Http2RequestExecutionExampl
final CountDownLatch latch = new CountDownLatch(requestUris.length);
for (final String requestUri: requestUris) {
- final Future<PooledClientEndpoint> future = requester.connect(target, 5, TimeUnit.SECONDS);
- final PooledClientEndpoint clientEndpoint = future.get();
+ final Future<AsyncClientEndpoint> future = requester.connect(target, 5, TimeUnit.SECONDS);
+ final AsyncClientEndpoint clientEndpoint = future.get();
clientEndpoint.executeAndRelease(
new BasicRequestProducer("GET", target, requestUri),
new BasicResponseConsumer<>(new StringAsyncEntityConsumer()),
Modified: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/bootstrap/H2RequesterBootstrap.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/bootstrap/H2RequesterBootstrap.java?rev=1784890&r1=1784889&r2=1784890&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/bootstrap/H2RequesterBootstrap.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/bootstrap/H2RequesterBootstrap.java Wed Mar 1 10:01:13 2017
@@ -35,7 +35,6 @@ import org.apache.hc.core5.http.Exceptio
import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.config.CharCodingConfig;
import org.apache.hc.core5.http.impl.ConnectionListener;
-import org.apache.hc.core5.http.impl.bootstrap.ClientSessionEndpoint;
import org.apache.hc.core5.http.impl.bootstrap.HttpAsyncRequester;
import org.apache.hc.core5.http.nio.AsyncPushConsumer;
import org.apache.hc.core5.http.nio.ssl.TlsStrategy;
@@ -49,6 +48,7 @@ import org.apache.hc.core5.pool.ConnPool
import org.apache.hc.core5.pool.ConnPoolPolicy;
import org.apache.hc.core5.pool.StrictConnPool;
import org.apache.hc.core5.reactor.IOReactorConfig;
+import org.apache.hc.core5.reactor.IOSession;
import org.apache.hc.core5.util.Args;
/**
@@ -193,7 +193,7 @@ public class H2RequesterBootstrap {
}
public HttpAsyncRequester create() {
- final StrictConnPool<HttpHost, ClientSessionEndpoint> connPool = new StrictConnPool<>(
+ final StrictConnPool<HttpHost, IOSession> connPool = new StrictConnPool<>(
defaultMaxPerRoute > 0 ? defaultMaxPerRoute : 20,
maxTotal > 0 ? maxTotal : 50,
timeToLive, timeUnit != null ? timeUnit : TimeUnit.MILLISECONDS,
Copied: httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/ClientSessionEndpoint.java (from r1784127, httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/ClientSessionEndpoint.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/ClientSessionEndpoint.java?p2=httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/ClientSessionEndpoint.java&p1=httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/ClientSessionEndpoint.java&r1=1784127&r2=1784890&rev=1784890&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/ClientSessionEndpoint.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/ClientSessionEndpoint.java Wed Mar 1 10:01:13 2017
@@ -25,7 +25,7 @@
*
*/
-package org.apache.hc.core5.http.impl.bootstrap;
+package org.apache.hc.core5.testing.nio.http;
import java.io.Closeable;
import java.io.IOException;
Propchange: httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/ClientSessionEndpoint.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/ClientSessionEndpoint.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/ClientSessionEndpoint.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/Http1TestClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/Http1TestClient.java?rev=1784890&r1=1784889&r2=1784890&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/Http1TestClient.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/Http1TestClient.java Wed Mar 1 10:01:13 2017
@@ -44,7 +44,6 @@ import org.apache.hc.core5.http.config.H
import org.apache.hc.core5.http.impl.DefaultConnectionReuseStrategy;
import org.apache.hc.core5.http.impl.HttpProcessors;
import org.apache.hc.core5.http.impl.bootstrap.AsyncRequester;
-import org.apache.hc.core5.http.impl.bootstrap.ClientSessionEndpoint;
import org.apache.hc.core5.http.nio.command.ShutdownCommand;
import org.apache.hc.core5.http.nio.command.ShutdownType;
import org.apache.hc.core5.http.protocol.HttpProcessor;
Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http2/Http2TestClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http2/Http2TestClient.java?rev=1784890&r1=1784889&r2=1784890&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http2/Http2TestClient.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http2/Http2TestClient.java Wed Mar 1 10:01:13 2017
@@ -42,7 +42,7 @@ import org.apache.hc.core5.http.Exceptio
import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.config.CharCodingConfig;
import org.apache.hc.core5.http.impl.bootstrap.AsyncRequester;
-import org.apache.hc.core5.http.impl.bootstrap.ClientSessionEndpoint;
+import org.apache.hc.core5.testing.nio.http.ClientSessionEndpoint;
import org.apache.hc.core5.http.nio.AsyncPushConsumer;
import org.apache.hc.core5.http.nio.command.ShutdownCommand;
import org.apache.hc.core5.http.nio.command.ShutdownType;
Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/compatibility/http2/Http2CompatibilityTest.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/compatibility/http2/Http2CompatibilityTest.java?rev=1784890&r1=1784889&r2=1784890&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/compatibility/http2/Http2CompatibilityTest.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/compatibility/http2/Http2CompatibilityTest.java Wed Mar 1 10:01:13 2017
@@ -47,7 +47,7 @@ import org.apache.hc.core5.http.HttpRequ
import org.apache.hc.core5.http.HttpResponse;
import org.apache.hc.core5.http.HttpStatus;
import org.apache.hc.core5.http.Message;
-import org.apache.hc.core5.http.impl.bootstrap.ClientSessionEndpoint;
+import org.apache.hc.core5.testing.nio.http.ClientSessionEndpoint;
import org.apache.hc.core5.http.message.BasicHttpRequest;
import org.apache.hc.core5.http.nio.AsyncPushConsumer;
import org.apache.hc.core5.http.nio.BasicRequestProducer;
Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/http/Http1IntegrationTest.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/http/Http1IntegrationTest.java?rev=1784890&r1=1784889&r2=1784890&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/http/Http1IntegrationTest.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/http/Http1IntegrationTest.java Wed Mar 1 10:01:13 2017
@@ -81,7 +81,6 @@ import org.apache.hc.core5.http.impl.Con
import org.apache.hc.core5.http.impl.DefaultConnectionReuseStrategy;
import org.apache.hc.core5.http.impl.Http1StreamListener;
import org.apache.hc.core5.http.impl.HttpProcessors;
-import org.apache.hc.core5.http.impl.bootstrap.ClientSessionEndpoint;
import org.apache.hc.core5.http.impl.nio.AbstractClassicServerExchangeHandler;
import org.apache.hc.core5.http.impl.nio.AbstractContentEncoder;
import org.apache.hc.core5.http.impl.nio.ServerHttp1StreamDuplexer;
Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/http2/Http2IntegrationTest.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/http2/Http2IntegrationTest.java?rev=1784890&r1=1784889&r2=1784890&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/http2/Http2IntegrationTest.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/http2/Http2IntegrationTest.java Wed Mar 1 10:01:13 2017
@@ -70,7 +70,7 @@ import org.apache.hc.core5.http.HttpRequ
import org.apache.hc.core5.http.HttpResponse;
import org.apache.hc.core5.http.HttpStatus;
import org.apache.hc.core5.http.Message;
-import org.apache.hc.core5.http.impl.bootstrap.ClientSessionEndpoint;
+import org.apache.hc.core5.testing.nio.http.ClientSessionEndpoint;
import org.apache.hc.core5.http.impl.nio.AbstractClassicServerExchangeHandler;
import org.apache.hc.core5.http.impl.nio.entity.AbstractClassicEntityConsumer;
import org.apache.hc.core5.http.impl.nio.entity.AbstractClassicEntityProducer;
Modified: httpcomponents/httpcore/trunk/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncPipelinedRequestExecutionExample.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncPipelinedRequestExecutionExample.java?rev=1784890&r1=1784889&r2=1784890&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncPipelinedRequestExecutionExample.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncPipelinedRequestExecutionExample.java Wed Mar 1 10:01:13 2017
@@ -39,9 +39,9 @@ import org.apache.hc.core5.http.Message;
import org.apache.hc.core5.http.impl.Http1StreamListener;
import org.apache.hc.core5.http.impl.bootstrap.AsyncRequesterBootstrap;
import org.apache.hc.core5.http.impl.bootstrap.HttpAsyncRequester;
-import org.apache.hc.core5.http.impl.bootstrap.PooledClientEndpoint;
import org.apache.hc.core5.http.message.RequestLine;
import org.apache.hc.core5.http.message.StatusLine;
+import org.apache.hc.core5.http.nio.AsyncClientEndpoint;
import org.apache.hc.core5.http.nio.BasicRequestProducer;
import org.apache.hc.core5.http.nio.BasicResponseConsumer;
import org.apache.hc.core5.http.nio.entity.StringAsyncEntityConsumer;
@@ -99,8 +99,8 @@ public class AsyncPipelinedRequestExecut
HttpHost target = new HttpHost("httpbin.org");
String[] requestUris = new String[] {"/", "/ip", "/user-agent", "/headers"};
- Future<PooledClientEndpoint> future = requester.connect(target, 5, TimeUnit.SECONDS);
- PooledClientEndpoint clientEndpoint = future.get();
+ Future<AsyncClientEndpoint> future = requester.connect(target, 5, TimeUnit.SECONDS);
+ AsyncClientEndpoint clientEndpoint = future.get();
final CountDownLatch latch = new CountDownLatch(requestUris.length);
for (final String requestUri: requestUris) {
Modified: httpcomponents/httpcore/trunk/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncRequestExecutionExample.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncRequestExecutionExample.java?rev=1784890&r1=1784889&r2=1784890&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncRequestExecutionExample.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncRequestExecutionExample.java Wed Mar 1 10:01:13 2017
@@ -39,9 +39,9 @@ import org.apache.hc.core5.http.Message;
import org.apache.hc.core5.http.impl.Http1StreamListener;
import org.apache.hc.core5.http.impl.bootstrap.AsyncRequesterBootstrap;
import org.apache.hc.core5.http.impl.bootstrap.HttpAsyncRequester;
-import org.apache.hc.core5.http.impl.bootstrap.PooledClientEndpoint;
import org.apache.hc.core5.http.message.RequestLine;
import org.apache.hc.core5.http.message.StatusLine;
+import org.apache.hc.core5.http.nio.AsyncClientEndpoint;
import org.apache.hc.core5.http.nio.BasicRequestProducer;
import org.apache.hc.core5.http.nio.BasicResponseConsumer;
import org.apache.hc.core5.http.nio.entity.StringAsyncEntityConsumer;
@@ -101,8 +101,8 @@ public class AsyncRequestExecutionExampl
final CountDownLatch latch = new CountDownLatch(requestUris.length);
for (final String requestUri: requestUris) {
- final Future<PooledClientEndpoint> future = requester.connect(target, 5, TimeUnit.SECONDS);
- final PooledClientEndpoint clientEndpoint = future.get();
+ final Future<AsyncClientEndpoint> future = requester.connect(target, 5, TimeUnit.SECONDS);
+ final AsyncClientEndpoint clientEndpoint = future.get();
clientEndpoint.executeAndRelease(
new BasicRequestProducer("GET", target, requestUri),
new BasicResponseConsumer<>(new StringAsyncEntityConsumer()),
Modified: httpcomponents/httpcore/trunk/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncReverseProxyExample.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncReverseProxyExample.java?rev=1784890&r1=1784889&r2=1784890&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncReverseProxyExample.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncReverseProxyExample.java Wed Mar 1 10:01:13 2017
@@ -64,10 +64,10 @@ import org.apache.hc.core5.http.impl.boo
import org.apache.hc.core5.http.impl.bootstrap.AsyncServerBootstrap;
import org.apache.hc.core5.http.impl.bootstrap.HttpAsyncRequester;
import org.apache.hc.core5.http.impl.bootstrap.HttpAsyncServer;
-import org.apache.hc.core5.http.impl.bootstrap.PooledClientEndpoint;
import org.apache.hc.core5.http.impl.nio.ExpandableBuffer;
import org.apache.hc.core5.http.message.BasicHttpRequest;
import org.apache.hc.core5.http.message.BasicHttpResponse;
+import org.apache.hc.core5.http.nio.AsyncClientEndpoint;
import org.apache.hc.core5.http.nio.AsyncClientExchangeHandler;
import org.apache.hc.core5.http.nio.AsyncServerExchangeHandler;
import org.apache.hc.core5.http.nio.CapacityChannel;
@@ -312,10 +312,10 @@ public class AsyncReverseProxyExample {
System.out.println("[proxy->origin] " + exchangeState.id + " request connection to " + targetHost);
- requester.connect(targetHost, 30, TimeUnit.SECONDS, new FutureCallback<PooledClientEndpoint>() {
+ requester.connect(targetHost, 30, TimeUnit.SECONDS, new FutureCallback<AsyncClientEndpoint>() {
@Override
- public void completed(final PooledClientEndpoint clientEndpoint) {
+ public void completed(final AsyncClientEndpoint clientEndpoint) {
System.out.println("[proxy->origin] " + exchangeState.id + " connection leased");
clientEndpoint.execute(new OutgoingExchangeHandler(clientEndpoint, exchangeState), null);
}
@@ -473,10 +473,10 @@ public class AsyncReverseProxyExample {
private static class OutgoingExchangeHandler implements AsyncClientExchangeHandler {
- private final PooledClientEndpoint clientEndpoint;
+ private final AsyncClientEndpoint clientEndpoint;
private final ProxyExchangeState exchangeState;
- OutgoingExchangeHandler(final PooledClientEndpoint clientEndpoint, final ProxyExchangeState exchangeState) {
+ OutgoingExchangeHandler(final AsyncClientEndpoint clientEndpoint, final ProxyExchangeState exchangeState) {
this.clientEndpoint = clientEndpoint;
this.exchangeState = exchangeState;
}
Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequesterBootstrap.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequesterBootstrap.java?rev=1784890&r1=1784889&r2=1784890&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequesterBootstrap.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequesterBootstrap.java Wed Mar 1 10:01:13 2017
@@ -47,6 +47,7 @@ import org.apache.hc.core5.pool.ConnPool
import org.apache.hc.core5.pool.ConnPoolPolicy;
import org.apache.hc.core5.pool.StrictConnPool;
import org.apache.hc.core5.reactor.IOReactorConfig;
+import org.apache.hc.core5.reactor.IOSession;
/**
* @since 5.0
@@ -172,7 +173,7 @@ public class AsyncRequesterBootstrap {
}
public HttpAsyncRequester create() {
- final StrictConnPool<HttpHost, ClientSessionEndpoint> connPool = new StrictConnPool<>(
+ final StrictConnPool<HttpHost, IOSession> connPool = new StrictConnPool<>(
defaultMaxPerRoute > 0 ? defaultMaxPerRoute : 20,
maxTotal > 0 ? maxTotal : 50,
timeToLive, timeUnit != null ? timeUnit : TimeUnit.MILLISECONDS,
Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncRequester.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncRequester.java?rev=1784890&r1=1784889&r2=1784890&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncRequester.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncRequester.java Wed Mar 1 10:01:13 2017
@@ -37,9 +37,12 @@ import org.apache.hc.core5.concurrent.Fu
import org.apache.hc.core5.function.Callback;
import org.apache.hc.core5.http.ExceptionListener;
import org.apache.hc.core5.http.HttpHost;
+import org.apache.hc.core5.http.nio.AsyncClientEndpoint;
+import org.apache.hc.core5.http.nio.AsyncClientExchangeHandler;
import org.apache.hc.core5.http.nio.command.ShutdownCommand;
import org.apache.hc.core5.http.nio.command.ShutdownType;
import org.apache.hc.core5.http.nio.ssl.TlsStrategy;
+import org.apache.hc.core5.http.protocol.HttpContext;
import org.apache.hc.core5.pool.ControlledConnPool;
import org.apache.hc.core5.pool.PoolEntry;
import org.apache.hc.core5.reactor.IOEventHandlerFactory;
@@ -56,13 +59,13 @@ import org.apache.hc.core5.util.Args;
public class HttpAsyncRequester extends AsyncRequester {
private final IOEventHandlerFactory handlerFactory;
- private final ControlledConnPool<HttpHost, ClientSessionEndpoint> connPool;
+ private final ControlledConnPool<HttpHost, IOSession> connPool;
private final TlsStrategy tlsStrategy;
public HttpAsyncRequester(
final IOReactorConfig ioReactorConfig,
final IOEventHandlerFactory handlerFactory,
- final ControlledConnPool<HttpHost, ClientSessionEndpoint> connPool,
+ final ControlledConnPool<HttpHost, IOSession> connPool,
final TlsStrategy tlsStrategy,
final ExceptionListener exceptionListener) {
super(ioReactorConfig, exceptionListener, new Callback<IOSession>() {
@@ -82,36 +85,36 @@ public class HttpAsyncRequester extends
execute(handlerFactory);
}
- public Future<PooledClientEndpoint> connect(
+ public Future<AsyncClientEndpoint> connect(
final HttpHost host,
final long timeout,
final TimeUnit timeUnit,
- final FutureCallback<PooledClientEndpoint> callback) {
+ final FutureCallback<AsyncClientEndpoint> callback) {
Args.notNull(host, "Host");
Args.notNull(timeUnit, "Time unit");
- final ComplexFuture<PooledClientEndpoint> resultFuture = new ComplexFuture<>(callback);
- final Future<PoolEntry<HttpHost, ClientSessionEndpoint>> leaseFuture = connPool.lease(
- host, null, new FutureCallback<PoolEntry<HttpHost, ClientSessionEndpoint>>() {
+ final ComplexFuture<AsyncClientEndpoint> resultFuture = new ComplexFuture<>(callback);
+ final Future<PoolEntry<HttpHost, IOSession>> leaseFuture = connPool.lease(
+ host, null, new FutureCallback<PoolEntry<HttpHost, IOSession>>() {
@Override
- public void completed(final PoolEntry<HttpHost, ClientSessionEndpoint> poolEntry) {
- final PoolEntryHolder<HttpHost, ClientSessionEndpoint> poolEntryHolder = new PoolEntryHolder<>(
+ public void completed(final PoolEntry<HttpHost, IOSession> poolEntry) {
+ final PoolEntryHolder<HttpHost, IOSession> poolEntryHolder = new PoolEntryHolder<>(
connPool,
poolEntry,
- new Callback<ClientSessionEndpoint>() {
+ new Callback<IOSession>() {
@Override
- public void execute(final ClientSessionEndpoint clientEndpoint) {
+ public void execute(final IOSession clientEndpoint) {
clientEndpoint.shutdown();
}
});
- final ClientSessionEndpoint clientEndpoint = poolEntry.getConnection();
- if (clientEndpoint != null && !clientEndpoint.isOpen()) {
+ final IOSession ioSession = poolEntry.getConnection();
+ if (ioSession != null && ioSession.isClosed()) {
poolEntry.discardConnection();
}
if (poolEntry.hasConnection()) {
- resultFuture.completed(new PooledClientEndpoint(poolEntryHolder));
+ resultFuture.completed(new InternalAsyncClientEndpoint(poolEntryHolder));
} else {
final SessionRequest sessionRequest = requestSession(
host, timeout, timeUnit,
@@ -127,8 +130,8 @@ public class HttpAsyncRequester extends
session.getLocalAddress(),
session.getRemoteAddress());
}
- poolEntry.assignConnection(new ClientSessionEndpoint(session));
- resultFuture.completed(new PooledClientEndpoint(poolEntryHolder));
+ poolEntry.assignConnection(session);
+ resultFuture.completed(new InternalAsyncClientEndpoint(poolEntryHolder));
}
@Override
@@ -178,11 +181,36 @@ public class HttpAsyncRequester extends
return resultFuture;
}
- public Future<PooledClientEndpoint> connect(
+ public Future<AsyncClientEndpoint> connect(
final HttpHost host,
final long timeout,
final TimeUnit timeUnit) throws InterruptedException {
return connect(host, timeout, timeUnit, null);
}
+ private static class InternalAsyncClientEndpoint extends AsyncClientEndpoint {
+
+ final PoolEntryHolder<HttpHost, IOSession> poolEntryHolder;
+
+ InternalAsyncClientEndpoint(final PoolEntryHolder<HttpHost, IOSession> poolEntryHolder) {
+ this.poolEntryHolder = poolEntryHolder;
+ }
+
+ @Override
+ public void execute(final AsyncClientExchangeHandler exchangeHandler, final HttpContext context) {
+
+ }
+
+ @Override
+ public void releaseAndReuse() {
+ poolEntryHolder.releaseConnection();
+ }
+
+ @Override
+ public void releaseAndDiscard() {
+ poolEntryHolder.abortConnection();
+ }
+
+ }
+
}
Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/PoolEntryHolder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/PoolEntryHolder.java?rev=1784890&r1=1784889&r2=1784890&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/PoolEntryHolder.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/PoolEntryHolder.java Wed Mar 1 10:01:13 2017
@@ -63,6 +63,10 @@ final class PoolEntryHolder<T, C extends
reusable.set(true);
}
+ public void markNonReusable() {
+ reusable.set(false);
+ }
+
public void releaseConnection() {
final PoolEntry<T, C> poolEntry = poolEntryRef.getAndSet(null);
if (poolEntry != null) {
Copied: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/AsyncClientEndpoint.java (from r1784127, httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/PooledClientEndpoint.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/AsyncClientEndpoint.java?p2=httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/AsyncClientEndpoint.java&p1=httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/PooledClientEndpoint.java&r1=1784127&r2=1784890&rev=1784890&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/PooledClientEndpoint.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/AsyncClientEndpoint.java Wed Mar 1 10:01:13 2017
@@ -25,43 +25,28 @@
*
*/
-package org.apache.hc.core5.http.impl.bootstrap;
+package org.apache.hc.core5.http.nio;
import java.util.concurrent.Future;
import org.apache.hc.core5.annotation.Contract;
import org.apache.hc.core5.annotation.ThreadingBehavior;
+import org.apache.hc.core5.concurrent.BasicFuture;
import org.apache.hc.core5.concurrent.FutureCallback;
-import org.apache.hc.core5.http.HttpHost;
-import org.apache.hc.core5.http.nio.AsyncClientExchangeHandler;
-import org.apache.hc.core5.http.nio.AsyncRequestProducer;
-import org.apache.hc.core5.http.nio.AsyncResponseConsumer;
+import org.apache.hc.core5.http.nio.support.BasicClientExchangeHandler;
import org.apache.hc.core5.http.protocol.HttpContext;
-import org.apache.hc.core5.util.Asserts;
+import org.apache.hc.core5.http.protocol.HttpCoreContext;
/**
- * Client endpoint leased from a pool of connections.
+ * Client endpoint leased from a connection manager.
* <p>
* Once the endpoint is no longer needed it MUST be released with {@link #releaseAndReuse()}
* or {@link #releaseAndDiscard()}.
*
* @since 5.0
*/
-@Contract(threading = ThreadingBehavior.SAFE_CONDITIONAL)
-public final class PooledClientEndpoint {
-
- private final PoolEntryHolder<HttpHost, ClientSessionEndpoint> poolEntryHolder;
-
- PooledClientEndpoint(final PoolEntryHolder<HttpHost, ClientSessionEndpoint> poolEntryHolder) {
- super();
- this.poolEntryHolder = poolEntryHolder;
- }
-
- private ClientSessionEndpoint getClientEndpoint() {
- final ClientSessionEndpoint endpoint = poolEntryHolder.getConnection();
- Asserts.check(endpoint != null, "Client endpoint already released");
- return endpoint;
- }
+@Contract(threading = ThreadingBehavior.SAFE)
+public abstract class AsyncClientEndpoint {
/**
* Initiates a message exchange using the given handler.
@@ -69,9 +54,17 @@ public final class PooledClientEndpoint
* Once the endpoint is no longer needed it MUST be released with {@link #releaseAndReuse()}
* or {@link #releaseAndDiscard()}.
*/
- public void execute(final AsyncClientExchangeHandler exchangeHandler, final HttpContext context) {
- getClientEndpoint().execute(exchangeHandler, context);
- }
+ public abstract void execute(AsyncClientExchangeHandler exchangeHandler, HttpContext context);
+
+ /**
+ * Releases the underlying connection back to the connection pool as re-usable.
+ */
+ public abstract void releaseAndReuse();
+
+ /**
+ * Shuts down the underlying connection and removes it from the connection pool.
+ */
+ public abstract void releaseAndDiscard();
/**
* Initiates message exchange using the given request producer and response consumer.
@@ -79,12 +72,33 @@ public final class PooledClientEndpoint
* Once the endpoint is no longer needed it MUST be released with {@link #releaseAndReuse()}
* or {@link #releaseAndDiscard()}.
*/
- public <T> Future<T> execute(
+ public final <T> Future<T> execute(
final AsyncRequestProducer requestProducer,
final AsyncResponseConsumer<T> responseConsumer,
final HttpContext context,
final FutureCallback<T> callback) {
- return getClientEndpoint().execute(requestProducer, responseConsumer, context, callback);
+ final BasicFuture<T> future = new BasicFuture<>(callback);
+ execute(new BasicClientExchangeHandler<>(requestProducer, responseConsumer,
+ new FutureCallback<T>() {
+
+ @Override
+ public void completed(final T result) {
+ future.completed(result);
+ }
+
+ @Override
+ public void failed(final Exception ex) {
+ future.failed(ex);
+ }
+
+ @Override
+ public void cancelled() {
+ future.cancel();
+ }
+
+ }),
+ context != null ? context : HttpCoreContext.create());
+ return future;
}
/**
@@ -93,7 +107,7 @@ public final class PooledClientEndpoint
* Once the endpoint is no longer needed it MUST be released with {@link #releaseAndReuse()}
* or {@link #releaseAndDiscard()}.
*/
- public <T> Future<T> execute(
+ public final <T> Future<T> execute(
final AsyncRequestProducer requestProducer,
final AsyncResponseConsumer<T> responseConsumer,
final FutureCallback<T> callback) {
@@ -104,12 +118,12 @@ public final class PooledClientEndpoint
* Initiates a message exchange using the given request producer and response consumer and
* automatically invokes {@link #releaseAndReuse()} upon its successful completion.
*/
- public <T> Future<T> executeAndRelease(
+ public final <T> Future<T> executeAndRelease(
final AsyncRequestProducer requestProducer,
final AsyncResponseConsumer<T> responseConsumer,
final HttpContext context,
final FutureCallback<T> callback) {
- return getClientEndpoint().execute(requestProducer, responseConsumer, context, new FutureCallback<T>() {
+ return execute(requestProducer, responseConsumer, context, new FutureCallback<T>() {
@Override
public void completed(final T result) {
@@ -151,32 +165,11 @@ public final class PooledClientEndpoint
* Initiates a message exchange using the given request producer and response consumer and
* automatically invokes {@link #releaseAndReuse()} upon its successful completion.
*/
- public <T> Future<T> executeAndRelease(
+ public final <T> Future<T> executeAndRelease(
final AsyncRequestProducer requestProducer,
final AsyncResponseConsumer<T> responseConsumer,
final FutureCallback<T> callback) {
return executeAndRelease(requestProducer, responseConsumer, null, callback);
}
- /**
- * Releases the underlying connection back to the connection pool as re-usable.
- */
- public void releaseAndReuse() {
- poolEntryHolder.markReusable();
- poolEntryHolder.releaseConnection();
- }
-
- /**
- * Shuts down the underlying connection and removes it from the connection pool.
- */
- public void releaseAndDiscard() {
- poolEntryHolder.abortConnection();
- }
-
- @Override
- public String toString() {
- final ClientSessionEndpoint endpoint = poolEntryHolder.getConnection();
- return endpoint != null ? endpoint.toString() : "released";
- }
-
}
Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/AsyncClientEndpoint.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/AsyncClientEndpoint.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/AsyncClientEndpoint.java
------------------------------------------------------------------------------
svn:mime-type = text/plain