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