annotate agent/src/share/classes/sun/jvm/hotspot/RMIHelper.java @ 2042:0a8e0d4345b3 hs20-b05 jdk7-b124

7010068: Update all 2010 Oracle-changed OpenJDK files to have the proper copyright dates - first pass Summary: Update the copyright to be 2010 on all changed files in OpenJDK Reviewed-by: jcoomes
author trims
date Mon, 03 Jan 2011 15:30:05 -0800
parents c18cbe5936b8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
2 * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 package sun.jvm.hotspot;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import java.io.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28 import java.net.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
29 import java.rmi.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
30 import java.rmi.registry.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
31 import sun.jvm.hotspot.debugger.DebuggerException;
a61af66fc99e Initial load
duke
parents:
diff changeset
32
a61af66fc99e Initial load
duke
parents:
diff changeset
33 public class RMIHelper {
a61af66fc99e Initial load
duke
parents:
diff changeset
34 private static final boolean startRegistry;
a61af66fc99e Initial load
duke
parents:
diff changeset
35 private static int port;
a61af66fc99e Initial load
duke
parents:
diff changeset
36 private static String serverNamePrefix;
a61af66fc99e Initial load
duke
parents:
diff changeset
37
a61af66fc99e Initial load
duke
parents:
diff changeset
38 static {
a61af66fc99e Initial load
duke
parents:
diff changeset
39 String tmp = System.getProperty("sun.jvm.hotspot.rmi.startRegistry");
a61af66fc99e Initial load
duke
parents:
diff changeset
40 if (tmp != null && tmp.equals("false")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
41 startRegistry = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
42 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
43 // by default, we attempt to start rmiregistry
a61af66fc99e Initial load
duke
parents:
diff changeset
44 startRegistry = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
45 }
a61af66fc99e Initial load
duke
parents:
diff changeset
46
a61af66fc99e Initial load
duke
parents:
diff changeset
47 port = Registry.REGISTRY_PORT;
a61af66fc99e Initial load
duke
parents:
diff changeset
48 tmp = System.getProperty("sun.jvm.hotspot.rmi.port");
a61af66fc99e Initial load
duke
parents:
diff changeset
49 if (tmp != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
50 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
51 port = Integer.parseInt(tmp);
a61af66fc99e Initial load
duke
parents:
diff changeset
52 } catch (NumberFormatException nfe) {
a61af66fc99e Initial load
duke
parents:
diff changeset
53 System.err.println("invalid port supplied, assuming default");
a61af66fc99e Initial load
duke
parents:
diff changeset
54 }
a61af66fc99e Initial load
duke
parents:
diff changeset
55 }
a61af66fc99e Initial load
duke
parents:
diff changeset
56
a61af66fc99e Initial load
duke
parents:
diff changeset
57 tmp = System.getProperty("sun.jvm.hotspot.rmi.serverNamePrefix");
a61af66fc99e Initial load
duke
parents:
diff changeset
58 serverNamePrefix = (tmp != null)? serverNamePrefix : "SARemoteDebugger";
a61af66fc99e Initial load
duke
parents:
diff changeset
59 }
a61af66fc99e Initial load
duke
parents:
diff changeset
60
a61af66fc99e Initial load
duke
parents:
diff changeset
61 public static void rebind(String uniqueID, Remote object) throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
62 String name = getName(uniqueID);
a61af66fc99e Initial load
duke
parents:
diff changeset
63 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
64 Naming.rebind(name, object);
a61af66fc99e Initial load
duke
parents:
diff changeset
65 } catch (RemoteException re) {
a61af66fc99e Initial load
duke
parents:
diff changeset
66 if (startRegistry) {
a61af66fc99e Initial load
duke
parents:
diff changeset
67 // may be the user didn't start rmiregistry, try to start it
a61af66fc99e Initial load
duke
parents:
diff changeset
68 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
69 LocateRegistry.createRegistry(port);
a61af66fc99e Initial load
duke
parents:
diff changeset
70 Naming.rebind(name, object);
a61af66fc99e Initial load
duke
parents:
diff changeset
71 } catch (Exception exp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
72 throw new DebuggerException(exp);
a61af66fc99e Initial load
duke
parents:
diff changeset
73 }
a61af66fc99e Initial load
duke
parents:
diff changeset
74 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
75 throw new DebuggerException(re);
a61af66fc99e Initial load
duke
parents:
diff changeset
76 }
a61af66fc99e Initial load
duke
parents:
diff changeset
77 } catch (Exception exp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
78 throw new DebuggerException(exp);
a61af66fc99e Initial load
duke
parents:
diff changeset
79 }
a61af66fc99e Initial load
duke
parents:
diff changeset
80 }
a61af66fc99e Initial load
duke
parents:
diff changeset
81
a61af66fc99e Initial load
duke
parents:
diff changeset
82 public static void unbind(String uniqueID) throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
83 String name = getName(uniqueID);
a61af66fc99e Initial load
duke
parents:
diff changeset
84 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
85 Naming.unbind(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
86 } catch (Exception exp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
87 throw new DebuggerException(exp);
a61af66fc99e Initial load
duke
parents:
diff changeset
88 }
a61af66fc99e Initial load
duke
parents:
diff changeset
89 }
a61af66fc99e Initial load
duke
parents:
diff changeset
90
a61af66fc99e Initial load
duke
parents:
diff changeset
91 public static Remote lookup(String debugServerID) throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
92 // debugServerID follows the pattern [unique_id@]host[:port]
a61af66fc99e Initial load
duke
parents:
diff changeset
93 // we have to transform this as //host[:port]/<serverNamePrefix>['_'<unique_id>]
a61af66fc99e Initial load
duke
parents:
diff changeset
94
a61af66fc99e Initial load
duke
parents:
diff changeset
95 int index = debugServerID.indexOf('@');
a61af66fc99e Initial load
duke
parents:
diff changeset
96 StringBuffer nameBuf = new StringBuffer("//");
a61af66fc99e Initial load
duke
parents:
diff changeset
97 String uniqueID = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
98 if (index != -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
99 nameBuf.append(debugServerID.substring(index + 1));
a61af66fc99e Initial load
duke
parents:
diff changeset
100 uniqueID = debugServerID.substring(0, index);
a61af66fc99e Initial load
duke
parents:
diff changeset
101 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
102 nameBuf.append(debugServerID);
a61af66fc99e Initial load
duke
parents:
diff changeset
103 }
a61af66fc99e Initial load
duke
parents:
diff changeset
104
a61af66fc99e Initial load
duke
parents:
diff changeset
105 nameBuf.append('/');
a61af66fc99e Initial load
duke
parents:
diff changeset
106 nameBuf.append(serverNamePrefix);
a61af66fc99e Initial load
duke
parents:
diff changeset
107 if (uniqueID != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
108 nameBuf.append('_');
a61af66fc99e Initial load
duke
parents:
diff changeset
109 nameBuf.append(uniqueID);
a61af66fc99e Initial load
duke
parents:
diff changeset
110 }
a61af66fc99e Initial load
duke
parents:
diff changeset
111
a61af66fc99e Initial load
duke
parents:
diff changeset
112 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
113 return Naming.lookup(nameBuf.toString());
a61af66fc99e Initial load
duke
parents:
diff changeset
114 } catch (Exception exp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
115 throw new DebuggerException(exp);
a61af66fc99e Initial load
duke
parents:
diff changeset
116 }
a61af66fc99e Initial load
duke
parents:
diff changeset
117 }
a61af66fc99e Initial load
duke
parents:
diff changeset
118
a61af66fc99e Initial load
duke
parents:
diff changeset
119 private static String getName(String uniqueID) {
a61af66fc99e Initial load
duke
parents:
diff changeset
120 String name = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
121 if (uniqueID != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
122 name = serverNamePrefix + "_" + uniqueID;
a61af66fc99e Initial load
duke
parents:
diff changeset
123 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
124 name = serverNamePrefix;
a61af66fc99e Initial load
duke
parents:
diff changeset
125 }
a61af66fc99e Initial load
duke
parents:
diff changeset
126 if (port != Registry.REGISTRY_PORT) {
a61af66fc99e Initial load
duke
parents:
diff changeset
127 name = "//localhost:" + port + "/" + name;
a61af66fc99e Initial load
duke
parents:
diff changeset
128 }
a61af66fc99e Initial load
duke
parents:
diff changeset
129 return name;
a61af66fc99e Initial load
duke
parents:
diff changeset
130 }
a61af66fc99e Initial load
duke
parents:
diff changeset
131 }