src/java.net.http/share/classes/jdk/internal/net/http/Http2ClientImpl.java
changeset 49944 4690a2871b44
parent 49765 ee6f7a61f3a5
child 50681 4254bed3c09d
child 56507 2294c51eae30
equal deleted inserted replaced
49943:8e1ed2a15845 49944:4690a2871b44
    93         String key = Http2Connection.keyFor(uri, proxy);
    93         String key = Http2Connection.keyFor(uri, proxy);
    94 
    94 
    95         synchronized (this) {
    95         synchronized (this) {
    96             Http2Connection connection = connections.get(key);
    96             Http2Connection connection = connections.get(key);
    97             if (connection != null) {
    97             if (connection != null) {
    98                 if (connection.closed) {
    98                 if (connection.closed || !connection.reserveStream(true)) {
    99                     if (debug.on())
    99                     if (debug.on())
   100                         debug.log("removing found closed connection: %s", connection);
   100                         debug.log("removing found closed or closing connection: %s", connection);
   101                     connections.remove(key);
   101                     deleteConnection(connection);
   102                 } else {
   102                 } else {
   103                     // fast path if connection already exists
   103                     // fast path if connection already exists
   104                     if (debug.on())
   104                     if (debug.on())
   105                         debug.log("found connection in the pool: %s", connection);
   105                         debug.log("found connection in the pool: %s", connection);
   106                     return MinimalFuture.completedFuture(connection);
   106                     return MinimalFuture.completedFuture(connection);
   136      * This situation should not arise with https because the request
   136      * This situation should not arise with https because the request
   137      * has not been sent as part of the initial alpn negotiation
   137      * has not been sent as part of the initial alpn negotiation
   138      */
   138      */
   139     boolean offerConnection(Http2Connection c) {
   139     boolean offerConnection(Http2Connection c) {
   140         if (debug.on()) debug.log("offering to the connection pool: %s", c);
   140         if (debug.on()) debug.log("offering to the connection pool: %s", c);
   141         if (c.closed) {
   141         if (c.closed || c.finalStream()) {
   142             if (debug.on())
   142             if (debug.on())
   143                 debug.log("skipping offered closed connection: %s", c);
   143                 debug.log("skipping offered closed or closing connection: %s", c);
   144             return false;
   144             return false;
   145         }
   145         }
   146 
   146 
   147         String key = c.key();
   147         String key = c.key();
   148         synchronized(this) {
   148         synchronized(this) {
   149             Http2Connection c1 = connections.putIfAbsent(key, c);
   149             Http2Connection c1 = connections.putIfAbsent(key, c);
   150             if (c1 != null) {
   150             if (c1 != null) {
   151                 c.setSingleStream(true);
   151                 c.setFinalStream();
   152                 if (debug.on())
   152                 if (debug.on())
   153                     debug.log("existing entry in connection pool for %s", key);
   153                     debug.log("existing entry in connection pool for %s", key);
   154                 return false;
   154                 return false;
   155             }
   155             }
   156             if (debug.on())
   156             if (debug.on())
   161 
   161 
   162     void deleteConnection(Http2Connection c) {
   162     void deleteConnection(Http2Connection c) {
   163         if (debug.on())
   163         if (debug.on())
   164             debug.log("removing from the connection pool: %s", c);
   164             debug.log("removing from the connection pool: %s", c);
   165         synchronized (this) {
   165         synchronized (this) {
   166             connections.remove(c.key());
   166             Http2Connection c1 = connections.get(c.key());
   167             if (debug.on())
   167             if (c1 != null && c1.equals(c)) {
   168                 debug.log("removed from the connection pool: %s", c);
   168                 connections.remove(c.key());
       
   169                 if (debug.on())
       
   170                     debug.log("removed from the connection pool: %s", c);
       
   171             }
   169         }
   172         }
   170     }
   173     }
   171 
   174 
   172     void stop() {
   175     void stop() {
   173         if (debug.on()) debug.log("stopping");
   176         if (debug.on()) debug.log("stopping");