Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/rmi/transport/closeServerSocket/CloseServerSocket.java
41155 views
1
/*
2
* Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/* @test
25
* @bug 4457683
26
* @summary After all of the remote objects (including a registry, if
27
* applicable) that had been exported with a given
28
* RMIServerSocketFactory value (including null) have been unexported,
29
* the server socket created for the exports should be closed (so that
30
* the local port is released).
31
* @author Peter Jones
32
*
33
* @library ../../testlibrary
34
* @modules java.rmi/sun.rmi.registry
35
* java.rmi/sun.rmi.server
36
* java.rmi/sun.rmi.transport
37
* java.rmi/sun.rmi.transport.tcp
38
* @build TestLibrary
39
* @run main/othervm CloseServerSocket
40
* @key intermittent
41
*/
42
43
import java.io.IOException;
44
import java.net.BindException;
45
import java.net.ServerSocket;
46
import java.rmi.Remote;
47
import java.rmi.registry.LocateRegistry;
48
import java.rmi.registry.Registry;
49
import java.rmi.server.RMIServerSocketFactory;
50
import java.rmi.server.UnicastRemoteObject;
51
52
public class CloseServerSocket implements Remote {
53
private static final int PORT = TestLibrary.getUnusedRandomPort();
54
55
private CloseServerSocket() { }
56
57
public static void main(String[] args) throws Exception {
58
System.err.println("\nRegression test for bug 4457683\n");
59
60
verifyPortFree(PORT);
61
Registry registry = LocateRegistry.createRegistry(PORT);
62
System.err.println("- exported registry: " + registry);
63
verifyPortInUse(PORT);
64
UnicastRemoteObject.unexportObject(registry, true);
65
System.err.println("- unexported registry");
66
int tries = (int)TestLibrary.getTimeoutFactor();
67
tries = Math.max(tries, 1);
68
while (tries-- > 0) {
69
Thread.sleep(1000);
70
try {
71
verifyPortFree(PORT);
72
break;
73
} catch (IOException ignore) { }
74
}
75
if (tries < 0) {
76
throw new RuntimeException("time out after tries: " + tries);
77
}
78
79
80
/*
81
* The follow portion of this test is disabled temporarily
82
* because 4457683 was partially backed out because of
83
* 6269166; for now, only server sockets originally opened for
84
* exports on non-anonymous ports will be closed when all of
85
* the corresponding remote objects have been exported. A
86
* separate bug will be filed to represent the remainder of
87
* 4457683 for anonymous-port exports.
88
*/
89
90
// SSF ssf = new SSF();
91
// Remote impl = new CloseServerSocket();
92
// Remote stub = UnicastRemoteObject.exportObject(impl, 0, null, ssf);
93
// System.err.println("- exported object: " + stub);
94
// UnicastRemoteObject.unexportObject(impl, true);
95
// System.err.println("- unexported object");
96
// synchronized (ssf) {
97
// if (!ssf.serverSocketClosed) {
98
// throw new RuntimeException("TEST FAILED: " +
99
// "server socket not closed");
100
// }
101
// }
102
103
System.err.println("TEST PASSED");
104
}
105
106
private static void verifyPortFree(int port) throws IOException {
107
ServerSocket ss = new ServerSocket(port);
108
ss.close();
109
System.err.println("- port " + port + " is free");
110
}
111
112
private static void verifyPortInUse(int port) throws IOException {
113
try {
114
verifyPortFree(port);
115
throw new RuntimeException("port is not in use: " + port);
116
} catch (BindException e) {
117
System.err.println("- port " + port + " is in use");
118
return;
119
}
120
}
121
122
private static class SSF implements RMIServerSocketFactory {
123
boolean serverSocketClosed = false;
124
SSF() { };
125
126
public ServerSocket createServerSocket(int port) throws IOException {
127
return new SS(port);
128
}
129
130
private class SS extends ServerSocket {
131
SS(int port) throws IOException {
132
super(port);
133
System.err.println("- created server socket: " + this);
134
};
135
136
public void close() throws IOException {
137
synchronized (SSF.this) {
138
serverSocketClosed = true;
139
SSF.this.notifyAll();
140
}
141
System.err.println("- closing server socket: " + this);
142
super.close();
143
}
144
}
145
}
146
}
147
148