2
|
1 |
/*
|
5506
|
2 |
* Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved.
|
2
|
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 |
*
|
5506
|
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.
|
2
|
22 |
*/
|
|
23 |
|
|
24 |
/**/
|
|
25 |
|
|
26 |
import java.rmi.*;
|
|
27 |
import java.rmi.registry.*;
|
|
28 |
import java.rmi.server.*;
|
|
29 |
|
|
30 |
/**
|
|
31 |
* Class to run a registry whos VM can be told to exit remotely; using
|
|
32 |
* the rmiregistry in this fashion makes tests more robust under
|
|
33 |
* windows where Process.destroy() seems not to be 100% reliable.
|
|
34 |
*/
|
|
35 |
public class RegistryRunner extends UnicastRemoteObject
|
|
36 |
implements RemoteExiter
|
|
37 |
{
|
|
38 |
private static Registry registry = null;
|
|
39 |
private static RemoteExiter exiter = null;
|
|
40 |
|
|
41 |
public RegistryRunner() throws RemoteException {
|
|
42 |
}
|
|
43 |
|
|
44 |
/**
|
|
45 |
* Ask the registry to exit instead of forcing it do so; this
|
|
46 |
* works better on windows...
|
|
47 |
*/
|
|
48 |
public void exit() throws RemoteException {
|
|
49 |
// REMIND: create a thread to do this to avoid
|
|
50 |
// a remote exception?
|
|
51 |
System.err.println("received call to exit");
|
|
52 |
System.exit(0);
|
|
53 |
}
|
|
54 |
|
|
55 |
/**
|
|
56 |
* Request that the registry process exit and handle
|
|
57 |
* related exceptions.
|
|
58 |
*/
|
|
59 |
public static void requestExit() {
|
|
60 |
try {
|
|
61 |
RemoteExiter exiter =
|
|
62 |
(RemoteExiter)
|
|
63 |
Naming.lookup("rmi://localhost:" +
|
|
64 |
TestLibrary.REGISTRY_PORT +
|
|
65 |
"/RemoteExiter");
|
|
66 |
try {
|
|
67 |
exiter.exit();
|
|
68 |
} catch (RemoteException re) {
|
|
69 |
}
|
|
70 |
exiter = null;
|
|
71 |
} catch (java.net.MalformedURLException mfue) {
|
|
72 |
// will not happen
|
|
73 |
} catch (NotBoundException nbe) {
|
|
74 |
TestLibrary.bomb("exiter not bound?", nbe);
|
|
75 |
} catch (RemoteException re) {
|
|
76 |
TestLibrary.bomb("remote exception trying to exit",
|
|
77 |
re);
|
|
78 |
}
|
|
79 |
}
|
|
80 |
|
|
81 |
public static void main(String[] args) {
|
|
82 |
try {
|
|
83 |
if (args.length == 0) {
|
|
84 |
System.err.println("Usage: <port>");
|
|
85 |
System.exit(0);
|
|
86 |
}
|
|
87 |
int port = TestLibrary.REGISTRY_PORT;
|
|
88 |
try {
|
|
89 |
port = Integer.parseInt(args[0]);
|
|
90 |
} catch (NumberFormatException nfe) {
|
|
91 |
}
|
|
92 |
|
|
93 |
// create a registry
|
|
94 |
registry = LocateRegistry.createRegistry(port);
|
|
95 |
|
|
96 |
// create a remote object to tell this VM to exit
|
|
97 |
exiter = new RegistryRunner();
|
|
98 |
Naming.rebind("rmi://localhost:" + port +
|
|
99 |
"/RemoteExiter", exiter);
|
|
100 |
|
|
101 |
} catch (Exception e) {
|
|
102 |
System.err.println(e.getMessage());
|
|
103 |
e.printStackTrace();
|
|
104 |
System.exit(-1);
|
|
105 |
}
|
|
106 |
}
|
|
107 |
}
|