1 /*
2 * Copyright (c) 1999, 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 */
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 }
|
1 /*
2 * Copyright (c) 1999, 2012, 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 */
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(int port) {
60
61 try {
62 RemoteExiter exiter =
63 (RemoteExiter)
64 Naming.lookup("rmi://localhost:" +
65 port +
66 "/RemoteExiter");
67 try {
68 exiter.exit();
69 } catch (RemoteException re) {
70 }
71 exiter = null;
72 } catch (java.net.MalformedURLException mfue) {
73 // will not happen
74 } catch (NotBoundException nbe) {
75 TestLibrary.bomb("exiter not bound?", nbe);
76 } catch (RemoteException re) {
77 TestLibrary.bomb("remote exception trying to exit",
78 re);
79 }
80 }
81
82 public static void main(String[] args) {
83 try {
84 if (args.length == 0) {
85 System.err.println("Usage: <port>");
86 System.exit(0);
87 }
88 int port = -1;
89 try {
90 port = Integer.parseInt(args[0]);
91 } catch (NumberFormatException nfe) {
92 }
93
94 // create a registry
95 registry = LocateRegistry.createRegistry(port);
96
97 // create a remote object to tell this VM to exit
98 exiter = new RegistryRunner();
99 Naming.rebind("rmi://localhost:" + port +
100 "/RemoteExiter", exiter);
101
102 } catch (Exception e) {
103 System.err.println(e.getMessage());
104 e.printStackTrace();
105 System.exit(-1);
106 }
107 }
108 }
|