Path: blob/master/test/jdk/java/rmi/registry/multipleRegistries/MultipleRegistries.java
41152 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* @modules java.rmi/sun.rmi.registry30* java.rmi/sun.rmi.server31* java.rmi/sun.rmi.transport32* java.rmi/sun.rmi.transport.tcp33* @build TestLibrary34* @run main/othervm/timeout=240 MultipleRegistries35*/3637import java.rmi.Remote;38import java.rmi.RemoteException;39import java.rmi.registry.LocateRegistry;40import java.rmi.registry.Registry;41import java.rmi.server.UnicastRemoteObject;4243public class MultipleRegistries implements RemoteInterface {4445private static final String NAME = "MultipleRegistries";4647public Object passObject(Object obj) {48return obj;49}5051public static void main(String[] args) throws Exception {5253RemoteInterface server = null;54RemoteInterface proxy = null;5556try {57System.err.println("export object");58server = new MultipleRegistries();59proxy =60(RemoteInterface) UnicastRemoteObject.exportObject(server, 0);6162System.err.println("proxy = " + proxy);6364System.err.println("export registries");65Registry registryImpl1 = TestLibrary.createRegistryOnUnusedPort();66int port1 = TestLibrary.getRegistryPort(registryImpl1);67Registry registryImpl2 = TestLibrary.createRegistryOnUnusedPort();68int port2 = TestLibrary.getRegistryPort(registryImpl2);69System.err.println("bind remote object in registries");70Registry registry1 = LocateRegistry.getRegistry(port1);71Registry registry2 = LocateRegistry.getRegistry(port2);7273registry1.bind(NAME, proxy);74registry2.bind(NAME, proxy);7576System.err.println("lookup remote object in registries");7778RemoteInterface remote1 = (RemoteInterface) registry1.lookup(NAME);79RemoteInterface remote2 = (RemoteInterface) registry2.lookup(NAME);8081System.err.println("invoke methods on remote objects");82remote1.passObject(remote1);83remote2.passObject(remote2);8485System.err.println("TEST PASSED");8687} finally {88if (proxy != null) {89UnicastRemoteObject.unexportObject(server, true);90}91}92}93}949596interface RemoteInterface extends Remote {97Object passObject(Object obj) throws RemoteException;98}99100101