J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2003 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 21 | * have any 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 | * @build MultipleRegistries |
| 30 | * @run main/othervm/timeout=240 MultipleRegistries |
| 31 | */ |
| 32 | |
| 33 | import java.rmi.Remote; |
| 34 | import java.rmi.RemoteException; |
| 35 | import java.rmi.registry.LocateRegistry; |
| 36 | import java.rmi.registry.Registry; |
| 37 | import java.rmi.server.UnicastRemoteObject; |
| 38 | |
| 39 | public class MultipleRegistries implements RemoteInterface { |
| 40 | |
| 41 | private static final String NAME = "MultipleRegistries"; |
| 42 | |
| 43 | public Object passObject(Object obj) { |
| 44 | return obj; |
| 45 | } |
| 46 | |
| 47 | public static void main(String[] args) throws Exception { |
| 48 | |
| 49 | RemoteInterface server = null; |
| 50 | RemoteInterface proxy = null; |
| 51 | |
| 52 | try { |
| 53 | System.err.println("export object"); |
| 54 | server = new MultipleRegistries(); |
| 55 | proxy = |
| 56 | (RemoteInterface) UnicastRemoteObject.exportObject(server, 0); |
| 57 | |
| 58 | System.err.println("proxy = " + proxy); |
| 59 | |
| 60 | System.err.println("export registries"); |
| 61 | Registry registryImpl1 = LocateRegistry.createRegistry(2030); |
| 62 | Registry registryImpl2 = LocateRegistry.createRegistry(2040); |
| 63 | |
| 64 | System.err.println("bind remote object in registries"); |
| 65 | Registry registry1 = LocateRegistry.getRegistry(2030); |
| 66 | Registry registry2 = LocateRegistry.getRegistry(2040); |
| 67 | |
| 68 | registry1.bind(NAME, proxy); |
| 69 | registry2.bind(NAME, proxy); |
| 70 | |
| 71 | System.err.println("lookup remote object in registries"); |
| 72 | |
| 73 | RemoteInterface remote1 = (RemoteInterface) registry1.lookup(NAME); |
| 74 | RemoteInterface remote2 = (RemoteInterface) registry2.lookup(NAME); |
| 75 | |
| 76 | System.err.println("invoke methods on remote objects"); |
| 77 | remote1.passObject(remote1); |
| 78 | remote2.passObject(remote2); |
| 79 | |
| 80 | System.err.println("TEST PASSED"); |
| 81 | |
| 82 | } finally { |
| 83 | if (proxy != null) { |
| 84 | UnicastRemoteObject.unexportObject(server, true); |
| 85 | } |
| 86 | } |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | |
| 91 | interface RemoteInterface extends Remote { |
| 92 | Object passObject(Object obj) throws RemoteException; |
| 93 | } |