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