Path: blob/master/test/jdk/java/rmi/testlibrary/RMIRegistryRunner.java
41149 views
/*1* Copyright (c) 2017, 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 rmiregistry whose VM can be told to exit remotely;31* Difference between this class and RegistryRunner is that this class32* simulate rmiregistry closer than RegistryRunner.33*/34public class RMIRegistryRunner extends RegistryRunner35{36public RMIRegistryRunner() throws RemoteException {37}3839/**40* port 0 means to use ephemeral port to start registry.41*42* @param args command line arguments passed in from main43* @return the port number on which registry accepts requests44*/45protected static int init(String[] args) {46try {47if (args.length == 0) {48System.err.println("Usage: <port>");49System.exit(0);50}51int port = -1;52port = Integer.parseInt(args[0]);5354// call RegistryImpl.createRegistry to simulate rmiregistry.55registry = sun.rmi.registry.RegistryImpl.createRegistry(port);56if (port == 0) {57port = TestLibrary.getRegistryPort(registry);58}5960// create a remote object to tell this VM to exit61exiter = new RMIRegistryRunner();62Naming.rebind("rmi://localhost:" + port +63"/RemoteExiter", exiter);6465return port;66} catch (Exception e) {67System.err.println(e.getMessage());68e.printStackTrace();69System.exit(1);70}71return -1;72}7374public static void main(String[] args) {75int port = init(args);76notify(port);77}78}798081