src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/Http2ClientImpl.java
equal
deleted
inserted
replaced
91 * connection, or when waiting for connection to be opened. |
91 * connection, or when waiting for connection to be opened. |
92 * First thread opens the connection and notifies the others when done. |
92 * First thread opens the connection and notifies the others when done. |
93 * |
93 * |
94 * If the request is secure (https) then we open the connection here. |
94 * If the request is secure (https) then we open the connection here. |
95 * If not, then the more complicated upgrade from 1.1 to 2 happens (not here) |
95 * If not, then the more complicated upgrade from 1.1 to 2 happens (not here) |
96 * In latter case, when the Http2Connection is connected, putConnection() must |
96 * In latter case, when the Http2Connection is connected, offerConnection() must |
97 * be called to store it. |
97 * be called to store it. |
98 */ |
98 */ |
99 CompletableFuture<Http2Connection> getConnectionFor(HttpRequestImpl req) { |
99 CompletableFuture<Http2Connection> getConnectionFor(HttpRequestImpl req) { |
100 URI uri = req.uri(); |
100 URI uri = req.uri(); |
101 InetSocketAddress proxy = req.proxy(); |
101 InetSocketAddress proxy = req.proxy(); |
128 synchronized (opening) { |
128 synchronized (opening) { |
129 Set<CompletableFuture<Http2Connection>> waiters = waiting.remove(key); |
129 Set<CompletableFuture<Http2Connection>> waiters = waiting.remove(key); |
130 debug.log(Level.DEBUG, "Opening completed: %s", key); |
130 debug.log(Level.DEBUG, "Opening completed: %s", key); |
131 opening.remove(key); |
131 opening.remove(key); |
132 if (t == null && conn != null) |
132 if (t == null && conn != null) |
133 putConnection(conn); |
133 offerConnection(conn); |
134 final Throwable cause = Utils.getCompletionCause(t); |
134 final Throwable cause = Utils.getCompletionCause(t); |
135 if (waiters == null) { |
135 if (waiters == null) { |
136 debug.log(Level.DEBUG, "no dependent to wake up"); |
136 debug.log(Level.DEBUG, "no dependent to wake up"); |
137 return; |
137 return; |
138 } else if (cause instanceof Http2Connection.ALPNException) { |
138 } else if (cause instanceof Http2Connection.ALPNException) { |
150 } |
150 } |
151 }); |
151 }); |
152 } |
152 } |
153 |
153 |
154 /* |
154 /* |
155 * TODO: If there isn't a connection to the same destination, then |
155 * Cache the given connection, if no connection to the same |
156 * store it. If there is already a connection, then close it |
156 * destination exists. If one exists, then we let the initial stream |
|
157 * complete but allow it to close itself upon completion. |
|
158 * This situation should not arise with https because the request |
|
159 * has not been sent as part of the initial alpn negotiation |
157 */ |
160 */ |
158 void putConnection(Http2Connection c) { |
161 boolean offerConnection(Http2Connection c) { |
159 connections.put(c.key(), c); |
162 String key = c.key(); |
|
163 Http2Connection c1 = connections.putIfAbsent(key, c); |
|
164 return c1 == null; |
160 } |
165 } |
161 |
166 |
162 void deleteConnection(Http2Connection c) { |
167 void deleteConnection(Http2Connection c) { |
163 connections.remove(c.key()); |
168 connections.remove(c.key()); |
164 } |
169 } |