http-client-branch: Cleanup unneeded buffer instance variable from Http1Exchange http-client-branch
authordfuchs
Tue, 14 Nov 2017 16:28:52 +0000
branchhttp-client-branch
changeset 55815 4f699653026b
parent 55814 cb1e2086ca36
child 55816 70738768515a
http-client-branch: Cleanup unneeded buffer instance variable from Http1Exchange
src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/AbstractAsyncSSLConnection.java
src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/Exchange.java
src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/Http1Exchange.java
src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/HttpClientImpl.java
src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/HttpResponseImpl.java
src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/PlainTunnelingConnection.java
--- a/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/AbstractAsyncSSLConnection.java	Tue Nov 14 15:57:11 2017 +0000
+++ b/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/AbstractAsyncSSLConnection.java	Tue Nov 14 16:28:52 2017 +0000
@@ -91,9 +91,6 @@
 
     final SSLEngine getEngine() { return engine; }
 
-//    @Override
-//    SSLParameters sslParameters() { return sslParameters; }
-
     private static SSLParameters createSSLParameters(HttpClientImpl client,
                                                      String serverName,
                                                      String[] alpn) {
--- a/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/Exchange.java	Tue Nov 14 15:57:11 2017 +0000
+++ b/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/Exchange.java	Tue Nov 14 16:28:52 2017 +0000
@@ -340,7 +340,7 @@
                     // while we build the Http2Connection
                     return Http2Connection.createAsync(e.connection(),
                                                  client.client2(),
-                                                 this, e::getBuffer)
+                                                 this, e::drainLeftOverBytes)
                         .thenCompose((Http2Connection c) -> {
                             c.putConnection();
                             Stream<T> s = c.getStream(1);
--- a/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/Http1Exchange.java	Tue Nov 14 15:57:11 2017 +0000
+++ b/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/Http1Exchange.java	Tue Nov 14 16:28:52 2017 +0000
@@ -56,13 +56,12 @@
     private static final System.Logger DEBUG_LOGGER =
             Utils.getDebugLogger("Http1Exchange"::toString, DEBUG);
 
-    final HttpRequestImpl request;        // main request
+    final HttpRequestImpl request; // main request
     final Http1Request requestAction;
     private volatile Http1Response<T> response;
     final HttpConnection connection;
     final HttpClientImpl client;
     final Executor executor;
-    private volatile ByteBuffer buffer; // used for receiving
     private final Http1AsyncReceiver asyncReceiver;
 
     /** Records a possible cancellation raised before any operation
@@ -163,7 +162,6 @@
         this.operations = new LinkedList<>();
         operations.add(headersSentCF);
         operations.add(bodySentCF);
-        this.buffer = Utils.EMPTY_BYTEBUFFER;  // TODO: need to check left over data?
         if (connection != null) {
             this.connection = connection;
         } else {
@@ -327,11 +325,10 @@
         return bodyCF;
     }
 
-    ByteBuffer getBuffer() {
+    ByteBuffer drainLeftOverBytes() {
         synchronized (lock) {
             asyncReceiver.stop();
-            this.buffer = asyncReceiver.drain(this.buffer);
-            return this.buffer;
+            return asyncReceiver.drain(Utils.EMPTY_BYTEBUFFER);
         }
     }
 
--- a/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/HttpClientImpl.java	Tue Nov 14 15:57:11 2017 +0000
+++ b/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/HttpClientImpl.java	Tue Nov 14 16:28:52 2017 +0000
@@ -420,7 +420,7 @@
         long start = DEBUGELAPSED ? System.nanoTime() : 0;
         reference();
         try {
-            debug.log(Level.DEBUG, "ClientImpl (async) send %s", userRequest);
+            debugelapsed.log(Level.DEBUG, "ClientImpl (async) send %s", userRequest);
 
             MultiExchange<Void,T> mex = new MultiExchange<>(userRequest,
                                                             requestImpl,
@@ -462,7 +462,7 @@
         long start = DEBUGELAPSED ? System.nanoTime() : 0;
         reference();
         try {
-            debug.log(Level.DEBUG, "ClientImpl (async) send multi %s", userRequest);
+            debugelapsed.log(Level.DEBUG, "ClientImpl (async) send multi %s", userRequest);
 
             MultiExchange<U,T> mex = new MultiExchange<>(userRequest,
                                                          requestImpl,
--- a/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/HttpResponseImpl.java	Tue Nov 14 15:57:11 2017 +0000
+++ b/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/HttpResponseImpl.java	Tue Nov 14 16:28:52 2017 +0000
@@ -161,7 +161,7 @@
             }
             // Http1Exchange may have some remaining bytes in its
             // internal buffer.
-            Supplier<ByteBuffer> initial = ((Http1Exchange<?>)exchImpl)::getBuffer;
+            Supplier<ByteBuffer> initial = ((Http1Exchange<?>)exchImpl)::drainLeftOverBytes;
             rawchan = new RawChannelImpl(exchange.client(), connection, initial);
         }
         return rawchan;
--- a/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/PlainTunnelingConnection.java	Tue Nov 14 15:57:11 2017 +0000
+++ b/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/PlainTunnelingConnection.java	Tue Nov 14 16:28:52 2017 +0000
@@ -76,7 +76,7 @@
                                         "Tunnel failed, got: "+ resp.statusCode()));
                             } else {
                                 // get the initial/remaining bytes
-                                ByteBuffer b = ((Http1Exchange<?>)connectExchange.exchImpl).getBuffer();
+                                ByteBuffer b = ((Http1Exchange<?>)connectExchange.exchImpl).drainLeftOverBytes();
                                 int remaining = b.remaining();
                                 assert remaining == 0: "Unexpected remaining: " + remaining;
                                 connected = true;