31 * over it. We must make it in a subprocess, and then kill the |
31 * over it. We must make it in a subprocess, and then kill the |
32 * subprocess when it has served our needs. |
32 * subprocess when it has served our needs. |
33 */ |
33 */ |
34 public class REGISTRY extends JavaVM { |
34 public class REGISTRY extends JavaVM { |
35 |
35 |
36 private static double startTimeout = 20_000 * TestLibrary.getTimeoutFactor(); |
36 private static final double START_TIMEOUT = |
|
37 20_000 * TestLibrary.getTimeoutFactor(); |
|
38 private static final String DEFAULT_RUNNER = "RegistryRunner"; |
37 |
39 |
38 private int port = -1; |
40 private int port = -1; |
39 |
41 |
40 private REGISTRY(OutputStream out, OutputStream err, |
42 private REGISTRY(String runner, OutputStream out, OutputStream err, |
41 String options, int port) { |
43 String options, int port) { |
42 super("RegistryRunner", options, Integer.toString(port), out, err); |
44 super(runner, options, Integer.toString(port), out, err); |
|
45 try { |
|
46 Class runnerClass = Class.forName(runner); |
|
47 if (!RegistryRunner.class.isAssignableFrom(runnerClass)) { |
|
48 throw new RuntimeException("runner class must be RegistryRunner" |
|
49 + " or its sub class"); |
|
50 } |
|
51 } catch (ClassNotFoundException ex) { |
|
52 throw new RuntimeException(ex); |
|
53 } |
43 this.port = port; |
54 this.port = port; |
44 } |
55 } |
45 |
56 |
46 public static REGISTRY createREGISTRY() { |
57 public static REGISTRY createREGISTRY() { |
47 return createREGISTRY(System.out, System.err, "", 0); |
58 return createREGISTRYWithRunner(DEFAULT_RUNNER, System.out, System.err, "", 0); |
48 } |
59 } |
49 |
60 |
50 public static REGISTRY createREGISTRY(OutputStream out, OutputStream err, |
61 public static REGISTRY createREGISTRY(OutputStream out, OutputStream err, |
51 String options, int port) { |
62 String options, int port) { |
|
63 return createREGISTRYWithRunner(DEFAULT_RUNNER, out, err, options, port); |
|
64 } |
|
65 |
|
66 public static REGISTRY createREGISTRYWithRunner(String runner, String options) { |
|
67 return createREGISTRYWithRunner(runner, System.out, System.err, options, 0); |
|
68 } |
|
69 |
|
70 public static REGISTRY createREGISTRYWithRunner(String runner, OutputStream out, |
|
71 OutputStream err, String options, int port) { |
52 options += " --add-exports=java.rmi/sun.rmi.registry=ALL-UNNAMED" |
72 options += " --add-exports=java.rmi/sun.rmi.registry=ALL-UNNAMED" |
53 + " --add-exports=java.rmi/sun.rmi.server=ALL-UNNAMED" |
73 + " --add-exports=java.rmi/sun.rmi.server=ALL-UNNAMED" |
54 + " --add-exports=java.rmi/sun.rmi.transport=ALL-UNNAMED" |
74 + " --add-exports=java.rmi/sun.rmi.transport=ALL-UNNAMED" |
55 + " --add-exports=java.rmi/sun.rmi.transport.tcp=ALL-UNNAMED"; |
75 + " --add-exports=java.rmi/sun.rmi.transport.tcp=ALL-UNNAMED"; |
56 REGISTRY reg = new REGISTRY(out, err, options, port); |
76 REGISTRY reg = new REGISTRY(runner, out, err, options, port); |
57 return reg; |
77 return reg; |
58 } |
78 } |
59 |
79 |
60 /** |
80 /** |
61 * Starts the registry in a sub-process and waits up to |
81 * Starts the registry in a sub-process and waits up to |
62 * the given timeout period to confirm that it's running, |
82 * the given timeout period to confirm that it's running, |
63 * and get the port where it's running. |
83 * and get the port where it's running. |
64 */ |
84 */ |
65 public void start() throws IOException { |
85 public void start() throws IOException { |
66 super.start(); |
86 super.start(); |
67 long startTime = System.currentTimeMillis(); |
87 long startTime = System.currentTimeMillis(); |
68 long deadline = TestLibrary.computeDeadline(startTime, (long)startTimeout); |
88 long deadline = TestLibrary.computeDeadline(startTime, (long)START_TIMEOUT); |
69 while (true) { |
89 while (true) { |
70 try { |
90 try { |
71 Thread.sleep(1000); |
91 Thread.sleep(1000); |
72 } catch (InterruptedException ignore) { } |
92 } catch (InterruptedException ignore) { } |
73 |
93 |