Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/rmi/testlibrary/RegistryRunner.java
47512 views
/*1* Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**/2425import java.rmi.*;26import java.rmi.registry.*;27import java.rmi.server.*;2829/**30* Class to run a registry whos VM can be told to exit remotely; using31* the rmiregistry in this fashion makes tests more robust under32* windows where Process.destroy() seems not to be 100% reliable.33*/34public class RegistryRunner extends UnicastRemoteObject35implements RemoteExiter36{37private static Registry registry = null;38private static RemoteExiter exiter = null;3940public RegistryRunner() throws RemoteException {41}4243/**44* Ask the registry to exit instead of forcing it do so; this45* works better on windows...46*/47public void exit() throws RemoteException {48// REMIND: create a thread to do this to avoid49// a remote exception?50System.err.println("received call to exit");51System.exit(0);52}5354/**55* Request that the registry process exit and handle56* related exceptions.57*/58public static void requestExit(int port) {5960try {61RemoteExiter exiter =62(RemoteExiter)63Naming.lookup("rmi://localhost:" +64port +65"/RemoteExiter");66try {67exiter.exit();68} catch (RemoteException re) {69}70exiter = null;71} catch (java.net.MalformedURLException mfue) {72// will not happen73} catch (NotBoundException nbe) {74TestLibrary.bomb("exiter not bound?", nbe);75} catch (RemoteException re) {76TestLibrary.bomb("remote exception trying to exit",77re);78}79}8081public static void main(String[] args) {82try {83if (args.length == 0) {84System.err.println("Usage: <port>");85System.exit(0);86}87int port = -1;88try {89port = Integer.parseInt(args[0]);90} catch (NumberFormatException nfe) {91}9293// create a registry94registry = LocateRegistry.createRegistry(port);9596// create a remote object to tell this VM to exit97exiter = new RegistryRunner();98Naming.rebind("rmi://localhost:" + port +99"/RemoteExiter", exiter);100101} catch (Exception e) {102System.err.println(e.getMessage());103e.printStackTrace();104System.exit(-1);105}106}107}108109110