author | michaelm |
Tue, 16 Jan 2018 15:52:01 +0000 | |
branch | http-client-branch |
changeset 56010 | 782b2f2d1e76 |
parent 55973 | 4d9b002587db |
permissions | -rw-r--r-- |
47116
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
1 |
/* |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
2 |
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
4 |
* |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
8 |
* |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
13 |
* accompanied this code). |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
14 |
* |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
18 |
* |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
21 |
* questions. |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
22 |
*/ |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
23 |
|
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
24 |
package jdk.incubator.http; |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
25 |
|
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
26 |
import java.io.IOException; |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
27 |
import java.lang.management.ManagementFactory; |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
28 |
import java.net.Authenticator; |
48083 | 29 |
import java.net.CookieHandler; |
47116
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
30 |
import java.net.InetSocketAddress; |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
31 |
import java.net.ProxySelector; |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
32 |
import java.nio.ByteBuffer; |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
33 |
import java.nio.channels.SocketChannel; |
48083 | 34 |
import java.util.List; |
47116
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
35 |
import java.util.Optional; |
48083 | 36 |
import java.util.Random; |
47116
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
37 |
import java.util.concurrent.CompletableFuture; |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
38 |
import java.util.concurrent.Executor; |
48083 | 39 |
import java.util.concurrent.Flow; |
40 |
import java.util.stream.IntStream; |
|
41 |
import java.time.Instant; |
|
42 |
import java.time.temporal.ChronoUnit; |
|
47116
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
43 |
import javax.net.ssl.SSLContext; |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
44 |
import javax.net.ssl.SSLParameters; |
48083 | 45 |
import jdk.incubator.http.internal.common.FlowTube; |
47116
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
46 |
|
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
47 |
/** |
48083 | 48 |
* @summary Verifies that the ConnectionPool correctly handle |
49 |
* connection deadlines and purges the right connections |
|
50 |
* from the cache. |
|
51 |
* @bug 8187044 8187111 |
|
47116
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
52 |
* @author danielfuchs |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
53 |
*/ |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
54 |
public class ConnectionPoolTest { |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
55 |
|
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
56 |
static long getActiveCleaners() throws ClassNotFoundException { |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
57 |
// ConnectionPool.ACTIVE_CLEANER_COUNTER.get() |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
58 |
// ConnectionPoolTest.class.getModule().addReads( |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
59 |
// Class.forName("java.lang.management.ManagementFactory").getModule()); |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
60 |
return java.util.stream.Stream.of(ManagementFactory.getThreadMXBean() |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
61 |
.dumpAllThreads(false, false)) |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
62 |
.filter(t -> t.getThreadName().startsWith("HTTP-Cache-cleaner")) |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
63 |
.count(); |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
64 |
} |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
65 |
|
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
66 |
public static void main(String[] args) throws Exception { |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
67 |
testCacheCleaners(); |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
68 |
} |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
69 |
|
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
70 |
public static void testCacheCleaners() throws Exception { |
48083 | 71 |
ConnectionPool pool = new ConnectionPool(666); |
47116
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
72 |
HttpClient client = new HttpClientStub(pool); |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
73 |
InetSocketAddress proxy = InetSocketAddress.createUnresolved("bar", 80); |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
74 |
System.out.println("Adding 10 connections to pool"); |
48083 | 75 |
Random random = new Random(); |
76 |
||
77 |
final int count = 20; |
|
78 |
Instant now = Instant.now().truncatedTo(ChronoUnit.SECONDS); |
|
79 |
int[] keepAlives = new int[count]; |
|
80 |
HttpConnectionStub[] connections = new HttpConnectionStub[count]; |
|
81 |
long purge = pool.purgeExpiredConnectionsAndReturnNextDeadline(now); |
|
82 |
long expected = 0; |
|
83 |
if (purge != expected) { |
|
84 |
throw new RuntimeException("Bad purge delay: " + purge |
|
85 |
+ ", expected " + expected); |
|
47116
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
86 |
} |
48083 | 87 |
expected = Long.MAX_VALUE; |
88 |
for (int i=0; i<count; i++) { |
|
47116
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
89 |
InetSocketAddress addr = InetSocketAddress.createUnresolved("foo"+i, 80); |
48083 | 90 |
keepAlives[i] = random.nextInt(10) * 10 + 10; |
91 |
connections[i] = new HttpConnectionStub(client, addr, proxy, true); |
|
92 |
System.out.println("Adding connection: " + now |
|
93 |
+ " keepAlive: " + keepAlives[i] |
|
94 |
+ " /" + connections[i]); |
|
95 |
pool.returnToPool(connections[i], now, keepAlives[i]); |
|
96 |
expected = Math.min(expected, keepAlives[i] * 1000); |
|
97 |
purge = pool.purgeExpiredConnectionsAndReturnNextDeadline(now); |
|
98 |
if (purge != expected) { |
|
99 |
throw new RuntimeException("Bad purge delay: " + purge |
|
100 |
+ ", expected " + expected); |
|
47116
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
101 |
} |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
102 |
} |
48083 | 103 |
int min = IntStream.of(keepAlives).min().getAsInt(); |
104 |
int max = IntStream.of(keepAlives).max().getAsInt(); |
|
105 |
int mean = (min + max)/2; |
|
106 |
System.out.println("min=" + min + ", max=" + max + ", mean=" + mean); |
|
107 |
purge = pool.purgeExpiredConnectionsAndReturnNextDeadline(now); |
|
108 |
System.out.println("first purge would be in " + purge + " ms"); |
|
109 |
if (Math.abs(purge/1000 - min) > 0) { |
|
110 |
throw new RuntimeException("expected " + min + " got " + purge/1000); |
|
47116
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
111 |
} |
48083 | 112 |
long opened = java.util.stream.Stream.of(connections) |
113 |
.filter(HttpConnectionStub::connected).count(); |
|
114 |
if (opened != count) { |
|
115 |
throw new RuntimeException("Opened: expected " |
|
116 |
+ count + " got " + opened); |
|
47116
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
117 |
} |
48083 | 118 |
purge = mean * 1000; |
119 |
System.out.println("start purging at " + purge + " ms"); |
|
120 |
Instant next = now; |
|
121 |
do { |
|
122 |
System.out.println("next purge is in " + purge + " ms"); |
|
123 |
next = next.plus(purge, ChronoUnit.MILLIS); |
|
124 |
purge = pool.purgeExpiredConnectionsAndReturnNextDeadline(next); |
|
125 |
long k = now.until(next, ChronoUnit.SECONDS); |
|
126 |
System.out.println("now is " + k + "s from start"); |
|
127 |
for (int i=0; i<count; i++) { |
|
128 |
if (connections[i].connected() != (k < keepAlives[i])) { |
|
129 |
throw new RuntimeException("Bad connection state for " |
|
130 |
+ i |
|
131 |
+ "\n\t connected=" + connections[i].connected() |
|
132 |
+ "\n\t keepAlive=" + keepAlives[i] |
|
133 |
+ "\n\t elapsed=" + k); |
|
134 |
} |
|
135 |
} |
|
136 |
} while (purge > 0); |
|
137 |
opened = java.util.stream.Stream.of(connections) |
|
138 |
.filter(HttpConnectionStub::connected).count(); |
|
139 |
if (opened != 0) { |
|
140 |
throw new RuntimeException("Closed: expected " |
|
141 |
+ count + " got " |
|
142 |
+ (count-opened)); |
|
47116
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
143 |
} |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
144 |
} |
48083 | 145 |
|
47116
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
146 |
static <T> T error() { |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
147 |
throw new InternalError("Should not reach here: wrong test assumptions!"); |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
148 |
} |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
149 |
|
48083 | 150 |
static class FlowTubeStub implements FlowTube { |
151 |
final HttpConnectionStub conn; |
|
152 |
FlowTubeStub(HttpConnectionStub conn) { this.conn = conn; } |
|
153 |
@Override |
|
154 |
public void onSubscribe(Flow.Subscription subscription) { } |
|
155 |
@Override public void onError(Throwable error) { error(); } |
|
156 |
@Override public void onComplete() { error(); } |
|
157 |
@Override public void onNext(List<ByteBuffer> item) { error();} |
|
158 |
@Override |
|
159 |
public void subscribe(Flow.Subscriber<? super List<ByteBuffer>> subscriber) { |
|
160 |
} |
|
161 |
@Override public boolean isFinished() { return conn.closed; } |
|
162 |
} |
|
163 |
||
47116
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
164 |
// Emulates an HttpConnection that has a strong reference to its HttpClient. |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
165 |
static class HttpConnectionStub extends HttpConnection { |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
166 |
|
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
167 |
public HttpConnectionStub(HttpClient client, |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
168 |
InetSocketAddress address, |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
169 |
InetSocketAddress proxy, |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
170 |
boolean secured) { |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
171 |
super(address, null); |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
172 |
this.key = ConnectionPool.cacheKey(address, proxy); |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
173 |
this.address = address; |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
174 |
this.proxy = proxy; |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
175 |
this.secured = secured; |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
176 |
this.client = client; |
48083 | 177 |
this.flow = new FlowTubeStub(this); |
47116
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
178 |
} |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
179 |
|
48083 | 180 |
final InetSocketAddress proxy; |
181 |
final InetSocketAddress address; |
|
182 |
final boolean secured; |
|
183 |
final ConnectionPool.CacheKey key; |
|
184 |
final HttpClient client; |
|
185 |
final FlowTubeStub flow; |
|
186 |
volatile boolean closed; |
|
47116
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
187 |
|
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
188 |
// All these return something |
48083 | 189 |
@Override boolean connected() {return !closed;} |
47116
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
190 |
@Override boolean isSecure() {return secured;} |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
191 |
@Override boolean isProxied() {return proxy!=null;} |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
192 |
@Override ConnectionPool.CacheKey cacheKey() {return key;} |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
193 |
@Override void shutdownInput() throws IOException {} |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
194 |
@Override void shutdownOutput() throws IOException {} |
48083 | 195 |
@Override |
196 |
public void close() { |
|
197 |
closed=true; |
|
198 |
System.out.println("closed: " + this); |
|
199 |
} |
|
200 |
@Override |
|
47116
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
201 |
public String toString() { |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
202 |
return "HttpConnectionStub: " + address + " proxy: " + proxy; |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
203 |
} |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
204 |
|
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
205 |
// All these throw errors |
48083 | 206 |
@Override public HttpPublisher publisher() {return error();} |
47116
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
207 |
@Override public CompletableFuture<Void> connectAsync() {return error();} |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
208 |
@Override SocketChannel channel() {return error();} |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
209 |
@Override |
48083 | 210 |
HttpConnection.DetachedConnectionChannel detachChannel() { |
211 |
return error(); |
|
47116
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
212 |
} |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
213 |
@Override |
48083 | 214 |
FlowTube getConnectionFlow() {return flow;} |
47116
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
215 |
} |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
216 |
// Emulates an HttpClient that has a strong reference to its connection pool. |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
217 |
static class HttpClientStub extends HttpClient { |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
218 |
public HttpClientStub(ConnectionPool pool) { |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
219 |
this.pool = pool; |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
220 |
} |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
221 |
final ConnectionPool pool; |
48083 | 222 |
@Override public Optional<CookieHandler> cookieHandler() {return error();} |
47116
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
223 |
@Override public HttpClient.Redirect followRedirects() {return error();} |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
224 |
@Override public Optional<ProxySelector> proxy() {return error();} |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
225 |
@Override public SSLContext sslContext() {return error();} |
48083 | 226 |
@Override public SSLParameters sslParameters() {return error();} |
47116
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
227 |
@Override public Optional<Authenticator> authenticator() {return error();} |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
228 |
@Override public HttpClient.Version version() {return HttpClient.Version.HTTP_1_1;} |
48083 | 229 |
@Override public Optional<Executor> executor() {return error();} |
47116
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
230 |
@Override |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
231 |
public <T> HttpResponse<T> send(HttpRequest req, |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
232 |
HttpResponse.BodyHandler<T> responseBodyHandler) |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
233 |
throws IOException, InterruptedException { |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
234 |
return error(); |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
235 |
} |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
236 |
@Override |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
237 |
public <T> CompletableFuture<HttpResponse<T>> sendAsync(HttpRequest req, |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
238 |
HttpResponse.BodyHandler<T> responseBodyHandler) { |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
239 |
return error(); |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
240 |
} |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
241 |
@Override |
56010 | 242 |
public <T> CompletableFuture<HttpResponse<T>> sendAsync(HttpRequest req, |
243 |
HttpResponse.BodyHandler<T> bodyHandler, |
|
244 |
HttpResponse.PushPromiseHandler<T> multiHandler) { |
|
47116
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
245 |
return error(); |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
246 |
} |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
247 |
} |
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
248 |
|
6160b308ed24
8187044: HttpClient ConnectionPool may spawn several concurrent CacheCleaner and prevent early GC of HttpClient.
dfuchs
parents:
diff
changeset
|
249 |
} |