author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 35217 | hotspot/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/RMIHelper.java@ce4b5303a813 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
2 |
* Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved. |
1 | 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 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
25 |
package sun.jvm.hotspot; |
|
26 |
||
27 |
import java.io.*; |
|
28 |
import java.net.*; |
|
29 |
import java.rmi.*; |
|
30 |
import java.rmi.registry.*; |
|
31 |
import sun.jvm.hotspot.debugger.DebuggerException; |
|
32 |
||
33 |
public class RMIHelper { |
|
34 |
private static final boolean startRegistry; |
|
35 |
private static int port; |
|
36 |
private static String serverNamePrefix; |
|
37 |
||
38 |
static { |
|
39 |
String tmp = System.getProperty("sun.jvm.hotspot.rmi.startRegistry"); |
|
40 |
if (tmp != null && tmp.equals("false")) { |
|
41 |
startRegistry = false; |
|
42 |
} else { |
|
43 |
// by default, we attempt to start rmiregistry |
|
44 |
startRegistry = true; |
|
45 |
} |
|
46 |
||
47 |
port = Registry.REGISTRY_PORT; |
|
48 |
tmp = System.getProperty("sun.jvm.hotspot.rmi.port"); |
|
49 |
if (tmp != null) { |
|
50 |
try { |
|
51 |
port = Integer.parseInt(tmp); |
|
52 |
} catch (NumberFormatException nfe) { |
|
53 |
System.err.println("invalid port supplied, assuming default"); |
|
54 |
} |
|
55 |
} |
|
56 |
||
57 |
tmp = System.getProperty("sun.jvm.hotspot.rmi.serverNamePrefix"); |
|
58 |
serverNamePrefix = (tmp != null)? serverNamePrefix : "SARemoteDebugger"; |
|
59 |
} |
|
60 |
||
61 |
public static void rebind(String uniqueID, Remote object) throws DebuggerException { |
|
62 |
String name = getName(uniqueID); |
|
63 |
try { |
|
64 |
Naming.rebind(name, object); |
|
65 |
} catch (RemoteException re) { |
|
66 |
if (startRegistry) { |
|
67 |
// may be the user didn't start rmiregistry, try to start it |
|
68 |
try { |
|
69 |
LocateRegistry.createRegistry(port); |
|
70 |
Naming.rebind(name, object); |
|
71 |
} catch (Exception exp) { |
|
72 |
throw new DebuggerException(exp); |
|
73 |
} |
|
74 |
} else { |
|
75 |
throw new DebuggerException(re); |
|
76 |
} |
|
77 |
} catch (Exception exp) { |
|
78 |
throw new DebuggerException(exp); |
|
79 |
} |
|
80 |
} |
|
81 |
||
82 |
public static void unbind(String uniqueID) throws DebuggerException { |
|
83 |
String name = getName(uniqueID); |
|
84 |
try { |
|
85 |
Naming.unbind(name); |
|
86 |
} catch (Exception exp) { |
|
87 |
throw new DebuggerException(exp); |
|
88 |
} |
|
89 |
} |
|
90 |
||
91 |
public static Remote lookup(String debugServerID) throws DebuggerException { |
|
92 |
// debugServerID follows the pattern [unique_id@]host[:port] |
|
93 |
// we have to transform this as //host[:port]/<serverNamePrefix>['_'<unique_id>] |
|
94 |
||
95 |
int index = debugServerID.indexOf('@'); |
|
96 |
StringBuffer nameBuf = new StringBuffer("//"); |
|
97 |
String uniqueID = null; |
|
98 |
if (index != -1) { |
|
99 |
nameBuf.append(debugServerID.substring(index + 1)); |
|
100 |
uniqueID = debugServerID.substring(0, index); |
|
101 |
} else { |
|
102 |
nameBuf.append(debugServerID); |
|
103 |
} |
|
104 |
||
105 |
nameBuf.append('/'); |
|
106 |
nameBuf.append(serverNamePrefix); |
|
107 |
if (uniqueID != null) { |
|
108 |
nameBuf.append('_'); |
|
109 |
nameBuf.append(uniqueID); |
|
110 |
} |
|
111 |
||
112 |
try { |
|
113 |
return Naming.lookup(nameBuf.toString()); |
|
114 |
} catch (Exception exp) { |
|
115 |
throw new DebuggerException(exp); |
|
116 |
} |
|
117 |
} |
|
118 |
||
119 |
private static String getName(String uniqueID) { |
|
120 |
String name = null; |
|
121 |
if (uniqueID != null) { |
|
122 |
name = serverNamePrefix + "_" + uniqueID; |
|
123 |
} else { |
|
124 |
name = serverNamePrefix; |
|
125 |
} |
|
126 |
if (port != Registry.REGISTRY_PORT) { |
|
127 |
name = "//localhost:" + port + "/" + name; |
|
128 |
} |
|
129 |
return name; |
|
130 |
} |
|
131 |
} |