1 /* 2 * Copyright (c) 2003, 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 */ 23 24 /* @test 25 * @bug 4267864 26 * @summary Can't run multiple registries in the same VM 27 * @author Ann Wollrath 28 * 29 * @library ../../testlibrary 30 * @build TestLibrary 31 * @run main/othervm/timeout=240 MultipleRegistries 32 */ 33 34 import java.rmi.Remote; 35 import java.rmi.RemoteException; 36 import java.rmi.registry.LocateRegistry; 37 import java.rmi.registry.Registry; 38 import java.rmi.server.UnicastRemoteObject; 39 40 public class MultipleRegistries implements RemoteInterface { 41 42 private static final String NAME = "MultipleRegistries"; 43 44 public Object passObject(Object obj) { 45 return obj; 46 } 47 48 public static void main(String[] args) throws Exception { 49 50 RemoteInterface server = null; 51 RemoteInterface proxy = null; 52 53 try { 54 System.err.println("export object"); 55 server = new MultipleRegistries(); 56 proxy = 57 (RemoteInterface) UnicastRemoteObject.exportObject(server, 0); 58 59 System.err.println("proxy = " + proxy); 60 61 System.err.println("export registries"); 62 Registry registryImpl1 = TestLibrary.createRegistryOnUnusedPort(); 63 int port1 = TestLibrary.getRegistryPort(registryImpl1); 64 Registry registryImpl2 = TestLibrary.createRegistryOnUnusedPort(); 65 int port2 = TestLibrary.getRegistryPort(registryImpl2); 66 System.err.println("bind remote object in registries"); 67 Registry registry1 = LocateRegistry.getRegistry(port1); 68 Registry registry2 = LocateRegistry.getRegistry(port2); 69 70 registry1.bind(NAME, proxy); 71 registry2.bind(NAME, proxy); 72 73 System.err.println("lookup remote object in registries"); 74 75 RemoteInterface remote1 = (RemoteInterface) registry1.lookup(NAME); 76 RemoteInterface remote2 = (RemoteInterface) registry2.lookup(NAME); 77 78 System.err.println("invoke methods on remote objects"); 79 remote1.passObject(remote1); 80 remote2.passObject(remote2); 81 82 System.err.println("TEST PASSED"); 83 84 } finally { 85 if (proxy != null) { 86 UnicastRemoteObject.unexportObject(server, true); 87 } 88 } 89 } 90 } 91 92 93 interface RemoteInterface extends Remote { 94 Object passObject(Object obj) throws RemoteException; 95 }