Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/rmi/registry/multipleRegistries/MultipleRegistries.java
38828 views
/*1* Copyright (c) 2003, 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/* @test24* @bug 426786425* @summary Can't run multiple registries in the same VM26* @author Ann Wollrath27*28* @library ../../testlibrary29* @build TestLibrary30* @run main/othervm/timeout=240 MultipleRegistries31*/3233import java.rmi.Remote;34import java.rmi.RemoteException;35import java.rmi.registry.LocateRegistry;36import java.rmi.registry.Registry;37import java.rmi.server.UnicastRemoteObject;3839public class MultipleRegistries implements RemoteInterface {4041private static final String NAME = "MultipleRegistries";4243public Object passObject(Object obj) {44return obj;45}4647public static void main(String[] args) throws Exception {4849RemoteInterface server = null;50RemoteInterface proxy = null;5152try {53System.err.println("export object");54server = new MultipleRegistries();55proxy =56(RemoteInterface) UnicastRemoteObject.exportObject(server, 0);5758System.err.println("proxy = " + proxy);5960System.err.println("export registries");61Registry registryImpl1 = TestLibrary.createRegistryOnUnusedPort();62int port1 = TestLibrary.getRegistryPort(registryImpl1);63Registry registryImpl2 = TestLibrary.createRegistryOnUnusedPort();64int port2 = TestLibrary.getRegistryPort(registryImpl2);65System.err.println("bind remote object in registries");66Registry registry1 = LocateRegistry.getRegistry(port1);67Registry registry2 = LocateRegistry.getRegistry(port2);6869registry1.bind(NAME, proxy);70registry2.bind(NAME, proxy);7172System.err.println("lookup remote object in registries");7374RemoteInterface remote1 = (RemoteInterface) registry1.lookup(NAME);75RemoteInterface remote2 = (RemoteInterface) registry2.lookup(NAME);7677System.err.println("invoke methods on remote objects");78remote1.passObject(remote1);79remote2.passObject(remote2);8081System.err.println("TEST PASSED");8283} finally {84if (proxy != null) {85UnicastRemoteObject.unexportObject(server, true);86}87}88}89}909192interface RemoteInterface extends Remote {93Object passObject(Object obj) throws RemoteException;94}959697