Skip to content

Commit 190e113

Browse files
committed
8364263: HttpClient: Improve encapsulation of ProxyServer
Reviewed-by: dfuchs, jpai
1 parent 166ea12 commit 190e113

File tree

1 file changed

+10
-18
lines changed

1 file changed

+10
-18
lines changed

test/jdk/java/net/httpclient/ProxyServer.java

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -40,7 +40,7 @@
4040
* Two threads are created per client connection. So, it's not
4141
* intended for large numbers of parallel connections.
4242
*/
43-
public class ProxyServer extends Thread implements Closeable {
43+
public final class ProxyServer implements Closeable {
4444

4545
// could use the test library here - Platform.isWindows(),
4646
// but it would force all tests that use ProxyServer to
@@ -97,9 +97,7 @@ public ProxyServer(Integer port,
9797
this(port, debug, null);
9898
}
9999

100-
public ProxyServer(Integer port,
101-
Boolean debug,
102-
Credentials credentials)
100+
private ProxyServer(Integer port, Boolean debug, Credentials credentials)
103101
throws IOException
104102
{
105103
this.debug = debug;
@@ -108,15 +106,8 @@ public ProxyServer(Integer port,
108106
listener.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), port));
109107
this.port = ((InetSocketAddress)listener.getLocalAddress()).getPort();
110108
this.credentials = credentials;
111-
setName("ProxyListener");
112-
setDaemon(true);
113-
connections = new CopyOnWriteArrayList<Connection>();
114-
start();
115-
}
116-
117-
public ProxyServer(String s) {
118-
credentials = null;
119109
connections = new CopyOnWriteArrayList<Connection>();
110+
Thread.ofPlatform().name("ProxyListener").daemon().start(this::run);
120111
}
121112

122113
/**
@@ -148,7 +139,7 @@ public void close() throws IOException {
148139

149140
volatile boolean done;
150141

151-
public void run() {
142+
private void run() {
152143
int id = 0;
153144
try {
154145
while (!done) {
@@ -656,10 +647,11 @@ public static void main(String[] args) throws Exception {
656647
int port = Integer.parseInt(args[0]);
657648
boolean debug = args.length > 1 && args[1].equals("-debug");
658649
System.out.println("Debugging : " + debug);
659-
ProxyServer ps = new ProxyServer(port, debug);
660-
System.out.println("Proxy server listening on port " + ps.getPort());
661-
while (true) {
662-
Thread.sleep(5000);
650+
try (ProxyServer ps = new ProxyServer(port, debug)) {
651+
System.out.println("Proxy server listening on port " + ps.getPort());
652+
while (true) {
653+
Thread.sleep(5000);
654+
}
663655
}
664656
}
665657
}

0 commit comments

Comments
 (0)