author | mli |
Mon, 19 Dec 2016 17:09:10 -0800 | |
changeset 42775 | a45fa7082c81 |
child 42918 | 038d77430a46 |
permissions | -rw-r--r-- |
42775
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
1 |
/* |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
2 |
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
4 |
* |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
8 |
* |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
13 |
* accompanied this code). |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
14 |
* |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
18 |
* |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
21 |
* questions. |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
22 |
*/ |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
23 |
|
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
24 |
import java.io.OutputStream; |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
25 |
import java.io.IOException; |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
26 |
|
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
27 |
/** |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
28 |
* Class to run and control rmiregistry in a sub-process. |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
29 |
* |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
30 |
* We can't kill a registry if we have too-close control |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
31 |
* over it. We must make it in a subprocess, and then kill the |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
32 |
* subprocess when it has served our needs. |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
33 |
*/ |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
34 |
public class REGISTRY extends JavaVM { |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
35 |
|
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
36 |
private static double startTimeout = 20_000 * TestLibrary.getTimeoutFactor(); |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
37 |
|
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
38 |
private int port = -1; |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
39 |
|
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
40 |
private REGISTRY(OutputStream out, OutputStream err, |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
41 |
String options, int port) { |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
42 |
super("RegistryRunner", options, Integer.toString(port), out, err); |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
43 |
this.port = port; |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
44 |
} |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
45 |
|
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
46 |
public static REGISTRY createREGISTRY() { |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
47 |
return createREGISTRY(System.out, System.err, "", 0); |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
48 |
} |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
49 |
|
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
50 |
public static REGISTRY createREGISTRY(OutputStream out, OutputStream err, |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
51 |
String options, int port) { |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
52 |
options += " --add-exports=java.rmi/sun.rmi.registry=ALL-UNNAMED" |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
53 |
+ " --add-exports=java.rmi/sun.rmi.server=ALL-UNNAMED" |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
54 |
+ " --add-exports=java.rmi/sun.rmi.transport=ALL-UNNAMED" |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
55 |
+ " --add-exports=java.rmi/sun.rmi.transport.tcp=ALL-UNNAMED"; |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
56 |
REGISTRY reg = new REGISTRY(out, err, options, port); |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
57 |
return reg; |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
58 |
} |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
59 |
|
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
60 |
/** |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
61 |
* Starts the registry in a sub-process and waits up to |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
62 |
* the given timeout period to confirm that it's running, |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
63 |
* and get the port where it's running. |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
64 |
*/ |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
65 |
public void start() throws IOException { |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
66 |
super.start(); |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
67 |
long startTime = System.currentTimeMillis(); |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
68 |
long deadline = TestLibrary.computeDeadline(startTime, (long)startTimeout); |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
69 |
while (true) { |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
70 |
try { |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
71 |
Thread.sleep(1000); |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
72 |
} catch (InterruptedException ignore) { } |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
73 |
|
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
74 |
String output = outputStream.ba.toString(); |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
75 |
port = RegistryRunner.getRegistryPort(output); |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
76 |
if (port != -1) { |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
77 |
break; |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
78 |
} |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
79 |
if (System.currentTimeMillis() > deadline) { |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
80 |
TestLibrary.bomb("Failed to start registry, giving up after " + |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
81 |
(System.currentTimeMillis() - startTime) + "ms.", null); |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
82 |
} |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
83 |
} |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
84 |
} |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
85 |
|
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
86 |
/** |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
87 |
* Shuts down the registry. |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
88 |
*/ |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
89 |
public void shutdown() { |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
90 |
RegistryRunner.requestExit(port); |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
91 |
} |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
92 |
|
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
93 |
/** |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
94 |
* Gets the port where the registry is serving. |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
95 |
*/ |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
96 |
public int getPort() { |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
97 |
return port; |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
98 |
} |
a45fa7082c81
8025199: java/rmi/registry/reexport/Reexport.java failed with: Port already in use
mli
parents:
diff
changeset
|
99 |
} |