author | alanb |
Fri, 10 Feb 2017 09:04:39 +0000 | |
changeset 43712 | 5dfd0950317c |
parent 43503 | bc7f8619ab70 |
child 44545 | 83b611b88ac8 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
40742
3697a4ff4721
8164730: Make it clear that 'cl' parameter passed to RMIConnector.OISWL is never null.
vtewari
parents:
36511
diff
changeset
|
2 |
* Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package javax.management.remote.rmi; |
|
27 |
||
28 |
import com.sun.jmx.remote.internal.ClientCommunicatorAdmin; |
|
29 |
import com.sun.jmx.remote.internal.ClientListenerInfo; |
|
30 |
import com.sun.jmx.remote.internal.ClientNotifForwarder; |
|
43503
bc7f8619ab70
8173607: JMX RMI connector should be in its own module
dfuchs
parents:
40742
diff
changeset
|
31 |
import com.sun.jmx.remote.internal.rmi.ProxyRef; |
2 | 32 |
import com.sun.jmx.remote.util.ClassLogger; |
33 |
import com.sun.jmx.remote.util.EnvHelp; |
|
34 |
import java.io.ByteArrayInputStream; |
|
35 |
import java.io.IOException; |
|
36 |
import java.io.InputStream; |
|
37 |
import java.io.InvalidObjectException; |
|
38 |
import java.io.ObjectInputStream; |
|
39 |
import java.io.ObjectStreamClass; |
|
40 |
import java.io.Serializable; |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
43503
diff
changeset
|
41 |
import java.lang.module.ModuleDescriptor; |
2 | 42 |
import java.lang.ref.WeakReference; |
43 |
import java.lang.reflect.Constructor; |
|
44 |
import java.lang.reflect.InvocationHandler; |
|
45 |
import java.lang.reflect.InvocationTargetException; |
|
36511 | 46 |
import java.lang.reflect.Module; |
2 | 47 |
import java.lang.reflect.Proxy; |
48 |
import java.net.MalformedURLException; |
|
49 |
import java.rmi.MarshalledObject; |
|
50 |
import java.rmi.NoSuchObjectException; |
|
51 |
import java.rmi.Remote; |
|
52 |
import java.rmi.ServerException; |
|
53 |
import java.rmi.UnmarshalException; |
|
54 |
import java.rmi.server.RMIClientSocketFactory; |
|
55 |
import java.rmi.server.RemoteObject; |
|
56 |
import java.rmi.server.RemoteObjectInvocationHandler; |
|
57 |
import java.rmi.server.RemoteRef; |
|
58 |
import java.security.AccessController; |
|
59 |
import java.security.PrivilegedAction; |
|
60 |
import java.security.PrivilegedExceptionAction; |
|
61 |
import java.security.ProtectionDomain; |
|
62 |
import java.util.Arrays; |
|
63 |
import java.util.Collections; |
|
64 |
import java.util.HashMap; |
|
32639
339de1317e84
8043937: Drop support for the IIOP transport from the JMX RMIConnector
jbachorik
parents:
32034
diff
changeset
|
65 |
import java.util.Hashtable; |
2 | 66 |
import java.util.Map; |
40742
3697a4ff4721
8164730: Make it clear that 'cl' parameter passed to RMIConnector.OISWL is never null.
vtewari
parents:
36511
diff
changeset
|
67 |
import java.util.Objects; |
2 | 68 |
import java.util.Set; |
69 |
import java.util.WeakHashMap; |
|
35282 | 70 |
import java.util.stream.Collectors; |
2 | 71 |
import javax.management.Attribute; |
72 |
import javax.management.AttributeList; |
|
73 |
import javax.management.AttributeNotFoundException; |
|
74 |
import javax.management.InstanceAlreadyExistsException; |
|
75 |
import javax.management.InstanceNotFoundException; |
|
76 |
import javax.management.IntrospectionException; |
|
77 |
import javax.management.InvalidAttributeValueException; |
|
78 |
import javax.management.ListenerNotFoundException; |
|
79 |
import javax.management.MBeanException; |
|
80 |
import javax.management.MBeanInfo; |
|
81 |
import javax.management.MBeanRegistrationException; |
|
82 |
import javax.management.MBeanServerConnection; |
|
83 |
import javax.management.MBeanServerDelegate; |
|
84 |
import javax.management.MBeanServerNotification; |
|
85 |
import javax.management.NotCompliantMBeanException; |
|
86 |
import javax.management.Notification; |
|
87 |
import javax.management.NotificationBroadcasterSupport; |
|
88 |
import javax.management.NotificationFilter; |
|
89 |
import javax.management.NotificationFilterSupport; |
|
90 |
import javax.management.NotificationListener; |
|
91 |
import javax.management.ObjectInstance; |
|
92 |
import javax.management.ObjectName; |
|
93 |
import javax.management.QueryExp; |
|
94 |
import javax.management.ReflectionException; |
|
95 |
import javax.management.remote.JMXConnectionNotification; |
|
96 |
import javax.management.remote.JMXConnector; |
|
97 |
import javax.management.remote.JMXConnectorFactory; |
|
98 |
import javax.management.remote.JMXServiceURL; |
|
99 |
import javax.management.remote.NotificationResult; |
|
100 |
import javax.management.remote.JMXAddressable; |
|
101 |
import javax.naming.InitialContext; |
|
102 |
import javax.naming.NamingException; |
|
103 |
import javax.rmi.ssl.SslRMIClientSocketFactory; |
|
104 |
import javax.security.auth.Subject; |
|
36511 | 105 |
import jdk.internal.module.Modules; |
18206 | 106 |
import sun.reflect.misc.ReflectUtil; |
2 | 107 |
import sun.rmi.server.UnicastRef2; |
108 |
import sun.rmi.transport.LiveRef; |
|
43503
bc7f8619ab70
8173607: JMX RMI connector should be in its own module
dfuchs
parents:
40742
diff
changeset
|
109 |
import java.io.NotSerializableException; |
2 | 110 |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
43503
diff
changeset
|
111 |
import static java.lang.module.ModuleDescriptor.Modifier.SYNTHETIC; |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
43503
diff
changeset
|
112 |
|
2 | 113 |
/** |
114 |
* <p>A connection to a remote RMI connector. Usually, such |
|
115 |
* connections are made using {@link |
|
116 |
* javax.management.remote.JMXConnectorFactory JMXConnectorFactory}. |
|
117 |
* However, specialized applications can use this class directly, for |
|
118 |
* example with an {@link RMIServer} stub obtained without going |
|
119 |
* through JNDI.</p> |
|
120 |
* |
|
121 |
* @since 1.5 |
|
122 |
*/ |
|
123 |
public class RMIConnector implements JMXConnector, Serializable, JMXAddressable { |
|
124 |
||
125 |
private static final ClassLogger logger = |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
126 |
new ClassLogger("javax.management.remote.rmi", "RMIConnector"); |
2 | 127 |
|
128 |
private static final long serialVersionUID = 817323035842634473L; |
|
129 |
||
43503
bc7f8619ab70
8173607: JMX RMI connector should be in its own module
dfuchs
parents:
40742
diff
changeset
|
130 |
static final class Util { |
bc7f8619ab70
8173607: JMX RMI connector should be in its own module
dfuchs
parents:
40742
diff
changeset
|
131 |
private Util() {} |
bc7f8619ab70
8173607: JMX RMI connector should be in its own module
dfuchs
parents:
40742
diff
changeset
|
132 |
|
bc7f8619ab70
8173607: JMX RMI connector should be in its own module
dfuchs
parents:
40742
diff
changeset
|
133 |
/* This method can be used by code that is deliberately violating the |
bc7f8619ab70
8173607: JMX RMI connector should be in its own module
dfuchs
parents:
40742
diff
changeset
|
134 |
* allowed checked casts. Rather than marking the whole method containing |
bc7f8619ab70
8173607: JMX RMI connector should be in its own module
dfuchs
parents:
40742
diff
changeset
|
135 |
* the code with @SuppressWarnings, you can use a call to this method for |
bc7f8619ab70
8173607: JMX RMI connector should be in its own module
dfuchs
parents:
40742
diff
changeset
|
136 |
* the exact place where you need to escape the constraints. Typically |
bc7f8619ab70
8173607: JMX RMI connector should be in its own module
dfuchs
parents:
40742
diff
changeset
|
137 |
* you will "import static" this method and then write either |
bc7f8619ab70
8173607: JMX RMI connector should be in its own module
dfuchs
parents:
40742
diff
changeset
|
138 |
* X x = cast(y); |
bc7f8619ab70
8173607: JMX RMI connector should be in its own module
dfuchs
parents:
40742
diff
changeset
|
139 |
* or, if that doesn't work (e.g. X is a type variable) |
bc7f8619ab70
8173607: JMX RMI connector should be in its own module
dfuchs
parents:
40742
diff
changeset
|
140 |
* Util.<X>cast(y); |
bc7f8619ab70
8173607: JMX RMI connector should be in its own module
dfuchs
parents:
40742
diff
changeset
|
141 |
*/ |
bc7f8619ab70
8173607: JMX RMI connector should be in its own module
dfuchs
parents:
40742
diff
changeset
|
142 |
@SuppressWarnings("unchecked") |
bc7f8619ab70
8173607: JMX RMI connector should be in its own module
dfuchs
parents:
40742
diff
changeset
|
143 |
public static <T> T cast(Object x) { |
bc7f8619ab70
8173607: JMX RMI connector should be in its own module
dfuchs
parents:
40742
diff
changeset
|
144 |
return (T) x; |
bc7f8619ab70
8173607: JMX RMI connector should be in its own module
dfuchs
parents:
40742
diff
changeset
|
145 |
} |
bc7f8619ab70
8173607: JMX RMI connector should be in its own module
dfuchs
parents:
40742
diff
changeset
|
146 |
} |
bc7f8619ab70
8173607: JMX RMI connector should be in its own module
dfuchs
parents:
40742
diff
changeset
|
147 |
|
2 | 148 |
private RMIConnector(RMIServer rmiServer, JMXServiceURL address, |
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
149 |
Map<String, ?> environment) { |
2 | 150 |
if (rmiServer == null && address == null) throw new |
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
151 |
IllegalArgumentException("rmiServer and jmxServiceURL both null"); |
2 | 152 |
initTransients(); |
153 |
||
154 |
this.rmiServer = rmiServer; |
|
155 |
this.jmxServiceURL = address; |
|
156 |
if (environment == null) { |
|
157 |
this.env = Collections.emptyMap(); |
|
158 |
} else { |
|
159 |
EnvHelp.checkAttributes(environment); |
|
160 |
this.env = Collections.unmodifiableMap(environment); |
|
161 |
} |
|
162 |
} |
|
163 |
||
164 |
/** |
|
32034
05676cfd40b5
8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents:
26594
diff
changeset
|
165 |
* <p>Constructs an {@code RMIConnector} that will connect |
2 | 166 |
* the RMI connector server with the given address.</p> |
167 |
* |
|
168 |
* <p>The address can refer directly to the connector server, |
|
32639
339de1317e84
8043937: Drop support for the IIOP transport from the JMX RMIConnector
jbachorik
parents:
32034
diff
changeset
|
169 |
* using the following syntax:</p> |
2 | 170 |
* |
171 |
* <pre> |
|
172 |
* service:jmx:rmi://<em>[host[:port]]</em>/stub/<em>encoded-stub</em> |
|
173 |
* </pre> |
|
174 |
* |
|
32034
05676cfd40b5
8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents:
26594
diff
changeset
|
175 |
* <p>(Here, the square brackets {@code []} are not part of the |
2 | 176 |
* address but indicate that the host and port are optional.)</p> |
177 |
* |
|
178 |
* <p>The address can instead indicate where to find an RMI stub |
|
32639
339de1317e84
8043937: Drop support for the IIOP transport from the JMX RMIConnector
jbachorik
parents:
32034
diff
changeset
|
179 |
* through JNDI, using the following syntax:</p> |
2 | 180 |
* |
181 |
* <pre> |
|
182 |
* service:jmx:rmi://<em>[host[:port]]</em>/jndi/<em>jndi-name</em> |
|
183 |
* </pre> |
|
184 |
* |
|
185 |
* <p>An implementation may also recognize additional address |
|
186 |
* syntaxes, for example:</p> |
|
187 |
* |
|
188 |
* <pre> |
|
189 |
* service:jmx:iiop://<em>[host[:port]]</em>/stub/<em>encoded-stub</em> |
|
190 |
* </pre> |
|
191 |
* |
|
192 |
* @param url the address of the RMI connector server. |
|
193 |
* |
|
194 |
* @param environment additional attributes specifying how to make |
|
195 |
* the connection. For JNDI-based addresses, these attributes can |
|
196 |
* usefully include JNDI attributes recognized by {@link |
|
197 |
* InitialContext#InitialContext(Hashtable) InitialContext}. This |
|
198 |
* parameter can be null, which is equivalent to an empty Map. |
|
199 |
* |
|
32034
05676cfd40b5
8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents:
26594
diff
changeset
|
200 |
* @exception IllegalArgumentException if {@code url} |
2 | 201 |
* is null. |
202 |
*/ |
|
203 |
public RMIConnector(JMXServiceURL url, Map<String,?> environment) { |
|
204 |
this(null, url, environment); |
|
205 |
} |
|
206 |
||
207 |
/** |
|
32034
05676cfd40b5
8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents:
26594
diff
changeset
|
208 |
* <p>Constructs an {@code RMIConnector} using the given RMI stub. |
2 | 209 |
* |
210 |
* @param rmiServer an RMI stub representing the RMI connector server. |
|
211 |
* @param environment additional attributes specifying how to make |
|
212 |
* the connection. This parameter can be null, which is |
|
213 |
* equivalent to an empty Map. |
|
214 |
* |
|
32034
05676cfd40b5
8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents:
26594
diff
changeset
|
215 |
* @exception IllegalArgumentException if {@code rmiServer} |
2 | 216 |
* is null. |
217 |
*/ |
|
218 |
public RMIConnector(RMIServer rmiServer, Map<String,?> environment) { |
|
219 |
this(rmiServer, null, environment); |
|
220 |
} |
|
221 |
||
222 |
/** |
|
223 |
* <p>Returns a string representation of this object. In general, |
|
32034
05676cfd40b5
8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents:
26594
diff
changeset
|
224 |
* the {@code toString} method returns a string that |
2 | 225 |
* "textually represents" this object. The result should be a |
226 |
* concise but informative representation that is easy for a |
|
227 |
* person to read.</p> |
|
228 |
* |
|
229 |
* @return a String representation of this object. |
|
230 |
**/ |
|
4156 | 231 |
@Override |
2 | 232 |
public String toString() { |
233 |
final StringBuilder b = new StringBuilder(this.getClass().getName()); |
|
234 |
b.append(":"); |
|
235 |
if (rmiServer != null) { |
|
236 |
b.append(" rmiServer=").append(rmiServer.toString()); |
|
237 |
} |
|
238 |
if (jmxServiceURL != null) { |
|
239 |
if (rmiServer!=null) b.append(","); |
|
240 |
b.append(" jmxServiceURL=").append(jmxServiceURL.toString()); |
|
241 |
} |
|
242 |
return b.toString(); |
|
243 |
} |
|
244 |
||
245 |
/** |
|
246 |
* <p>The address of this connector.</p> |
|
247 |
* |
|
248 |
* @return the address of this connector, or null if it |
|
249 |
* does not have one. |
|
250 |
* |
|
251 |
* @since 1.6 |
|
252 |
*/ |
|
253 |
public JMXServiceURL getAddress() { |
|
254 |
return jmxServiceURL; |
|
255 |
} |
|
256 |
||
257 |
//-------------------------------------------------------------------- |
|
258 |
// implements JMXConnector interface |
|
259 |
//-------------------------------------------------------------------- |
|
14917
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
14342
diff
changeset
|
260 |
|
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
14342
diff
changeset
|
261 |
/** |
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
14342
diff
changeset
|
262 |
* @throws IOException if the connection could not be made because of a |
32639
339de1317e84
8043937: Drop support for the IIOP transport from the JMX RMIConnector
jbachorik
parents:
32034
diff
changeset
|
263 |
* communication problem |
14917
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
14342
diff
changeset
|
264 |
*/ |
2 | 265 |
public void connect() throws IOException { |
266 |
connect(null); |
|
267 |
} |
|
268 |
||
14917
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
14342
diff
changeset
|
269 |
/** |
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
14342
diff
changeset
|
270 |
* @throws IOException if the connection could not be made because of a |
32639
339de1317e84
8043937: Drop support for the IIOP transport from the JMX RMIConnector
jbachorik
parents:
32034
diff
changeset
|
271 |
* communication problem |
14917
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
14342
diff
changeset
|
272 |
*/ |
2 | 273 |
public synchronized void connect(Map<String,?> environment) |
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
274 |
throws IOException { |
2 | 275 |
final boolean tracing = logger.traceOn(); |
276 |
String idstr = (tracing?"["+this.toString()+"]":null); |
|
277 |
||
278 |
if (terminated) { |
|
279 |
logger.trace("connect",idstr + " already closed."); |
|
280 |
throw new IOException("Connector closed"); |
|
281 |
} |
|
282 |
if (connected) { |
|
283 |
logger.trace("connect",idstr + " already connected."); |
|
284 |
return; |
|
285 |
} |
|
286 |
||
287 |
try { |
|
288 |
if (tracing) logger.trace("connect",idstr + " connecting..."); |
|
289 |
||
290 |
final Map<String, Object> usemap = |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
291 |
new HashMap<String, Object>((this.env==null) ? |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
292 |
Collections.<String, Object>emptyMap() : this.env); |
2 | 293 |
|
294 |
||
295 |
if (environment != null) { |
|
296 |
EnvHelp.checkAttributes(environment); |
|
297 |
usemap.putAll(environment); |
|
298 |
} |
|
299 |
||
300 |
// Get RMIServer stub from directory or URL encoding if needed. |
|
301 |
if (tracing) logger.trace("connect",idstr + " finding stub..."); |
|
302 |
RMIServer stub = (rmiServer!=null)?rmiServer: |
|
303 |
findRMIServer(jmxServiceURL, usemap); |
|
304 |
||
305 |
// Check for secure RMIServer stub if the corresponding |
|
306 |
// client-side environment property is set to "true". |
|
307 |
// |
|
14210
042f1a001234
7158796: Tighten properties checking in EnvHelp
dsamersoff
parents:
7167
diff
changeset
|
308 |
String stringBoolean = (String) usemap.get("jmx.remote.x.check.stub"); |
042f1a001234
7158796: Tighten properties checking in EnvHelp
dsamersoff
parents:
7167
diff
changeset
|
309 |
boolean checkStub = EnvHelp.computeBooleanFromString(stringBoolean); |
042f1a001234
7158796: Tighten properties checking in EnvHelp
dsamersoff
parents:
7167
diff
changeset
|
310 |
|
2 | 311 |
if (checkStub) checkStub(stub, rmiServerImplStubClass); |
312 |
||
313 |
if (tracing) logger.trace("connect",idstr + " connecting stub..."); |
|
314 |
idstr = (tracing?"["+this.toString()+"]":null); |
|
315 |
||
316 |
// Calling newClient on the RMIServer stub. |
|
317 |
if (tracing) |
|
318 |
logger.trace("connect",idstr + " getting connection..."); |
|
319 |
Object credentials = usemap.get(CREDENTIALS); |
|
7167
f5a0fca591f8
6696028: JMXServiceURL like service:jmx:rmi:///jndi/iiop:// should be rejected by the RMI conn provider.
coffeys
parents:
5506
diff
changeset
|
320 |
|
f5a0fca591f8
6696028: JMXServiceURL like service:jmx:rmi:///jndi/iiop:// should be rejected by the RMI conn provider.
coffeys
parents:
5506
diff
changeset
|
321 |
try { |
f5a0fca591f8
6696028: JMXServiceURL like service:jmx:rmi:///jndi/iiop:// should be rejected by the RMI conn provider.
coffeys
parents:
5506
diff
changeset
|
322 |
connection = getConnection(stub, credentials, checkStub); |
f5a0fca591f8
6696028: JMXServiceURL like service:jmx:rmi:///jndi/iiop:// should be rejected by the RMI conn provider.
coffeys
parents:
5506
diff
changeset
|
323 |
} catch (java.rmi.RemoteException re) { |
f5a0fca591f8
6696028: JMXServiceURL like service:jmx:rmi:///jndi/iiop:// should be rejected by the RMI conn provider.
coffeys
parents:
5506
diff
changeset
|
324 |
throw re; |
f5a0fca591f8
6696028: JMXServiceURL like service:jmx:rmi:///jndi/iiop:// should be rejected by the RMI conn provider.
coffeys
parents:
5506
diff
changeset
|
325 |
} |
2 | 326 |
|
327 |
// Always use one of: |
|
328 |
// ClassLoader provided in Map at connect time, |
|
329 |
// or contextClassLoader at connect time. |
|
330 |
if (tracing) |
|
331 |
logger.trace("connect",idstr + " getting class loader..."); |
|
332 |
defaultClassLoader = EnvHelp.resolveClientClassLoader(usemap); |
|
333 |
||
334 |
usemap.put(JMXConnectorFactory.DEFAULT_CLASS_LOADER, |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
335 |
defaultClassLoader); |
2 | 336 |
|
337 |
rmiNotifClient = new RMINotifClient(defaultClassLoader, usemap); |
|
338 |
||
339 |
env = usemap; |
|
340 |
final long checkPeriod = EnvHelp.getConnectionCheckPeriod(usemap); |
|
341 |
communicatorAdmin = new RMIClientCommunicatorAdmin(checkPeriod); |
|
342 |
||
343 |
connected = true; |
|
344 |
||
345 |
// The connectionId variable is used in doStart(), when |
|
346 |
// reconnecting, to identify the "old" connection. |
|
347 |
// |
|
348 |
connectionId = getConnectionId(); |
|
349 |
||
350 |
Notification connectedNotif = |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
351 |
new JMXConnectionNotification(JMXConnectionNotification.OPENED, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
352 |
this, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
353 |
connectionId, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
354 |
clientNotifSeqNo++, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
355 |
"Successful connection", |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
356 |
null); |
2 | 357 |
sendNotification(connectedNotif); |
358 |
||
359 |
if (tracing) logger.trace("connect",idstr + " done..."); |
|
360 |
} catch (IOException e) { |
|
361 |
if (tracing) |
|
362 |
logger.trace("connect",idstr + " failed to connect: " + e); |
|
363 |
throw e; |
|
364 |
} catch (RuntimeException e) { |
|
365 |
if (tracing) |
|
366 |
logger.trace("connect",idstr + " failed to connect: " + e); |
|
367 |
throw e; |
|
368 |
} catch (NamingException e) { |
|
369 |
final String msg = "Failed to retrieve RMIServer stub: " + e; |
|
370 |
if (tracing) logger.trace("connect",idstr + " " + msg); |
|
371 |
throw EnvHelp.initCause(new IOException(msg),e); |
|
372 |
} |
|
373 |
} |
|
374 |
||
375 |
public synchronized String getConnectionId() throws IOException { |
|
376 |
if (terminated || !connected) { |
|
377 |
if (logger.traceOn()) |
|
378 |
logger.trace("getConnectionId","["+this.toString()+ |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
379 |
"] not connected."); |
2 | 380 |
|
381 |
throw new IOException("Not connected"); |
|
382 |
} |
|
383 |
||
384 |
// we do a remote call to have an IOException if the connection is broken. |
|
385 |
// see the bug 4939578 |
|
386 |
return connection.getConnectionId(); |
|
387 |
} |
|
388 |
||
389 |
public synchronized MBeanServerConnection getMBeanServerConnection() |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
390 |
throws IOException { |
2 | 391 |
return getMBeanServerConnection(null); |
392 |
} |
|
393 |
||
394 |
public synchronized MBeanServerConnection |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
395 |
getMBeanServerConnection(Subject delegationSubject) |
2 | 396 |
throws IOException { |
397 |
||
398 |
if (terminated) { |
|
399 |
if (logger.traceOn()) |
|
400 |
logger.trace("getMBeanServerConnection","[" + this.toString() + |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
401 |
"] already closed."); |
2 | 402 |
throw new IOException("Connection closed"); |
403 |
} else if (!connected) { |
|
404 |
if (logger.traceOn()) |
|
405 |
logger.trace("getMBeanServerConnection","[" + this.toString() + |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
406 |
"] is not connected."); |
2 | 407 |
throw new IOException("Not connected"); |
408 |
} |
|
409 |
||
19791
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
18206
diff
changeset
|
410 |
return getConnectionWithSubject(delegationSubject); |
1004 | 411 |
} |
412 |
||
2 | 413 |
public void |
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
414 |
addConnectionNotificationListener(NotificationListener listener, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
415 |
NotificationFilter filter, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
416 |
Object handback) { |
2 | 417 |
if (listener == null) |
418 |
throw new NullPointerException("listener"); |
|
419 |
connectionBroadcaster.addNotificationListener(listener, filter, |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
420 |
handback); |
2 | 421 |
} |
422 |
||
423 |
public void |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
424 |
removeConnectionNotificationListener(NotificationListener listener) |
2 | 425 |
throws ListenerNotFoundException { |
426 |
if (listener == null) |
|
427 |
throw new NullPointerException("listener"); |
|
428 |
connectionBroadcaster.removeNotificationListener(listener); |
|
429 |
} |
|
430 |
||
431 |
public void |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
432 |
removeConnectionNotificationListener(NotificationListener listener, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
433 |
NotificationFilter filter, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
434 |
Object handback) |
2 | 435 |
throws ListenerNotFoundException { |
436 |
if (listener == null) |
|
437 |
throw new NullPointerException("listener"); |
|
438 |
connectionBroadcaster.removeNotificationListener(listener, filter, |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
439 |
handback); |
2 | 440 |
} |
441 |
||
442 |
private void sendNotification(Notification n) { |
|
443 |
connectionBroadcaster.sendNotification(n); |
|
444 |
} |
|
445 |
||
446 |
public synchronized void close() throws IOException { |
|
447 |
close(false); |
|
448 |
} |
|
449 |
||
450 |
// allows to do close after setting the flag "terminated" to true. |
|
451 |
// It is necessary to avoid a deadlock, see 6296324 |
|
452 |
private synchronized void close(boolean intern) throws IOException { |
|
453 |
final boolean tracing = logger.traceOn(); |
|
454 |
final boolean debug = logger.debugOn(); |
|
455 |
final String idstr = (tracing?"["+this.toString()+"]":null); |
|
456 |
||
457 |
if (!intern) { |
|
458 |
// Return if already cleanly closed. |
|
459 |
// |
|
460 |
if (terminated) { |
|
461 |
if (closeException == null) { |
|
462 |
if (tracing) logger.trace("close",idstr + " already closed."); |
|
463 |
return; |
|
464 |
} |
|
465 |
} else { |
|
466 |
terminated = true; |
|
467 |
} |
|
468 |
} |
|
469 |
||
470 |
if (closeException != null && tracing) { |
|
471 |
// Already closed, but not cleanly. Attempt again. |
|
472 |
// |
|
473 |
if (tracing) { |
|
474 |
logger.trace("close",idstr + " had failed: " + closeException); |
|
475 |
logger.trace("close",idstr + " attempting to close again."); |
|
476 |
} |
|
477 |
} |
|
478 |
||
479 |
String savedConnectionId = null; |
|
480 |
if (connected) { |
|
481 |
savedConnectionId = connectionId; |
|
482 |
} |
|
483 |
||
484 |
closeException = null; |
|
485 |
||
486 |
if (tracing) logger.trace("close",idstr + " closing."); |
|
487 |
||
488 |
if (communicatorAdmin != null) { |
|
489 |
communicatorAdmin.terminate(); |
|
490 |
} |
|
491 |
||
492 |
if (rmiNotifClient != null) { |
|
493 |
try { |
|
494 |
rmiNotifClient.terminate(); |
|
495 |
if (tracing) logger.trace("close",idstr + |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
496 |
" RMI Notification client terminated."); |
2 | 497 |
} catch (RuntimeException x) { |
498 |
closeException = x; |
|
499 |
if (tracing) logger.trace("close",idstr + |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
500 |
" Failed to terminate RMI Notification client: " + x); |
2 | 501 |
if (debug) logger.debug("close",x); |
502 |
} |
|
503 |
} |
|
504 |
||
505 |
if (connection != null) { |
|
506 |
try { |
|
507 |
connection.close(); |
|
508 |
if (tracing) logger.trace("close",idstr + " closed."); |
|
509 |
} catch (NoSuchObjectException nse) { |
|
510 |
// OK, the server maybe closed itself. |
|
511 |
} catch (IOException e) { |
|
512 |
closeException = e; |
|
513 |
if (tracing) logger.trace("close",idstr + |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
514 |
" Failed to close RMIServer: " + e); |
2 | 515 |
if (debug) logger.debug("close",e); |
516 |
} |
|
517 |
} |
|
518 |
||
519 |
// Clean up MBeanServerConnection table |
|
520 |
// |
|
521 |
rmbscMap.clear(); |
|
522 |
||
523 |
/* Send notification of closure. We don't do this if the user |
|
524 |
* never called connect() on the connector, because there's no |
|
525 |
* connection id in that case. */ |
|
526 |
||
527 |
if (savedConnectionId != null) { |
|
528 |
Notification closedNotif = |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
529 |
new JMXConnectionNotification(JMXConnectionNotification.CLOSED, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
530 |
this, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
531 |
savedConnectionId, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
532 |
clientNotifSeqNo++, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
533 |
"Client has been closed", |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
534 |
null); |
2 | 535 |
sendNotification(closedNotif); |
536 |
} |
|
537 |
||
538 |
// throw exception if needed |
|
539 |
// |
|
540 |
if (closeException != null) { |
|
541 |
if (tracing) logger.trace("close",idstr + " failed to close: " + |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
542 |
closeException); |
2 | 543 |
if (closeException instanceof IOException) |
544 |
throw (IOException) closeException; |
|
545 |
if (closeException instanceof RuntimeException) |
|
546 |
throw (RuntimeException) closeException; |
|
547 |
final IOException x = |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
548 |
new IOException("Failed to close: " + closeException); |
2 | 549 |
throw EnvHelp.initCause(x,closeException); |
550 |
} |
|
551 |
} |
|
552 |
||
553 |
// added for re-connection |
|
554 |
private Integer addListenerWithSubject(ObjectName name, |
|
1510
e747d3193ef2
6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents:
1446
diff
changeset
|
555 |
MarshalledObject<NotificationFilter> filter, |
2 | 556 |
Subject delegationSubject, |
557 |
boolean reconnect) |
|
558 |
throws InstanceNotFoundException, IOException { |
|
559 |
||
560 |
final boolean debug = logger.debugOn(); |
|
561 |
if (debug) |
|
562 |
logger.debug("addListenerWithSubject", |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
563 |
"(ObjectName,MarshalledObject,Subject)"); |
2 | 564 |
|
565 |
final ObjectName[] names = new ObjectName[] {name}; |
|
1510
e747d3193ef2
6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents:
1446
diff
changeset
|
566 |
final MarshalledObject<NotificationFilter>[] filters = |
e747d3193ef2
6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents:
1446
diff
changeset
|
567 |
Util.cast(new MarshalledObject<?>[] {filter}); |
2 | 568 |
final Subject[] delegationSubjects = new Subject[] { |
569 |
delegationSubject |
|
570 |
}; |
|
571 |
||
572 |
final Integer[] listenerIDs = |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
573 |
addListenersWithSubjects(names,filters,delegationSubjects, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
574 |
reconnect); |
2 | 575 |
|
576 |
if (debug) logger.debug("addListenerWithSubject","listenerID=" |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
577 |
+ listenerIDs[0]); |
2 | 578 |
return listenerIDs[0]; |
579 |
} |
|
580 |
||
581 |
// added for re-connection |
|
582 |
private Integer[] addListenersWithSubjects(ObjectName[] names, |
|
1510
e747d3193ef2
6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents:
1446
diff
changeset
|
583 |
MarshalledObject<NotificationFilter>[] filters, |
2 | 584 |
Subject[] delegationSubjects, |
585 |
boolean reconnect) |
|
586 |
throws InstanceNotFoundException, IOException { |
|
587 |
||
588 |
final boolean debug = logger.debugOn(); |
|
589 |
if (debug) |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
590 |
logger.debug("addListenersWithSubjects", |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
591 |
"(ObjectName[],MarshalledObject[],Subject[])"); |
2 | 592 |
|
593 |
final ClassLoader old = pushDefaultClassLoader(); |
|
594 |
Integer[] listenerIDs = null; |
|
595 |
||
596 |
try { |
|
597 |
listenerIDs = connection.addNotificationListeners(names, |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
598 |
filters, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
599 |
delegationSubjects); |
2 | 600 |
} catch (NoSuchObjectException noe) { |
601 |
// maybe reconnect |
|
602 |
if (reconnect) { |
|
603 |
communicatorAdmin.gotIOException(noe); |
|
604 |
||
605 |
listenerIDs = connection.addNotificationListeners(names, |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
606 |
filters, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
607 |
delegationSubjects); |
2 | 608 |
} else { |
609 |
throw noe; |
|
610 |
} |
|
611 |
} catch (IOException ioe) { |
|
612 |
// send a failed notif if necessary |
|
613 |
communicatorAdmin.gotIOException(ioe); |
|
614 |
} finally { |
|
615 |
popDefaultClassLoader(old); |
|
616 |
} |
|
617 |
||
618 |
if (debug) logger.debug("addListenersWithSubjects","registered " |
|
1004 | 619 |
+ ((listenerIDs==null)?0:listenerIDs.length) |
620 |
+ " listener(s)"); |
|
2 | 621 |
return listenerIDs; |
622 |
} |
|
623 |
||
624 |
//-------------------------------------------------------------------- |
|
625 |
// Implementation of MBeanServerConnection |
|
626 |
//-------------------------------------------------------------------- |
|
1004 | 627 |
private class RemoteMBeanServerConnection implements MBeanServerConnection { |
628 |
private Subject delegationSubject; |
|
2 | 629 |
|
630 |
public RemoteMBeanServerConnection() { |
|
631 |
this(null); |
|
632 |
} |
|
633 |
||
634 |
public RemoteMBeanServerConnection(Subject delegationSubject) { |
|
635 |
this.delegationSubject = delegationSubject; |
|
636 |
} |
|
637 |
||
638 |
public ObjectInstance createMBean(String className, |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
639 |
ObjectName name) |
2 | 640 |
throws ReflectionException, |
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
641 |
InstanceAlreadyExistsException, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
642 |
MBeanRegistrationException, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
643 |
MBeanException, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
644 |
NotCompliantMBeanException, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
645 |
IOException { |
2 | 646 |
if (logger.debugOn()) |
647 |
logger.debug("createMBean(String,ObjectName)", |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
648 |
"className=" + className + ", name=" + |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
649 |
name); |
2 | 650 |
|
651 |
final ClassLoader old = pushDefaultClassLoader(); |
|
652 |
try { |
|
653 |
return connection.createMBean(className, |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
654 |
name, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
655 |
delegationSubject); |
2 | 656 |
} catch (IOException ioe) { |
657 |
communicatorAdmin.gotIOException(ioe); |
|
658 |
||
659 |
return connection.createMBean(className, |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
660 |
name, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
661 |
delegationSubject); |
2 | 662 |
} finally { |
663 |
popDefaultClassLoader(old); |
|
664 |
} |
|
665 |
} |
|
666 |
||
667 |
public ObjectInstance createMBean(String className, |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
668 |
ObjectName name, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
669 |
ObjectName loaderName) |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
670 |
throws ReflectionException, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
671 |
InstanceAlreadyExistsException, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
672 |
MBeanRegistrationException, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
673 |
MBeanException, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
674 |
NotCompliantMBeanException, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
675 |
InstanceNotFoundException, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
676 |
IOException { |
2 | 677 |
|
678 |
if (logger.debugOn()) |
|
679 |
logger.debug("createMBean(String,ObjectName,ObjectName)", |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
680 |
"className=" + className + ", name=" |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
681 |
+ name + ", loaderName=" |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
682 |
+ loaderName + ")"); |
2 | 683 |
|
684 |
final ClassLoader old = pushDefaultClassLoader(); |
|
685 |
try { |
|
686 |
return connection.createMBean(className, |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
687 |
name, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
688 |
loaderName, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
689 |
delegationSubject); |
2 | 690 |
|
691 |
} catch (IOException ioe) { |
|
692 |
communicatorAdmin.gotIOException(ioe); |
|
693 |
||
694 |
return connection.createMBean(className, |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
695 |
name, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
696 |
loaderName, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
697 |
delegationSubject); |
2 | 698 |
|
699 |
} finally { |
|
700 |
popDefaultClassLoader(old); |
|
701 |
} |
|
702 |
} |
|
703 |
||
704 |
public ObjectInstance createMBean(String className, |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
705 |
ObjectName name, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
706 |
Object params[], |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
707 |
String signature[]) |
2 | 708 |
throws ReflectionException, |
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
709 |
InstanceAlreadyExistsException, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
710 |
MBeanRegistrationException, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
711 |
MBeanException, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
712 |
NotCompliantMBeanException, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
713 |
IOException { |
2 | 714 |
if (logger.debugOn()) |
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
715 |
logger.debug("createMBean(String,ObjectName,Object[],String[])", |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
716 |
"className=" + className + ", name=" |
35282 | 717 |
+ name + ", signature=" + strings(signature)); |
2 | 718 |
|
719 |
final MarshalledObject<Object[]> sParams = |
|
720 |
new MarshalledObject<Object[]>(params); |
|
721 |
final ClassLoader old = pushDefaultClassLoader(); |
|
722 |
try { |
|
723 |
return connection.createMBean(className, |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
724 |
name, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
725 |
sParams, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
726 |
signature, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
727 |
delegationSubject); |
2 | 728 |
} catch (IOException ioe) { |
729 |
communicatorAdmin.gotIOException(ioe); |
|
730 |
||
731 |
return connection.createMBean(className, |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
732 |
name, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
733 |
sParams, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
734 |
signature, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
735 |
delegationSubject); |
2 | 736 |
} finally { |
737 |
popDefaultClassLoader(old); |
|
738 |
} |
|
739 |
} |
|
740 |
||
741 |
public ObjectInstance createMBean(String className, |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
742 |
ObjectName name, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
743 |
ObjectName loaderName, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
744 |
Object params[], |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
745 |
String signature[]) |
2 | 746 |
throws ReflectionException, |
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
747 |
InstanceAlreadyExistsException, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
748 |
MBeanRegistrationException, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
749 |
MBeanException, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
750 |
NotCompliantMBeanException, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
751 |
InstanceNotFoundException, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
752 |
IOException { |
2 | 753 |
if (logger.debugOn()) logger.debug( |
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
754 |
"createMBean(String,ObjectName,ObjectName,Object[],String[])", |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
755 |
"className=" + className + ", name=" + name + ", loaderName=" |
35282 | 756 |
+ loaderName + ", signature=" + strings(signature)); |
2 | 757 |
|
758 |
final MarshalledObject<Object[]> sParams = |
|
759 |
new MarshalledObject<Object[]>(params); |
|
760 |
final ClassLoader old = pushDefaultClassLoader(); |
|
761 |
try { |
|
762 |
return connection.createMBean(className, |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
763 |
name, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
764 |
loaderName, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
765 |
sParams, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
766 |
signature, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
767 |
delegationSubject); |
2 | 768 |
} catch (IOException ioe) { |
769 |
communicatorAdmin.gotIOException(ioe); |
|
770 |
||
771 |
return connection.createMBean(className, |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
772 |
name, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
773 |
loaderName, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
774 |
sParams, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
775 |
signature, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
776 |
delegationSubject); |
2 | 777 |
} finally { |
778 |
popDefaultClassLoader(old); |
|
779 |
} |
|
780 |
} |
|
781 |
||
782 |
public void unregisterMBean(ObjectName name) |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
783 |
throws InstanceNotFoundException, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
784 |
MBeanRegistrationException, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
785 |
IOException { |
2 | 786 |
if (logger.debugOn()) |
787 |
logger.debug("unregisterMBean", "name=" + name); |
|
788 |
||
789 |
final ClassLoader old = pushDefaultClassLoader(); |
|
790 |
try { |
|
791 |
connection.unregisterMBean(name, delegationSubject); |
|
792 |
} catch (IOException ioe) { |
|
793 |
communicatorAdmin.gotIOException(ioe); |
|
794 |
||
795 |
connection.unregisterMBean(name, delegationSubject); |
|
796 |
} finally { |
|
797 |
popDefaultClassLoader(old); |
|
798 |
} |
|
799 |
} |
|
800 |
||
801 |
public ObjectInstance getObjectInstance(ObjectName name) |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
802 |
throws InstanceNotFoundException, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
803 |
IOException { |
2 | 804 |
if (logger.debugOn()) |
805 |
logger.debug("getObjectInstance", "name=" + name); |
|
806 |
||
807 |
final ClassLoader old = pushDefaultClassLoader(); |
|
808 |
try { |
|
809 |
return connection.getObjectInstance(name, delegationSubject); |
|
810 |
} catch (IOException ioe) { |
|
811 |
communicatorAdmin.gotIOException(ioe); |
|
812 |
||
813 |
return connection.getObjectInstance(name, delegationSubject); |
|
814 |
} finally { |
|
815 |
popDefaultClassLoader(old); |
|
816 |
} |
|
817 |
} |
|
818 |
||
819 |
public Set<ObjectInstance> queryMBeans(ObjectName name, |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
820 |
QueryExp query) |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
821 |
throws IOException { |
2 | 822 |
if (logger.debugOn()) logger.debug("queryMBeans", |
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
823 |
"name=" + name + ", query=" + query); |
2 | 824 |
|
825 |
final MarshalledObject<QueryExp> sQuery = |
|
826 |
new MarshalledObject<QueryExp>(query); |
|
827 |
final ClassLoader old = pushDefaultClassLoader(); |
|
828 |
try { |
|
829 |
return connection.queryMBeans(name, sQuery, delegationSubject); |
|
830 |
} catch (IOException ioe) { |
|
831 |
communicatorAdmin.gotIOException(ioe); |
|
832 |
||
833 |
return connection.queryMBeans(name, sQuery, delegationSubject); |
|
834 |
} finally { |
|
835 |
popDefaultClassLoader(old); |
|
836 |
} |
|
837 |
} |
|
838 |
||
839 |
public Set<ObjectName> queryNames(ObjectName name, |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
840 |
QueryExp query) |
2 | 841 |
throws IOException { |
842 |
if (logger.debugOn()) logger.debug("queryNames", |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
843 |
"name=" + name + ", query=" + query); |
2 | 844 |
|
845 |
final MarshalledObject<QueryExp> sQuery = |
|
846 |
new MarshalledObject<QueryExp>(query); |
|
847 |
final ClassLoader old = pushDefaultClassLoader(); |
|
848 |
try { |
|
849 |
return connection.queryNames(name, sQuery, delegationSubject); |
|
850 |
} catch (IOException ioe) { |
|
851 |
communicatorAdmin.gotIOException(ioe); |
|
852 |
||
853 |
return connection.queryNames(name, sQuery, delegationSubject); |
|
854 |
} finally { |
|
855 |
popDefaultClassLoader(old); |
|
856 |
} |
|
857 |
} |
|
858 |
||
859 |
public boolean isRegistered(ObjectName name) |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
860 |
throws IOException { |
2 | 861 |
if (logger.debugOn()) |
862 |
logger.debug("isRegistered", "name=" + name); |
|
863 |
||
864 |
final ClassLoader old = pushDefaultClassLoader(); |
|
865 |
try { |
|
866 |
return connection.isRegistered(name, delegationSubject); |
|
867 |
} catch (IOException ioe) { |
|
868 |
communicatorAdmin.gotIOException(ioe); |
|
869 |
||
870 |
return connection.isRegistered(name, delegationSubject); |
|
871 |
} finally { |
|
872 |
popDefaultClassLoader(old); |
|
873 |
} |
|
874 |
} |
|
875 |
||
876 |
public Integer getMBeanCount() |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
877 |
throws IOException { |
2 | 878 |
if (logger.debugOn()) logger.debug("getMBeanCount", ""); |
879 |
||
880 |
final ClassLoader old = pushDefaultClassLoader(); |
|
881 |
try { |
|
882 |
return connection.getMBeanCount(delegationSubject); |
|
883 |
} catch (IOException ioe) { |
|
884 |
communicatorAdmin.gotIOException(ioe); |
|
885 |
||
886 |
return connection.getMBeanCount(delegationSubject); |
|
887 |
} finally { |
|
888 |
popDefaultClassLoader(old); |
|
889 |
} |
|
890 |
} |
|
891 |
||
892 |
public Object getAttribute(ObjectName name, |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
893 |
String attribute) |
2 | 894 |
throws MBeanException, |
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
895 |
AttributeNotFoundException, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
896 |
InstanceNotFoundException, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
897 |
ReflectionException, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
898 |
IOException { |
2 | 899 |
if (logger.debugOn()) logger.debug("getAttribute", |
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
900 |
"name=" + name + ", attribute=" |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
901 |
+ attribute); |
2 | 902 |
|
903 |
final ClassLoader old = pushDefaultClassLoader(); |
|
904 |
try { |
|
905 |
return connection.getAttribute(name, |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
906 |
attribute, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
907 |
delegationSubject); |
2 | 908 |
} catch (IOException ioe) { |
909 |
communicatorAdmin.gotIOException(ioe); |
|
910 |
||
911 |
return connection.getAttribute(name, |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
912 |
attribute, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
913 |
delegationSubject); |
2 | 914 |
} finally { |
915 |
popDefaultClassLoader(old); |
|
916 |
} |
|
917 |
} |
|
918 |
||
919 |
public AttributeList getAttributes(ObjectName name, |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
920 |
String[] attributes) |
2 | 921 |
throws InstanceNotFoundException, |
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
922 |
ReflectionException, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
923 |
IOException { |
2 | 924 |
if (logger.debugOn()) logger.debug("getAttributes", |
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
925 |
"name=" + name + ", attributes=" |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
926 |
+ strings(attributes)); |
2 | 927 |
|
928 |
final ClassLoader old = pushDefaultClassLoader(); |
|
929 |
try { |
|
930 |
return connection.getAttributes(name, |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
931 |
attributes, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
932 |
delegationSubject); |
2 | 933 |
|
934 |
} catch (IOException ioe) { |
|
935 |
communicatorAdmin.gotIOException(ioe); |
|
936 |
||
937 |
return connection.getAttributes(name, |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
938 |
attributes, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
939 |
delegationSubject); |
2 | 940 |
} finally { |
941 |
popDefaultClassLoader(old); |
|
942 |
} |
|
943 |
} |
|
944 |
||
945 |
||
946 |
public void setAttribute(ObjectName name, |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
947 |
Attribute attribute) |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
948 |
throws InstanceNotFoundException, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
949 |
AttributeNotFoundException, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
950 |
InvalidAttributeValueException, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
951 |
MBeanException, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
952 |
ReflectionException, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
953 |
IOException { |
2 | 954 |
|
955 |
if (logger.debugOn()) logger.debug("setAttribute", |
|
35282 | 956 |
"name=" + name + ", attribute name=" |
957 |
+ attribute.getName()); |
|
2 | 958 |
|
959 |
final MarshalledObject<Attribute> sAttribute = |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
960 |
new MarshalledObject<Attribute>(attribute); |
2 | 961 |
final ClassLoader old = pushDefaultClassLoader(); |
962 |
try { |
|
963 |
connection.setAttribute(name, sAttribute, delegationSubject); |
|
964 |
} catch (IOException ioe) { |
|
965 |
communicatorAdmin.gotIOException(ioe); |
|
966 |
||
967 |
connection.setAttribute(name, sAttribute, delegationSubject); |
|
968 |
} finally { |
|
969 |
popDefaultClassLoader(old); |
|
970 |
} |
|
971 |
} |
|
972 |
||
973 |
public AttributeList setAttributes(ObjectName name, |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
974 |
AttributeList attributes) |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
975 |
throws InstanceNotFoundException, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
976 |
ReflectionException, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
977 |
IOException { |
2 | 978 |
|
35282 | 979 |
if (logger.debugOn()) { |
980 |
logger.debug("setAttributes", |
|
981 |
"name=" + name + ", attribute names=" |
|
982 |
+ getAttributesNames(attributes)); |
|
983 |
} |
|
2 | 984 |
|
985 |
final MarshalledObject<AttributeList> sAttributes = |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
986 |
new MarshalledObject<AttributeList>(attributes); |
2 | 987 |
final ClassLoader old = pushDefaultClassLoader(); |
988 |
try { |
|
989 |
return connection.setAttributes(name, |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
990 |
sAttributes, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
991 |
delegationSubject); |
2 | 992 |
} catch (IOException ioe) { |
993 |
communicatorAdmin.gotIOException(ioe); |
|
994 |
||
995 |
return connection.setAttributes(name, |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
996 |
sAttributes, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
997 |
delegationSubject); |
2 | 998 |
} finally { |
999 |
popDefaultClassLoader(old); |
|
1000 |
} |
|
1001 |
} |
|
1002 |
||
1003 |
||
1004 |
public Object invoke(ObjectName name, |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1005 |
String operationName, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1006 |
Object params[], |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1007 |
String signature[]) |
2 | 1008 |
throws InstanceNotFoundException, |
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1009 |
MBeanException, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1010 |
ReflectionException, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1011 |
IOException { |
2 | 1012 |
|
1013 |
if (logger.debugOn()) logger.debug("invoke", |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1014 |
"name=" + name |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1015 |
+ ", operationName=" + operationName |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1016 |
+ ", signature=" + strings(signature)); |
2 | 1017 |
|
1018 |
final MarshalledObject<Object[]> sParams = |
|
1019 |
new MarshalledObject<Object[]>(params); |
|
1020 |
final ClassLoader old = pushDefaultClassLoader(); |
|
1021 |
try { |
|
1022 |
return connection.invoke(name, |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1023 |
operationName, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1024 |
sParams, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1025 |
signature, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1026 |
delegationSubject); |
2 | 1027 |
} catch (IOException ioe) { |
1028 |
communicatorAdmin.gotIOException(ioe); |
|
1029 |
||
1030 |
return connection.invoke(name, |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1031 |
operationName, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1032 |
sParams, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1033 |
signature, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1034 |
delegationSubject); |
2 | 1035 |
} finally { |
1036 |
popDefaultClassLoader(old); |
|
1037 |
} |
|
1038 |
} |
|
1039 |
||
1040 |
||
1041 |
public String getDefaultDomain() |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1042 |
throws IOException { |
2 | 1043 |
if (logger.debugOn()) logger.debug("getDefaultDomain", ""); |
1044 |
||
1045 |
final ClassLoader old = pushDefaultClassLoader(); |
|
1046 |
try { |
|
1047 |
return connection.getDefaultDomain(delegationSubject); |
|
1048 |
} catch (IOException ioe) { |
|
1049 |
communicatorAdmin.gotIOException(ioe); |
|
1050 |
||
1051 |
return connection.getDefaultDomain(delegationSubject); |
|
1052 |
} finally { |
|
1053 |
popDefaultClassLoader(old); |
|
1054 |
} |
|
1055 |
} |
|
1056 |
||
1057 |
public String[] getDomains() throws IOException { |
|
1058 |
if (logger.debugOn()) logger.debug("getDomains", ""); |
|
1059 |
||
1060 |
final ClassLoader old = pushDefaultClassLoader(); |
|
1061 |
try { |
|
1062 |
return connection.getDomains(delegationSubject); |
|
1063 |
} catch (IOException ioe) { |
|
1064 |
communicatorAdmin.gotIOException(ioe); |
|
1065 |
||
1066 |
return connection.getDomains(delegationSubject); |
|
1067 |
} finally { |
|
1068 |
popDefaultClassLoader(old); |
|
1069 |
} |
|
1070 |
} |
|
1071 |
||
1072 |
public MBeanInfo getMBeanInfo(ObjectName name) |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1073 |
throws InstanceNotFoundException, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1074 |
IntrospectionException, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1075 |
ReflectionException, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1076 |
IOException { |
2 | 1077 |
|
1078 |
if (logger.debugOn()) logger.debug("getMBeanInfo", "name=" + name); |
|
1079 |
final ClassLoader old = pushDefaultClassLoader(); |
|
1080 |
try { |
|
1081 |
return connection.getMBeanInfo(name, delegationSubject); |
|
1082 |
} catch (IOException ioe) { |
|
1083 |
communicatorAdmin.gotIOException(ioe); |
|
1084 |
||
1085 |
return connection.getMBeanInfo(name, delegationSubject); |
|
1086 |
} finally { |
|
1087 |
popDefaultClassLoader(old); |
|
1088 |
} |
|
1089 |
} |
|
1090 |
||
1091 |
||
1092 |
public boolean isInstanceOf(ObjectName name, |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1093 |
String className) |
2 | 1094 |
throws InstanceNotFoundException, |
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1095 |
IOException { |
2 | 1096 |
if (logger.debugOn()) |
1097 |
logger.debug("isInstanceOf", "name=" + name + |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1098 |
", className=" + className); |
2 | 1099 |
|
1100 |
final ClassLoader old = pushDefaultClassLoader(); |
|
1101 |
try { |
|
1102 |
return connection.isInstanceOf(name, |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1103 |
className, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1104 |
delegationSubject); |
2 | 1105 |
} catch (IOException ioe) { |
1106 |
communicatorAdmin.gotIOException(ioe); |
|
1107 |
||
1108 |
return connection.isInstanceOf(name, |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1109 |
className, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1110 |
delegationSubject); |
2 | 1111 |
} finally { |
1112 |
popDefaultClassLoader(old); |
|
1113 |
} |
|
1114 |
} |
|
1115 |
||
1116 |
public void addNotificationListener(ObjectName name, |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1117 |
ObjectName listener, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1118 |
NotificationFilter filter, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1119 |
Object handback) |
2 | 1120 |
throws InstanceNotFoundException, |
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1121 |
IOException { |
2 | 1122 |
|
1123 |
if (logger.debugOn()) |
|
1124 |
logger.debug("addNotificationListener" + |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1125 |
"(ObjectName,ObjectName,NotificationFilter,Object)", |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1126 |
"name=" + name + ", listener=" + listener |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1127 |
+ ", filter=" + filter + ", handback=" + handback); |
2 | 1128 |
|
1129 |
final MarshalledObject<NotificationFilter> sFilter = |
|
1130 |
new MarshalledObject<NotificationFilter>(filter); |
|
1131 |
final MarshalledObject<Object> sHandback = |
|
1132 |
new MarshalledObject<Object>(handback); |
|
1133 |
final ClassLoader old = pushDefaultClassLoader(); |
|
1134 |
try { |
|
1135 |
connection.addNotificationListener(name, |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1136 |
listener, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1137 |
sFilter, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1138 |
sHandback, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1139 |
delegationSubject); |
2 | 1140 |
} catch (IOException ioe) { |
1141 |
communicatorAdmin.gotIOException(ioe); |
|
1142 |
||
1143 |
connection.addNotificationListener(name, |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1144 |
listener, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1145 |
sFilter, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1146 |
sHandback, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1147 |
delegationSubject); |
2 | 1148 |
} finally { |
1149 |
popDefaultClassLoader(old); |
|
1150 |
} |
|
1151 |
} |
|
1152 |
||
1153 |
public void removeNotificationListener(ObjectName name, |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1154 |
ObjectName listener) |
2 | 1155 |
throws InstanceNotFoundException, |
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1156 |
ListenerNotFoundException, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1157 |
IOException { |
2 | 1158 |
|
1159 |
if (logger.debugOn()) logger.debug("removeNotificationListener" + |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1160 |
"(ObjectName,ObjectName)", |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1161 |
"name=" + name |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1162 |
+ ", listener=" + listener); |
2 | 1163 |
|
1164 |
final ClassLoader old = pushDefaultClassLoader(); |
|
1165 |
try { |
|
1166 |
connection.removeNotificationListener(name, |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1167 |
listener, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1168 |
delegationSubject); |
2 | 1169 |
} catch (IOException ioe) { |
1170 |
communicatorAdmin.gotIOException(ioe); |
|
1171 |
||
1172 |
connection.removeNotificationListener(name, |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1173 |
listener, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1174 |
delegationSubject); |
2 | 1175 |
} finally { |
1176 |
popDefaultClassLoader(old); |
|
1177 |
} |
|
1178 |
} |
|
1179 |
||
1180 |
public void removeNotificationListener(ObjectName name, |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1181 |
ObjectName listener, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1182 |
NotificationFilter filter, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1183 |
Object handback) |
2 | 1184 |
throws InstanceNotFoundException, |
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1185 |
ListenerNotFoundException, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1186 |
IOException { |
2 | 1187 |
if (logger.debugOn()) |
1188 |
logger.debug("removeNotificationListener" + |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1189 |
"(ObjectName,ObjectName,NotificationFilter,Object)", |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1190 |
"name=" + name |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1191 |
+ ", listener=" + listener |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1192 |
+ ", filter=" + filter |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1193 |
+ ", handback=" + handback); |
2 | 1194 |
|
1195 |
final MarshalledObject<NotificationFilter> sFilter = |
|
1196 |
new MarshalledObject<NotificationFilter>(filter); |
|
1197 |
final MarshalledObject<Object> sHandback = |
|
1198 |
new MarshalledObject<Object>(handback); |
|
1199 |
final ClassLoader old = pushDefaultClassLoader(); |
|
1200 |
try { |
|
1201 |
connection.removeNotificationListener(name, |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1202 |
listener, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1203 |
sFilter, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1204 |
sHandback, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1205 |
delegationSubject); |
2 | 1206 |
} catch (IOException ioe) { |
1207 |
communicatorAdmin.gotIOException(ioe); |
|
1208 |
||
1209 |
connection.removeNotificationListener(name, |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1210 |
listener, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1211 |
sFilter, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1212 |
sHandback, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1213 |
delegationSubject); |
2 | 1214 |
} finally { |
1215 |
popDefaultClassLoader(old); |
|
1216 |
} |
|
1217 |
} |
|
1218 |
||
1219 |
// Specific Notification Handle ---------------------------------- |
|
1220 |
||
1221 |
public void addNotificationListener(ObjectName name, |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1222 |
NotificationListener listener, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1223 |
NotificationFilter filter, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1224 |
Object handback) |
2 | 1225 |
throws InstanceNotFoundException, |
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1226 |
IOException { |
2 | 1227 |
|
1228 |
final boolean debug = logger.debugOn(); |
|
1004 | 1229 |
|
2 | 1230 |
if (debug) |
1231 |
logger.debug("addNotificationListener" + |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1232 |
"(ObjectName,NotificationListener,"+ |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1233 |
"NotificationFilter,Object)", |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1234 |
"name=" + name |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1235 |
+ ", listener=" + listener |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1236 |
+ ", filter=" + filter |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1237 |
+ ", handback=" + handback); |
2 | 1238 |
|
1239 |
final Integer listenerID = |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1240 |
addListenerWithSubject(name, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1241 |
new MarshalledObject<NotificationFilter>(filter), |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1242 |
delegationSubject,true); |
2 | 1243 |
rmiNotifClient.addNotificationListener(listenerID, name, listener, |
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1244 |
filter, handback, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1245 |
delegationSubject); |
2 | 1246 |
} |
1247 |
||
1248 |
public void removeNotificationListener(ObjectName name, |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1249 |
NotificationListener listener) |
2 | 1250 |
throws InstanceNotFoundException, |
1004 | 1251 |
ListenerNotFoundException, |
1252 |
IOException { |
|
1253 |
||
2 | 1254 |
final boolean debug = logger.debugOn(); |
1255 |
||
1256 |
if (debug) logger.debug("removeNotificationListener"+ |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1257 |
"(ObjectName,NotificationListener)", |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1258 |
"name=" + name |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1259 |
+ ", listener=" + listener); |
2 | 1260 |
|
1261 |
final Integer[] ret = |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1262 |
rmiNotifClient.removeNotificationListener(name, listener); |
2 | 1263 |
|
1264 |
if (debug) logger.debug("removeNotificationListener", |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1265 |
"listenerIDs=" + objects(ret)); |
2 | 1266 |
|
1267 |
final ClassLoader old = pushDefaultClassLoader(); |
|
1268 |
||
1269 |
try { |
|
1270 |
connection.removeNotificationListeners(name, |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1271 |
ret, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1272 |
delegationSubject); |
2 | 1273 |
} catch (IOException ioe) { |
1274 |
communicatorAdmin.gotIOException(ioe); |
|
1275 |
||
1276 |
connection.removeNotificationListeners(name, |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1277 |
ret, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1278 |
delegationSubject); |
2 | 1279 |
} finally { |
1280 |
popDefaultClassLoader(old); |
|
1281 |
} |
|
1282 |
||
1283 |
} |
|
1284 |
||
1285 |
public void removeNotificationListener(ObjectName name, |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1286 |
NotificationListener listener, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1287 |
NotificationFilter filter, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1288 |
Object handback) |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1289 |
throws InstanceNotFoundException, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1290 |
ListenerNotFoundException, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1291 |
IOException { |
2 | 1292 |
final boolean debug = logger.debugOn(); |
1293 |
||
1294 |
if (debug) |
|
1295 |
logger.debug("removeNotificationListener"+ |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1296 |
"(ObjectName,NotificationListener,"+ |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1297 |
"NotificationFilter,Object)", |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1298 |
"name=" + name |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1299 |
+ ", listener=" + listener |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1300 |
+ ", filter=" + filter |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1301 |
+ ", handback=" + handback); |
2 | 1302 |
|
1303 |
final Integer ret = |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1304 |
rmiNotifClient.removeNotificationListener(name, listener, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1305 |
filter, handback); |
2 | 1306 |
|
1307 |
if (debug) logger.debug("removeNotificationListener", |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1308 |
"listenerID=" + ret); |
2 | 1309 |
|
1310 |
final ClassLoader old = pushDefaultClassLoader(); |
|
1311 |
try { |
|
1312 |
connection.removeNotificationListeners(name, |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1313 |
new Integer[] {ret}, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1314 |
delegationSubject); |
2 | 1315 |
} catch (IOException ioe) { |
1316 |
communicatorAdmin.gotIOException(ioe); |
|
1317 |
||
1318 |
connection.removeNotificationListeners(name, |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1319 |
new Integer[] {ret}, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1320 |
delegationSubject); |
2 | 1321 |
} finally { |
1322 |
popDefaultClassLoader(old); |
|
1323 |
} |
|
1324 |
||
1325 |
} |
|
1326 |
} |
|
1327 |
||
1328 |
//-------------------------------------------------------------------- |
|
1329 |
private class RMINotifClient extends ClientNotifForwarder { |
|
1510
e747d3193ef2
6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents:
1446
diff
changeset
|
1330 |
public RMINotifClient(ClassLoader cl, Map<String, ?> env) { |
2 | 1331 |
super(cl, env); |
1332 |
} |
|
1333 |
||
1334 |
protected NotificationResult fetchNotifs(long clientSequenceNumber, |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1335 |
int maxNotifications, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1336 |
long timeout) |
2 | 1337 |
throws IOException, ClassNotFoundException { |
1338 |
||
26594
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1339 |
boolean retried = false; |
2 | 1340 |
while (true) { // used for a successful re-connection |
26594
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1341 |
// or a transient network problem |
2 | 1342 |
try { |
1343 |
return connection.fetchNotifications(clientSequenceNumber, |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1344 |
maxNotifications, |
26594
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1345 |
timeout); // return normally |
2 | 1346 |
} catch (IOException ioe) { |
26594
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1347 |
// Examine the chain of exceptions to determine whether this |
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1348 |
// is a deserialization issue. If so - we propagate the |
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1349 |
// appropriate exception to the caller, who will then |
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1350 |
// proceed with fetching notifications one by one |
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1351 |
rethrowDeserializationException(ioe); |
2 | 1352 |
|
1353 |
try { |
|
1354 |
communicatorAdmin.gotIOException(ioe); |
|
26594
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1355 |
// reconnection OK, back to "while" to do again |
2 | 1356 |
} catch (IOException ee) { |
26594
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1357 |
boolean toClose = false; |
2 | 1358 |
|
26594
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1359 |
synchronized (this) { |
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1360 |
if (terminated) { |
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1361 |
// the connection is closed. |
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1362 |
throw ioe; |
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1363 |
} else if (retried) { |
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1364 |
toClose = true; |
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1365 |
} |
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1366 |
} |
2 | 1367 |
|
26594
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1368 |
if (toClose) { |
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1369 |
// JDK-8049303 |
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1370 |
// We received an IOException - but the communicatorAdmin |
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1371 |
// did not close the connection - possibly because |
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1372 |
// the original exception was raised by a transient network |
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1373 |
// problem? |
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1374 |
// We already know that this exception is not due to a deserialization |
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1375 |
// issue as we already took care of that before involving the |
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1376 |
// communicatorAdmin. Moreover - we already made one retry attempt |
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1377 |
// at fetching the same batch of notifications - and the |
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1378 |
// problem persisted. |
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1379 |
// Since trying again doesn't seem to solve the issue, we will now |
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1380 |
// close the connection. Doing otherwise might cause the |
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1381 |
// NotifFetcher thread to die silently. |
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1382 |
final Notification failedNotif = |
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1383 |
new JMXConnectionNotification( |
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1384 |
JMXConnectionNotification.FAILED, |
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1385 |
this, |
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1386 |
connectionId, |
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1387 |
clientNotifSeqNo++, |
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1388 |
"Failed to communicate with the server: " + ioe.toString(), |
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1389 |
ioe); |
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1390 |
|
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1391 |
sendNotification(failedNotif); |
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1392 |
|
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1393 |
try { |
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1394 |
close(true); |
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1395 |
} catch (Exception e) { |
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1396 |
// OK. |
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1397 |
// We are closing |
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1398 |
} |
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1399 |
throw ioe; // the connection is closed here. |
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1400 |
} else { |
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1401 |
// JDK-8049303 possible transient network problem, |
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1402 |
// let's try one more time |
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1403 |
retried = true; |
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1404 |
} |
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1405 |
} |
2 | 1406 |
} |
26594
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1407 |
} |
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1408 |
} |
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1409 |
|
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1410 |
private void rethrowDeserializationException(IOException ioe) |
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1411 |
throws ClassNotFoundException, IOException { |
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1412 |
// specially treating for an UnmarshalException |
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1413 |
if (ioe instanceof UnmarshalException) { |
43503
bc7f8619ab70
8173607: JMX RMI connector should be in its own module
dfuchs
parents:
40742
diff
changeset
|
1414 |
NotSerializableException nse = new NotSerializableException(); |
bc7f8619ab70
8173607: JMX RMI connector should be in its own module
dfuchs
parents:
40742
diff
changeset
|
1415 |
nse.initCause(ioe); |
bc7f8619ab70
8173607: JMX RMI connector should be in its own module
dfuchs
parents:
40742
diff
changeset
|
1416 |
throw nse; // the fix of 6937053 made ClientNotifForwarder.fetchNotifs |
26594
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1417 |
// fetch one by one with UnmarshalException |
2 | 1418 |
} |
1419 |
||
26594
b561a19107c7
8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents:
25859
diff
changeset
|
1420 |
// Not serialization problem, return. |
2 | 1421 |
} |
1422 |
||
1423 |
protected Integer addListenerForMBeanRemovedNotif() |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1424 |
throws IOException, InstanceNotFoundException { |
2 | 1425 |
NotificationFilterSupport clientFilter = |
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1426 |
new NotificationFilterSupport(); |
2 | 1427 |
clientFilter.enableType( |
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1428 |
MBeanServerNotification.UNREGISTRATION_NOTIFICATION); |
526
61ba2d5ea9da
6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents:
2
diff
changeset
|
1429 |
MarshalledObject<NotificationFilter> sFilter = |
61ba2d5ea9da
6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents:
2
diff
changeset
|
1430 |
new MarshalledObject<NotificationFilter>(clientFilter); |
2 | 1431 |
|
1432 |
Integer[] listenerIDs; |
|
1433 |
final ObjectName[] names = |
|
1434 |
new ObjectName[] {MBeanServerDelegate.DELEGATE_NAME}; |
|
1510
e747d3193ef2
6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents:
1446
diff
changeset
|
1435 |
final MarshalledObject<NotificationFilter>[] filters = |
e747d3193ef2
6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents:
1446
diff
changeset
|
1436 |
Util.cast(new MarshalledObject<?>[] {sFilter}); |
2 | 1437 |
final Subject[] subjects = new Subject[] {null}; |
1438 |
try { |
|
1439 |
listenerIDs = |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1440 |
connection.addNotificationListeners(names, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1441 |
filters, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1442 |
subjects); |
2 | 1443 |
|
1444 |
} catch (IOException ioe) { |
|
1445 |
communicatorAdmin.gotIOException(ioe); |
|
1446 |
||
1447 |
listenerIDs = |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1448 |
connection.addNotificationListeners(names, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1449 |
filters, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1450 |
subjects); |
2 | 1451 |
} |
1452 |
return listenerIDs[0]; |
|
1453 |
} |
|
1454 |
||
1455 |
protected void removeListenerForMBeanRemovedNotif(Integer id) |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1456 |
throws IOException, InstanceNotFoundException, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1457 |
ListenerNotFoundException { |
2 | 1458 |
try { |
1459 |
connection.removeNotificationListeners( |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1460 |
MBeanServerDelegate.DELEGATE_NAME, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1461 |
new Integer[] {id}, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1462 |
null); |
2 | 1463 |
} catch (IOException ioe) { |
1464 |
communicatorAdmin.gotIOException(ioe); |
|
1465 |
||
1466 |
connection.removeNotificationListeners( |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1467 |
MBeanServerDelegate.DELEGATE_NAME, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1468 |
new Integer[] {id}, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1469 |
null); |
2 | 1470 |
} |
1471 |
||
1472 |
} |
|
1473 |
||
1474 |
protected void lostNotifs(String message, long number) { |
|
1475 |
final String notifType = JMXConnectionNotification.NOTIFS_LOST; |
|
1476 |
||
1477 |
final JMXConnectionNotification n = |
|
1478 |
new JMXConnectionNotification(notifType, |
|
1479 |
RMIConnector.this, |
|
1480 |
connectionId, |
|
1481 |
clientNotifCounter++, |
|
1482 |
message, |
|
526
61ba2d5ea9da
6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents:
2
diff
changeset
|
1483 |
Long.valueOf(number)); |
2 | 1484 |
sendNotification(n); |
1485 |
} |
|
1486 |
} |
|
1487 |
||
1488 |
private class RMIClientCommunicatorAdmin extends ClientCommunicatorAdmin { |
|
1489 |
public RMIClientCommunicatorAdmin(long period) { |
|
1490 |
super(period); |
|
1491 |
} |
|
1492 |
||
4156 | 1493 |
@Override |
1446
605e30465515
6757225: MXBean: Incorrect type names for parametrized types, dealing with arrays
emcmanus
parents:
1229
diff
changeset
|
1494 |
public void gotIOException(IOException ioe) throws IOException { |
2 | 1495 |
if (ioe instanceof NoSuchObjectException) { |
1496 |
// need to restart |
|
1497 |
super.gotIOException(ioe); |
|
1498 |
||
1499 |
return; |
|
1500 |
} |
|
1501 |
||
1502 |
// check if the connection is broken |
|
1503 |
try { |
|
1504 |
connection.getDefaultDomain(null); |
|
1505 |
} catch (IOException ioexc) { |
|
1506 |
boolean toClose = false; |
|
1507 |
||
1508 |
synchronized(this) { |
|
1509 |
if (!terminated) { |
|
1510 |
terminated = true; |
|
1511 |
||
1512 |
toClose = true; |
|
1513 |
} |
|
1514 |
} |
|
1515 |
||
1516 |
if (toClose) { |
|
1517 |
// we should close the connection, |
|
1518 |
// but send a failed notif at first |
|
1519 |
final Notification failedNotif = |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1520 |
new JMXConnectionNotification( |
2 | 1521 |
JMXConnectionNotification.FAILED, |
1522 |
this, |
|
1523 |
connectionId, |
|
1524 |
clientNotifSeqNo++, |
|
1525 |
"Failed to communicate with the server: "+ioe.toString(), |
|
1526 |
ioe); |
|
1527 |
||
1528 |
sendNotification(failedNotif); |
|
1529 |
||
1530 |
try { |
|
1531 |
close(true); |
|
1532 |
} catch (Exception e) { |
|
1533 |
// OK. |
|
1534 |
// We are closing |
|
1535 |
} |
|
1536 |
} |
|
1537 |
} |
|
1538 |
||
1539 |
// forward the exception |
|
1540 |
if (ioe instanceof ServerException) { |
|
1541 |
/* Need to unwrap the exception. |
|
1542 |
Some user-thrown exception at server side will be wrapped by |
|
1543 |
rmi into a ServerException. |
|
1544 |
For example, a RMIConnnectorServer will wrap a |
|
1545 |
ClassNotFoundException into a UnmarshalException, and rmi |
|
1546 |
will throw a ServerException at client side which wraps this |
|
1547 |
UnmarshalException. |
|
1548 |
No failed notif here. |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1549 |
*/ |
2 | 1550 |
Throwable tt = ((ServerException)ioe).detail; |
1551 |
||
1552 |
if (tt instanceof IOException) { |
|
1553 |
throw (IOException)tt; |
|
1554 |
} else if (tt instanceof RuntimeException) { |
|
1555 |
throw (RuntimeException)tt; |
|
1556 |
} |
|
1557 |
} |
|
1558 |
||
1559 |
throw ioe; |
|
1560 |
} |
|
1561 |
||
1562 |
public void reconnectNotificationListeners(ClientListenerInfo[] old) throws IOException { |
|
1563 |
final int len = old.length; |
|
1564 |
int i; |
|
1565 |
||
1566 |
ClientListenerInfo[] clis = new ClientListenerInfo[len]; |
|
1567 |
||
1568 |
final Subject[] subjects = new Subject[len]; |
|
1569 |
final ObjectName[] names = new ObjectName[len]; |
|
1570 |
final NotificationListener[] listeners = new NotificationListener[len]; |
|
1571 |
final NotificationFilter[] filters = new NotificationFilter[len]; |
|
1510
e747d3193ef2
6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents:
1446
diff
changeset
|
1572 |
final MarshalledObject<NotificationFilter>[] mFilters = |
e747d3193ef2
6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents:
1446
diff
changeset
|
1573 |
Util.cast(new MarshalledObject<?>[len]); |
2 | 1574 |
final Object[] handbacks = new Object[len]; |
1575 |
||
1576 |
for (i=0;i<len;i++) { |
|
1577 |
subjects[i] = old[i].getDelegationSubject(); |
|
1578 |
names[i] = old[i].getObjectName(); |
|
1579 |
listeners[i] = old[i].getListener(); |
|
1580 |
filters[i] = old[i].getNotificationFilter(); |
|
1581 |
mFilters[i] = new MarshalledObject<NotificationFilter>(filters[i]); |
|
1582 |
handbacks[i] = old[i].getHandback(); |
|
1583 |
} |
|
1584 |
||
1585 |
try { |
|
1586 |
Integer[] ids = addListenersWithSubjects(names,mFilters,subjects,false); |
|
1587 |
||
1588 |
for (i=0;i<len;i++) { |
|
1589 |
clis[i] = new ClientListenerInfo(ids[i], |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1590 |
names[i], |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1591 |
listeners[i], |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1592 |
filters[i], |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1593 |
handbacks[i], |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1594 |
subjects[i]); |
2 | 1595 |
} |
1596 |
||
1597 |
rmiNotifClient.postReconnection(clis); |
|
1598 |
||
1599 |
return; |
|
1600 |
} catch (InstanceNotFoundException infe) { |
|
1601 |
// OK, we will do one by one |
|
1602 |
} |
|
1603 |
||
1604 |
int j = 0; |
|
1605 |
for (i=0;i<len;i++) { |
|
1606 |
try { |
|
1607 |
Integer id = addListenerWithSubject(names[i], |
|
1608 |
new MarshalledObject<NotificationFilter>(filters[i]), |
|
1609 |
subjects[i], |
|
1610 |
false); |
|
1611 |
||
1612 |
clis[j++] = new ClientListenerInfo(id, |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1613 |
names[i], |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1614 |
listeners[i], |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1615 |
filters[i], |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1616 |
handbacks[i], |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1617 |
subjects[i]); |
2 | 1618 |
} catch (InstanceNotFoundException infe) { |
1619 |
logger.warning("reconnectNotificationListeners", |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1620 |
"Can't reconnect listener for " + |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1621 |
names[i]); |
2 | 1622 |
} |
1623 |
} |
|
1624 |
||
1625 |
if (j != len) { |
|
1626 |
ClientListenerInfo[] tmp = clis; |
|
1627 |
clis = new ClientListenerInfo[j]; |
|
1628 |
System.arraycopy(tmp, 0, clis, 0, j); |
|
1629 |
} |
|
1630 |
||
1631 |
rmiNotifClient.postReconnection(clis); |
|
1632 |
} |
|
1633 |
||
1634 |
protected void checkConnection() throws IOException { |
|
1635 |
if (logger.debugOn()) |
|
1636 |
logger.debug("RMIClientCommunicatorAdmin-checkConnection", |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1637 |
"Calling the method getDefaultDomain."); |
2 | 1638 |
|
1639 |
connection.getDefaultDomain(null); |
|
1640 |
} |
|
1641 |
||
1642 |
protected void doStart() throws IOException { |
|
1643 |
// Get RMIServer stub from directory or URL encoding if needed. |
|
526
61ba2d5ea9da
6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents:
2
diff
changeset
|
1644 |
RMIServer stub; |
2 | 1645 |
try { |
1646 |
stub = (rmiServer!=null)?rmiServer: |
|
1647 |
findRMIServer(jmxServiceURL, env); |
|
1648 |
} catch (NamingException ne) { |
|
1649 |
throw new IOException("Failed to get a RMI stub: "+ne); |
|
1650 |
} |
|
1651 |
||
1652 |
// Calling newClient on the RMIServer stub. |
|
1653 |
Object credentials = env.get(CREDENTIALS); |
|
1654 |
connection = stub.newClient(credentials); |
|
1655 |
||
1656 |
// notif issues |
|
1657 |
final ClientListenerInfo[] old = rmiNotifClient.preReconnection(); |
|
1658 |
||
1659 |
reconnectNotificationListeners(old); |
|
1660 |
||
1661 |
connectionId = getConnectionId(); |
|
1662 |
||
1663 |
Notification reconnectedNotif = |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1664 |
new JMXConnectionNotification(JMXConnectionNotification.OPENED, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1665 |
this, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1666 |
connectionId, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1667 |
clientNotifSeqNo++, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1668 |
"Reconnected to server", |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1669 |
null); |
2 | 1670 |
sendNotification(reconnectedNotif); |
1671 |
||
1672 |
} |
|
1673 |
||
1674 |
protected void doStop() { |
|
1675 |
try { |
|
1676 |
close(); |
|
1677 |
} catch (IOException ioe) { |
|
1678 |
logger.warning("RMIClientCommunicatorAdmin-doStop", |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1679 |
"Failed to call the method close():" + ioe); |
2 | 1680 |
logger.debug("RMIClientCommunicatorAdmin-doStop",ioe); |
1681 |
} |
|
1682 |
} |
|
1683 |
} |
|
1684 |
||
1685 |
//-------------------------------------------------------------------- |
|
1686 |
// Private stuff - Serialization |
|
1687 |
//-------------------------------------------------------------------- |
|
1688 |
/** |
|
1689 |
* Read RMIConnector fields from an {@link java.io.ObjectInputStream |
|
1690 |
* ObjectInputStream}. |
|
32034
05676cfd40b5
8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents:
26594
diff
changeset
|
1691 |
* Calls {@code s.defaultReadObject()} and then initializes |
2 | 1692 |
* all transient variables that need initializing. |
1693 |
* @param s The ObjectInputStream to read from. |
|
1694 |
* @exception InvalidObjectException if none of <var>rmiServer</var> stub |
|
1695 |
* or <var>jmxServiceURL</var> are set. |
|
1696 |
* @see #RMIConnector(JMXServiceURL,Map) |
|
1697 |
* @see #RMIConnector(RMIServer,Map) |
|
1698 |
**/ |
|
1699 |
private void readObject(java.io.ObjectInputStream s) |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1700 |
throws IOException, ClassNotFoundException { |
2 | 1701 |
s.defaultReadObject(); |
1702 |
||
1703 |
if (rmiServer == null && jmxServiceURL == null) throw new |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1704 |
InvalidObjectException("rmiServer and jmxServiceURL both null"); |
2 | 1705 |
|
1706 |
initTransients(); |
|
1707 |
} |
|
1708 |
||
1709 |
/** |
|
1710 |
* Writes the RMIConnector fields to an {@link java.io.ObjectOutputStream |
|
1711 |
* ObjectOutputStream}. |
|
1712 |
* <p>Connects the underlying RMIServer stub to an ORB, if needed, |
|
1713 |
* before serializing it. This is done using the environment |
|
1714 |
* map that was provided to the constructor, if any, and as documented |
|
1715 |
* in {@link javax.management.remote.rmi}.</p> |
|
32034
05676cfd40b5
8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents:
26594
diff
changeset
|
1716 |
* <p>This method then calls {@code s.defaultWriteObject()}. |
2 | 1717 |
* Usually, <var>rmiServer</var> is null if this object |
1718 |
* was constructed with a JMXServiceURL, and <var>jmxServiceURL</var> |
|
1719 |
* is null if this object is constructed with a RMIServer stub. |
|
1720 |
* <p>Note that the environment Map is not serialized, since the objects |
|
1721 |
* it contains are assumed to be contextual and relevant only |
|
1722 |
* with respect to the local environment (class loader, ORB, etc...).</p> |
|
1723 |
* <p>After an RMIConnector is deserialized, it is assumed that the |
|
1724 |
* user will call {@link #connect(Map)}, providing a new Map that |
|
1725 |
* can contain values which are contextually relevant to the new |
|
1726 |
* local environment.</p> |
|
1727 |
* <p>Since connection to the ORB is needed prior to serializing, and |
|
1728 |
* since the ORB to connect to is one of those contextual parameters, |
|
1729 |
* it is not recommended to re-serialize a just de-serialized object - |
|
1730 |
* as the de-serialized object has no map. Thus, when an RMIConnector |
|
1731 |
* object is needed for serialization or transmission to a remote |
|
1732 |
* application, it is recommended to obtain a new RMIConnector stub |
|
1733 |
* by calling {@link RMIConnectorServer#toJMXConnector(Map)}.</p> |
|
1734 |
* @param s The ObjectOutputStream to write to. |
|
1735 |
* @exception InvalidObjectException if none of <var>rmiServer</var> stub |
|
1736 |
* or <var>jmxServiceURL</var> are set. |
|
1737 |
* @see #RMIConnector(JMXServiceURL,Map) |
|
1738 |
* @see #RMIConnector(RMIServer,Map) |
|
1739 |
**/ |
|
1740 |
private void writeObject(java.io.ObjectOutputStream s) |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1741 |
throws IOException { |
2 | 1742 |
if (rmiServer == null && jmxServiceURL == null) throw new |
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1743 |
InvalidObjectException("rmiServer and jmxServiceURL both null."); |
2 | 1744 |
s.defaultWriteObject(); |
1745 |
} |
|
1746 |
||
1747 |
// Initialization of transient variables. |
|
1748 |
private void initTransients() { |
|
19791
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
18206
diff
changeset
|
1749 |
rmbscMap = new WeakHashMap<Subject, WeakReference<MBeanServerConnection>>(); |
2 | 1750 |
connected = false; |
1751 |
terminated = false; |
|
1752 |
||
1753 |
connectionBroadcaster = new NotificationBroadcasterSupport(); |
|
1754 |
} |
|
1755 |
||
1756 |
//-------------------------------------------------------------------- |
|
1757 |
// Private stuff - Check if stub can be trusted. |
|
1758 |
//-------------------------------------------------------------------- |
|
1759 |
||
1760 |
private static void checkStub(Remote stub, |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1761 |
Class<?> stubClass) { |
2 | 1762 |
|
1763 |
// Check remote stub is from the expected class. |
|
1764 |
// |
|
1765 |
if (stub.getClass() != stubClass) { |
|
1766 |
if (!Proxy.isProxyClass(stub.getClass())) { |
|
1767 |
throw new SecurityException( |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1768 |
"Expecting a " + stubClass.getName() + " stub!"); |
2 | 1769 |
} else { |
1770 |
InvocationHandler handler = Proxy.getInvocationHandler(stub); |
|
1771 |
if (handler.getClass() != RemoteObjectInvocationHandler.class) |
|
1772 |
throw new SecurityException( |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1773 |
"Expecting a dynamic proxy instance with a " + |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1774 |
RemoteObjectInvocationHandler.class.getName() + |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1775 |
" invocation handler!"); |
2 | 1776 |
else |
1777 |
stub = (Remote) handler; |
|
1778 |
} |
|
1779 |
} |
|
1780 |
||
1781 |
// Check RemoteRef in stub is from the expected class |
|
1782 |
// "sun.rmi.server.UnicastRef2". |
|
1783 |
// |
|
1784 |
RemoteRef ref = ((RemoteObject)stub).getRef(); |
|
1785 |
if (ref.getClass() != UnicastRef2.class) |
|
1786 |
throw new SecurityException( |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1787 |
"Expecting a " + UnicastRef2.class.getName() + |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1788 |
" remote reference in stub!"); |
2 | 1789 |
|
1790 |
// Check RMIClientSocketFactory in stub is from the expected class |
|
1791 |
// "javax.rmi.ssl.SslRMIClientSocketFactory". |
|
1792 |
// |
|
1793 |
LiveRef liveRef = ((UnicastRef2)ref).getLiveRef(); |
|
1794 |
RMIClientSocketFactory csf = liveRef.getClientSocketFactory(); |
|
1795 |
if (csf == null || csf.getClass() != SslRMIClientSocketFactory.class) |
|
1796 |
throw new SecurityException( |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1797 |
"Expecting a " + SslRMIClientSocketFactory.class.getName() + |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1798 |
" RMI client socket factory in stub!"); |
2 | 1799 |
} |
1800 |
||
1801 |
//-------------------------------------------------------------------- |
|
1802 |
// Private stuff - RMIServer creation |
|
1803 |
//-------------------------------------------------------------------- |
|
1804 |
||
1805 |
private RMIServer findRMIServer(JMXServiceURL directoryURL, |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1806 |
Map<String, Object> environment) |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1807 |
throws NamingException, IOException { |
2 | 1808 |
|
1809 |
String path = directoryURL.getURLPath(); |
|
1810 |
int end = path.indexOf(';'); |
|
1811 |
if (end < 0) end = path.length(); |
|
1812 |
if (path.startsWith("/jndi/")) |
|
32639
339de1317e84
8043937: Drop support for the IIOP transport from the JMX RMIConnector
jbachorik
parents:
32034
diff
changeset
|
1813 |
return findRMIServerJNDI(path.substring(6,end), environment); |
2 | 1814 |
else if (path.startsWith("/stub/")) |
32639
339de1317e84
8043937: Drop support for the IIOP transport from the JMX RMIConnector
jbachorik
parents:
32034
diff
changeset
|
1815 |
return findRMIServerJRMP(path.substring(6,end), environment); |
339de1317e84
8043937: Drop support for the IIOP transport from the JMX RMIConnector
jbachorik
parents:
32034
diff
changeset
|
1816 |
else { |
2 | 1817 |
final String msg = "URL path must begin with /jndi/ or /stub/ " + |
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1818 |
"or /ior/: " + path; |
2 | 1819 |
throw new MalformedURLException(msg); |
1820 |
} |
|
1821 |
} |
|
1822 |
||
1823 |
/** |
|
1824 |
* Lookup the RMIServer stub in a directory. |
|
1825 |
* @param jndiURL A JNDI URL indicating the location of the Stub |
|
1826 |
* (see {@link javax.management.remote.rmi}), e.g.: |
|
32034
05676cfd40b5
8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents:
26594
diff
changeset
|
1827 |
* <ul><li>{@code rmi://registry-host:port/rmi-stub-name}</li> |
05676cfd40b5
8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents:
26594
diff
changeset
|
1828 |
* <li>or {@code ldap://ldap-host:port/java-container-dn}</li> |
2 | 1829 |
* </ul> |
1830 |
* @param env the environment Map passed to the connector. |
|
1831 |
* @return The retrieved RMIServer stub. |
|
1832 |
* @exception NamingException if the stub couldn't be found. |
|
1833 |
**/ |
|
32639
339de1317e84
8043937: Drop support for the IIOP transport from the JMX RMIConnector
jbachorik
parents:
32034
diff
changeset
|
1834 |
private RMIServer findRMIServerJNDI(String jndiURL, Map<String, ?> env) |
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1835 |
throws NamingException { |
2 | 1836 |
|
1837 |
InitialContext ctx = new InitialContext(EnvHelp.mapToHashtable(env)); |
|
1838 |
||
1839 |
Object objref = ctx.lookup(jndiURL); |
|
1840 |
ctx.close(); |
|
1841 |
||
32639
339de1317e84
8043937: Drop support for the IIOP transport from the JMX RMIConnector
jbachorik
parents:
32034
diff
changeset
|
1842 |
return narrowJRMPServer(objref); |
2 | 1843 |
} |
1844 |
||
1845 |
private static RMIServer narrowJRMPServer(Object objref) { |
|
1846 |
||
1847 |
return (RMIServer) objref; |
|
1848 |
} |
|
1849 |
||
32639
339de1317e84
8043937: Drop support for the IIOP transport from the JMX RMIConnector
jbachorik
parents:
32034
diff
changeset
|
1850 |
private RMIServer findRMIServerJRMP(String base64, Map<String, ?> env) |
2 | 1851 |
throws IOException { |
1852 |
final byte[] serialized; |
|
1853 |
try { |
|
1854 |
serialized = base64ToByteArray(base64); |
|
1855 |
} catch (IllegalArgumentException e) { |
|
1856 |
throw new MalformedURLException("Bad BASE64 encoding: " + |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1857 |
e.getMessage()); |
2 | 1858 |
} |
1859 |
final ByteArrayInputStream bin = new ByteArrayInputStream(serialized); |
|
1860 |
||
1861 |
final ClassLoader loader = EnvHelp.resolveClientClassLoader(env); |
|
1862 |
final ObjectInputStream oin = |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1863 |
(loader == null) ? |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1864 |
new ObjectInputStream(bin) : |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1865 |
new ObjectInputStreamWithLoader(bin, loader); |
2 | 1866 |
final Object stub; |
1867 |
try { |
|
1868 |
stub = oin.readObject(); |
|
1869 |
} catch (ClassNotFoundException e) { |
|
1870 |
throw new MalformedURLException("Class not found: " + e); |
|
1871 |
} |
|
4167 | 1872 |
return (RMIServer)stub; |
2 | 1873 |
} |
1874 |
||
1875 |
private static final class ObjectInputStreamWithLoader |
|
1876 |
extends ObjectInputStream { |
|
1877 |
ObjectInputStreamWithLoader(InputStream in, ClassLoader cl) |
|
40742
3697a4ff4721
8164730: Make it clear that 'cl' parameter passed to RMIConnector.OISWL is never null.
vtewari
parents:
36511
diff
changeset
|
1878 |
throws IOException, IllegalArgumentException { |
2 | 1879 |
super(in); |
40742
3697a4ff4721
8164730: Make it clear that 'cl' parameter passed to RMIConnector.OISWL is never null.
vtewari
parents:
36511
diff
changeset
|
1880 |
if (cl == null ) { |
3697a4ff4721
8164730: Make it clear that 'cl' parameter passed to RMIConnector.OISWL is never null.
vtewari
parents:
36511
diff
changeset
|
1881 |
throw new IllegalArgumentException("class loader is null"); |
3697a4ff4721
8164730: Make it clear that 'cl' parameter passed to RMIConnector.OISWL is never null.
vtewari
parents:
36511
diff
changeset
|
1882 |
} |
2 | 1883 |
this.loader = cl; |
1884 |
} |
|
1885 |
||
1510
e747d3193ef2
6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents:
1446
diff
changeset
|
1886 |
@Override |
e747d3193ef2
6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents:
1446
diff
changeset
|
1887 |
protected Class<?> resolveClass(ObjectStreamClass classDesc) |
2 | 1888 |
throws IOException, ClassNotFoundException { |
18206 | 1889 |
String name = classDesc.getName(); |
1890 |
ReflectUtil.checkPackageAccess(name); |
|
40742
3697a4ff4721
8164730: Make it clear that 'cl' parameter passed to RMIConnector.OISWL is never null.
vtewari
parents:
36511
diff
changeset
|
1891 |
return Class.forName(name, false, Objects.requireNonNull(loader)); |
2 | 1892 |
} |
1893 |
||
1894 |
private final ClassLoader loader; |
|
1895 |
} |
|
1896 |
||
19791
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
18206
diff
changeset
|
1897 |
private MBeanServerConnection getConnectionWithSubject(Subject delegationSubject) { |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
18206
diff
changeset
|
1898 |
MBeanServerConnection conn = null; |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
18206
diff
changeset
|
1899 |
|
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
18206
diff
changeset
|
1900 |
if (delegationSubject == null) { |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
18206
diff
changeset
|
1901 |
if (nullSubjectConnRef == null |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
18206
diff
changeset
|
1902 |
|| (conn = nullSubjectConnRef.get()) == null) { |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
18206
diff
changeset
|
1903 |
conn = new RemoteMBeanServerConnection(null); |
24871
224e298c3978
8044865: Fix raw and unchecked lint warnings in management-related code
sjiang
parents:
21656
diff
changeset
|
1904 |
nullSubjectConnRef = new WeakReference<MBeanServerConnection>(conn); |
19791
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
18206
diff
changeset
|
1905 |
} |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
18206
diff
changeset
|
1906 |
} else { |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
18206
diff
changeset
|
1907 |
WeakReference<MBeanServerConnection> wr = rmbscMap.get(delegationSubject); |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
18206
diff
changeset
|
1908 |
if (wr == null || (conn = wr.get()) == null) { |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
18206
diff
changeset
|
1909 |
conn = new RemoteMBeanServerConnection(delegationSubject); |
24871
224e298c3978
8044865: Fix raw and unchecked lint warnings in management-related code
sjiang
parents:
21656
diff
changeset
|
1910 |
rmbscMap.put(delegationSubject, new WeakReference<MBeanServerConnection>(conn)); |
19791
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
18206
diff
changeset
|
1911 |
} |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
18206
diff
changeset
|
1912 |
} |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
18206
diff
changeset
|
1913 |
return conn; |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
18206
diff
changeset
|
1914 |
} |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
18206
diff
changeset
|
1915 |
|
2 | 1916 |
/* |
1917 |
The following section of code avoids a class loading problem |
|
1918 |
with RMI. The problem is that an RMI stub, when deserializing |
|
1919 |
a remote method return value or exception, will first of all |
|
1920 |
consult the first non-bootstrap class loader it finds in the |
|
1921 |
call stack. This can lead to behavior that is not portable |
|
1922 |
between implementations of the JMX Remote API. Notably, an |
|
1923 |
implementation on J2SE 1.4 will find the RMI stub's loader on |
|
1924 |
the stack. But in J2SE 5, this stub is loaded by the |
|
1925 |
bootstrap loader, so RMI will find the loader of the user code |
|
1926 |
that called an MBeanServerConnection method. |
|
1927 |
||
1928 |
To avoid this problem, we take advantage of what the RMI stub |
|
1929 |
is doing internally. Each remote call will end up calling |
|
1930 |
ref.invoke(...), where ref is the RemoteRef parameter given to |
|
1931 |
the RMI stub's constructor. It is within this call that the |
|
1932 |
deserialization will happen. So we fabricate our own RemoteRef |
|
1933 |
that delegates everything to the "real" one but that is loaded |
|
1934 |
by a class loader that knows no other classes. The class |
|
1935 |
loader NoCallStackClassLoader does this: the RemoteRef is an |
|
1936 |
instance of the class named by proxyRefClassName, which is |
|
1937 |
fabricated by the class loader using byte code that is defined |
|
1938 |
by the string below. |
|
1939 |
||
1940 |
The call stack when the deserialization happens is thus this: |
|
1941 |
MBeanServerConnection.getAttribute (or whatever) |
|
1942 |
-> RMIConnectionImpl_Stub.getAttribute |
|
1943 |
-> ProxyRef.invoke(...getAttribute...) |
|
1944 |
-> UnicastRef.invoke(...getAttribute...) |
|
1945 |
-> internal RMI stuff |
|
1946 |
||
1947 |
Here UnicastRef is the RemoteRef created when the stub was |
|
1948 |
deserialized (which is of some RMI internal class). It and the |
|
1949 |
"internal RMI stuff" are loaded by the bootstrap loader, so are |
|
1950 |
transparent to the stack search. The first non-bootstrap |
|
1951 |
loader found is our ProxyRefLoader, as required. |
|
1952 |
||
1953 |
In a future version of this code as integrated into J2SE 5, |
|
1954 |
this workaround could be replaced by direct access to the |
|
1955 |
internals of RMI. For now, we use the same code base for J2SE |
|
1956 |
and for the standalone Reference Implementation. |
|
1957 |
||
1958 |
The byte code below encodes the following class, compiled using |
|
1959 |
J2SE 1.4.2 with the -g:none option. |
|
1960 |
||
43503
bc7f8619ab70
8173607: JMX RMI connector should be in its own module
dfuchs
parents:
40742
diff
changeset
|
1961 |
package jdk.jmx.remote.internal.rmi; |
2 | 1962 |
|
1963 |
import java.lang.reflect.Method; |
|
1964 |
import java.rmi.Remote; |
|
1965 |
import java.rmi.server.RemoteRef; |
|
43503
bc7f8619ab70
8173607: JMX RMI connector should be in its own module
dfuchs
parents:
40742
diff
changeset
|
1966 |
import com.sun.jmx.remote.internal.rmi.ProxyRef; |
2 | 1967 |
|
1968 |
public class PRef extends ProxyRef { |
|
1969 |
public PRef(RemoteRef ref) { |
|
1970 |
super(ref); |
|
1971 |
} |
|
1972 |
||
1973 |
public Object invoke(Remote obj, Method method, |
|
1974 |
Object[] params, long opnum) |
|
1975 |
throws Exception { |
|
1976 |
return ref.invoke(obj, method, params, opnum); |
|
1977 |
} |
|
1978 |
} |
|
1979 |
*/ |
|
1980 |
||
1981 |
private static final String rmiServerImplStubClassName = |
|
1982 |
RMIServer.class.getName() + "Impl_Stub"; |
|
1510
e747d3193ef2
6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents:
1446
diff
changeset
|
1983 |
private static final Class<?> rmiServerImplStubClass; |
2 | 1984 |
private static final String rmiConnectionImplStubClassName = |
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
1985 |
RMIConnection.class.getName() + "Impl_Stub"; |
2 | 1986 |
private static final Class<?> rmiConnectionImplStubClass; |
1987 |
private static final String pRefClassName = |
|
43503
bc7f8619ab70
8173607: JMX RMI connector should be in its own module
dfuchs
parents:
40742
diff
changeset
|
1988 |
"jdk.jmx.remote.internal.rmi.PRef"; |
1510
e747d3193ef2
6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents:
1446
diff
changeset
|
1989 |
private static final Constructor<?> proxyRefConstructor; |
2 | 1990 |
static { |
1991 |
final String pRefByteCodeString = |
|
43503
bc7f8619ab70
8173607: JMX RMI connector should be in its own module
dfuchs
parents:
40742
diff
changeset
|
1992 |
"\312\376\272\276\0\0\0\65\0\27\12\0\5\0\15\11\0\4\0\16\13\0\17"+ |
36511 | 1993 |
"\0\20\7\0\21\7\0\22\1\0\6<init>\1\0\36(Ljava/rmi/server/Remote"+ |
1994 |
"Ref;)V\1\0\4Code\1\0\6invoke\1\0S(Ljava/rmi/Remote;Ljava/lang/"+ |
|
1995 |
"reflect/Method;[Ljava/lang/Object;J)Ljava/lang/Object;\1\0\12E"+ |
|
1996 |
"xceptions\7\0\23\14\0\6\0\7\14\0\24\0\25\7\0\26\14\0\11\0\12\1"+ |
|
43503
bc7f8619ab70
8173607: JMX RMI connector should be in its own module
dfuchs
parents:
40742
diff
changeset
|
1997 |
"\0 jdk/jmx/remote/internal/rmi/PRef\1\0(com/sun/jmx/remote/int"+ |
bc7f8619ab70
8173607: JMX RMI connector should be in its own module
dfuchs
parents:
40742
diff
changeset
|
1998 |
"ernal/rmi/ProxyRef\1\0\23java/lang/Exception\1\0\3ref\1\0\33Lj"+ |
bc7f8619ab70
8173607: JMX RMI connector should be in its own module
dfuchs
parents:
40742
diff
changeset
|
1999 |
"ava/rmi/server/RemoteRef;\1\0\31java/rmi/server/RemoteRef\0!\0"+ |
bc7f8619ab70
8173607: JMX RMI connector should be in its own module
dfuchs
parents:
40742
diff
changeset
|
2000 |
"\4\0\5\0\0\0\0\0\2\0\1\0\6\0\7\0\1\0\10\0\0\0\22\0\2\0\2\0\0\0"+ |
bc7f8619ab70
8173607: JMX RMI connector should be in its own module
dfuchs
parents:
40742
diff
changeset
|
2001 |
"\6*+\267\0\1\261\0\0\0\0\0\1\0\11\0\12\0\2\0\10\0\0\0\33\0\6\0"+ |
bc7f8619ab70
8173607: JMX RMI connector should be in its own module
dfuchs
parents:
40742
diff
changeset
|
2002 |
"\6\0\0\0\17*\264\0\2+,-\26\4\271\0\3\6\0\260\0\0\0\0\0\13\0\0\0"+ |
bc7f8619ab70
8173607: JMX RMI connector should be in its own module
dfuchs
parents:
40742
diff
changeset
|
2003 |
"\4\0\1\0\14\0\0"; |
2 | 2004 |
final byte[] pRefByteCode = |
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
2005 |
NoCallStackClassLoader.stringToBytes(pRefByteCodeString); |
2 | 2006 |
PrivilegedExceptionAction<Constructor<?>> action = |
2007 |
new PrivilegedExceptionAction<Constructor<?>>() { |
|
2008 |
public Constructor<?> run() throws Exception { |
|
24871
224e298c3978
8044865: Fix raw and unchecked lint warnings in management-related code
sjiang
parents:
21656
diff
changeset
|
2009 |
Class<RMIConnector> thisClass = RMIConnector.class; |
2 | 2010 |
ClassLoader thisLoader = thisClass.getClassLoader(); |
2011 |
ProtectionDomain thisProtectionDomain = |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
2012 |
thisClass.getProtectionDomain(); |
36511 | 2013 |
|
2014 |
String proxyRefCName = ProxyRef.class.getName(); |
|
2 | 2015 |
ClassLoader cl = |
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
2016 |
new NoCallStackClassLoader(pRefClassName, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
2017 |
pRefByteCode, |
36511 | 2018 |
new String[] { proxyRefCName }, |
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
2019 |
thisLoader, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
2020 |
thisProtectionDomain); |
36511 | 2021 |
|
2022 |
Module jmxModule = ProxyRef.class.getModule(); |
|
2023 |
Module rmiModule = RemoteRef.class.getModule(); |
|
2024 |
||
2025 |
String pkg = packageOf(pRefClassName); |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
43503
diff
changeset
|
2026 |
assert pkg != null && pkg.length() > 0 && |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
43503
diff
changeset
|
2027 |
!pkg.equals(packageOf(proxyRefCName)); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
43503
diff
changeset
|
2028 |
|
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
43503
diff
changeset
|
2029 |
ModuleDescriptor descriptor = |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
43503
diff
changeset
|
2030 |
ModuleDescriptor.newModule("jdk.remoteref", Set.of(SYNTHETIC)) |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
43503
diff
changeset
|
2031 |
.packages(Set.of(pkg)) |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
43503
diff
changeset
|
2032 |
.build(); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
43503
diff
changeset
|
2033 |
Module m = Modules.defineModule(cl, descriptor, null); |
36511 | 2034 |
|
2035 |
// jdk.remoteref needs to read to java.base and jmxModule |
|
2036 |
Modules.addReads(m, Object.class.getModule()); |
|
2037 |
Modules.addReads(m, jmxModule); |
|
2038 |
Modules.addReads(m, rmiModule); |
|
2039 |
||
2040 |
// jdk.remoteref needs access to ProxyRef class |
|
2041 |
Modules.addExports(jmxModule, packageOf(proxyRefCName), m); |
|
2042 |
||
2043 |
// java.management needs to instantiate the fabricated RemoteRef class |
|
2044 |
Modules.addReads(jmxModule, m); |
|
2045 |
Modules.addExports(m, pkg, jmxModule); |
|
2046 |
||
2 | 2047 |
Class<?> c = cl.loadClass(pRefClassName); |
2048 |
return c.getConstructor(RemoteRef.class); |
|
2049 |
} |
|
2050 |
}; |
|
2051 |
||
1510
e747d3193ef2
6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents:
1446
diff
changeset
|
2052 |
Class<?> serverStubClass; |
2 | 2053 |
try { |
2054 |
serverStubClass = Class.forName(rmiServerImplStubClassName); |
|
2055 |
} catch (Exception e) { |
|
2056 |
logger.error("<clinit>", |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
2057 |
"Failed to instantiate " + |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
2058 |
rmiServerImplStubClassName + ": " + e); |
2 | 2059 |
logger.debug("<clinit>",e); |
2060 |
serverStubClass = null; |
|
2061 |
} |
|
2062 |
rmiServerImplStubClass = serverStubClass; |
|
2063 |
||
2064 |
Class<?> stubClass; |
|
1510
e747d3193ef2
6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents:
1446
diff
changeset
|
2065 |
Constructor<?> constr; |
2 | 2066 |
try { |
2067 |
stubClass = Class.forName(rmiConnectionImplStubClassName); |
|
1510
e747d3193ef2
6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents:
1446
diff
changeset
|
2068 |
constr = (Constructor<?>) AccessController.doPrivileged(action); |
2 | 2069 |
} catch (Exception e) { |
2070 |
logger.error("<clinit>", |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
2071 |
"Failed to initialize proxy reference constructor "+ |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
2072 |
"for " + rmiConnectionImplStubClassName + ": " + e); |
2 | 2073 |
logger.debug("<clinit>",e); |
2074 |
stubClass = null; |
|
2075 |
constr = null; |
|
2076 |
} |
|
2077 |
rmiConnectionImplStubClass = stubClass; |
|
2078 |
proxyRefConstructor = constr; |
|
2079 |
} |
|
2080 |
||
36511 | 2081 |
private static String packageOf(String cn) { |
2082 |
int i = cn.lastIndexOf('.'); |
|
2083 |
return i > 0 ? cn.substring(0, i) : ""; |
|
2084 |
} |
|
2085 |
||
2 | 2086 |
private static RMIConnection shadowJrmpStub(RemoteObject stub) |
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
2087 |
throws InstantiationException, IllegalAccessException, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
2088 |
InvocationTargetException, ClassNotFoundException, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
2089 |
NoSuchMethodException { |
2 | 2090 |
RemoteRef ref = stub.getRef(); |
2091 |
RemoteRef proxyRef = (RemoteRef) |
|
2092 |
proxyRefConstructor.newInstance(new Object[] {ref}); |
|
1510
e747d3193ef2
6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents:
1446
diff
changeset
|
2093 |
final Constructor<?> rmiConnectionImplStubConstructor = |
e747d3193ef2
6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents:
1446
diff
changeset
|
2094 |
rmiConnectionImplStubClass.getConstructor(RemoteRef.class); |
2 | 2095 |
Object[] args = {proxyRef}; |
2096 |
RMIConnection proxyStub = (RMIConnection) |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
2097 |
rmiConnectionImplStubConstructor.newInstance(args); |
2 | 2098 |
return proxyStub; |
2099 |
} |
|
2100 |
||
2101 |
private static RMIConnection getConnection(RMIServer server, |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
2102 |
Object credentials, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
2103 |
boolean checkStub) |
2 | 2104 |
throws IOException { |
2105 |
RMIConnection c = server.newClient(credentials); |
|
2106 |
if (checkStub) checkStub(c, rmiConnectionImplStubClass); |
|
2107 |
try { |
|
2108 |
if (c.getClass() == rmiConnectionImplStubClass) |
|
2109 |
return shadowJrmpStub((RemoteObject) c); |
|
2110 |
logger.trace("getConnection", |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
2111 |
"Did not wrap " + c.getClass() + " to foil " + |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
2112 |
"stack search for classes: class loading semantics " + |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
2113 |
"may be incorrect"); |
2 | 2114 |
} catch (Exception e) { |
2115 |
logger.error("getConnection", |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
2116 |
"Could not wrap " + c.getClass() + " to foil " + |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
2117 |
"stack search for classes: class loading semantics " + |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
2118 |
"may be incorrect: " + e); |
2 | 2119 |
logger.debug("getConnection",e); |
2120 |
// so just return the original stub, which will work for all |
|
2121 |
// but the most exotic class loading situations |
|
2122 |
} |
|
2123 |
return c; |
|
2124 |
} |
|
2125 |
||
2126 |
private static byte[] base64ToByteArray(String s) { |
|
2127 |
int sLen = s.length(); |
|
2128 |
int numGroups = sLen/4; |
|
2129 |
if (4*numGroups != sLen) |
|
2130 |
throw new IllegalArgumentException( |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
2131 |
"String length must be a multiple of four."); |
2 | 2132 |
int missingBytesInLastGroup = 0; |
2133 |
int numFullGroups = numGroups; |
|
2134 |
if (sLen != 0) { |
|
2135 |
if (s.charAt(sLen-1) == '=') { |
|
2136 |
missingBytesInLastGroup++; |
|
2137 |
numFullGroups--; |
|
2138 |
} |
|
2139 |
if (s.charAt(sLen-2) == '=') |
|
2140 |
missingBytesInLastGroup++; |
|
2141 |
} |
|
2142 |
byte[] result = new byte[3*numGroups - missingBytesInLastGroup]; |
|
2143 |
||
2144 |
// Translate all full groups from base64 to byte array elements |
|
2145 |
int inCursor = 0, outCursor = 0; |
|
2146 |
for (int i=0; i<numFullGroups; i++) { |
|
2147 |
int ch0 = base64toInt(s.charAt(inCursor++)); |
|
2148 |
int ch1 = base64toInt(s.charAt(inCursor++)); |
|
2149 |
int ch2 = base64toInt(s.charAt(inCursor++)); |
|
2150 |
int ch3 = base64toInt(s.charAt(inCursor++)); |
|
2151 |
result[outCursor++] = (byte) ((ch0 << 2) | (ch1 >> 4)); |
|
2152 |
result[outCursor++] = (byte) ((ch1 << 4) | (ch2 >> 2)); |
|
2153 |
result[outCursor++] = (byte) ((ch2 << 6) | ch3); |
|
2154 |
} |
|
2155 |
||
2156 |
// Translate partial group, if present |
|
2157 |
if (missingBytesInLastGroup != 0) { |
|
2158 |
int ch0 = base64toInt(s.charAt(inCursor++)); |
|
2159 |
int ch1 = base64toInt(s.charAt(inCursor++)); |
|
2160 |
result[outCursor++] = (byte) ((ch0 << 2) | (ch1 >> 4)); |
|
2161 |
||
2162 |
if (missingBytesInLastGroup == 1) { |
|
2163 |
int ch2 = base64toInt(s.charAt(inCursor++)); |
|
2164 |
result[outCursor++] = (byte) ((ch1 << 4) | (ch2 >> 2)); |
|
2165 |
} |
|
2166 |
} |
|
2167 |
// assert inCursor == s.length()-missingBytesInLastGroup; |
|
2168 |
// assert outCursor == result.length; |
|
2169 |
return result; |
|
2170 |
} |
|
2171 |
||
2172 |
/** |
|
2173 |
* Translates the specified character, which is assumed to be in the |
|
2174 |
* "Base 64 Alphabet" into its equivalent 6-bit positive integer. |
|
2175 |
* |
|
2176 |
* @throws IllegalArgumentException if |
|
2177 |
* c is not in the Base64 Alphabet. |
|
2178 |
*/ |
|
2179 |
private static int base64toInt(char c) { |
|
2180 |
int result; |
|
2181 |
||
2182 |
if (c >= base64ToInt.length) |
|
2183 |
result = -1; |
|
2184 |
else |
|
2185 |
result = base64ToInt[c]; |
|
2186 |
||
2187 |
if (result < 0) |
|
2188 |
throw new IllegalArgumentException("Illegal character " + c); |
|
2189 |
return result; |
|
2190 |
} |
|
2191 |
||
2192 |
/** |
|
2193 |
* This array is a lookup table that translates unicode characters |
|
2194 |
* drawn from the "Base64 Alphabet" (as specified in Table 1 of RFC 2045) |
|
2195 |
* into their 6-bit positive integer equivalents. Characters that |
|
2196 |
* are not in the Base64 alphabet but fall within the bounds of the |
|
2197 |
* array are translated to -1. |
|
2198 |
*/ |
|
2199 |
private static final byte base64ToInt[] = { |
|
2200 |
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
|
2201 |
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
|
2202 |
-1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, 54, |
|
2203 |
55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, |
|
2204 |
5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, |
|
2205 |
24, 25, -1, -1, -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, |
|
2206 |
35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51 |
|
2207 |
}; |
|
2208 |
||
2209 |
//-------------------------------------------------------------------- |
|
2210 |
// Private stuff - Find / Set default class loader |
|
2211 |
//-------------------------------------------------------------------- |
|
2212 |
private ClassLoader pushDefaultClassLoader() { |
|
2213 |
final Thread t = Thread.currentThread(); |
|
2214 |
final ClassLoader old = t.getContextClassLoader(); |
|
2215 |
if (defaultClassLoader != null) |
|
2216 |
AccessController.doPrivileged(new PrivilegedAction<Void>() { |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
2217 |
public Void run() { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
2218 |
t.setContextClassLoader(defaultClassLoader); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
2219 |
return null; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
2220 |
} |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
2221 |
}); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
2222 |
return old; |
2 | 2223 |
} |
2224 |
||
2225 |
private void popDefaultClassLoader(final ClassLoader old) { |
|
2226 |
AccessController.doPrivileged(new PrivilegedAction<Void>() { |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
2227 |
public Void run() { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
2228 |
Thread.currentThread().setContextClassLoader(old); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
2229 |
return null; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
2230 |
} |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1510
diff
changeset
|
2231 |
}); |
2 | 2232 |
} |
2233 |
||
2234 |
//-------------------------------------------------------------------- |
|
2235 |
// Private variables |
|
2236 |
//-------------------------------------------------------------------- |
|
2237 |
/** |
|
2238 |
* @serial The RMIServer stub of the RMI JMX Connector server to |
|
2239 |
* which this client connector is (or will be) connected. This |
|
2240 |
* field can be null when <var>jmxServiceURL</var> is not |
|
2241 |
* null. This includes the case where <var>jmxServiceURL</var> |
|
2242 |
* contains a serialized RMIServer stub. If both |
|
2243 |
* <var>rmiServer</var> and <var>jmxServiceURL</var> are null then |
|
2244 |
* serialization will fail. |
|
2245 |
* |
|
2246 |
* @see #RMIConnector(RMIServer,Map) |
|
2247 |
**/ |
|
2248 |
private final RMIServer rmiServer; |
|
2249 |
||
2250 |
/** |
|
2251 |
* @serial The JMXServiceURL of the RMI JMX Connector server to |
|
2252 |
* which this client connector will be connected. This field can |
|
2253 |
* be null when <var>rmiServer</var> is not null. If both |
|
2254 |
* <var>rmiServer</var> and <var>jmxServiceURL</var> are null then |
|
2255 |
* serialization will fail. |
|
2256 |
* |
|
2257 |
* @see #RMIConnector(JMXServiceURL,Map) |
|
2258 |
**/ |
|
2259 |
private final JMXServiceURL jmxServiceURL; |
|
2260 |
||
2261 |
// --------------------------------------------------------- |
|
2262 |
// WARNING - WARNING - WARNING - WARNING - WARNING - WARNING |
|
2263 |
// --------------------------------------------------------- |
|
2264 |
// Any transient variable which needs to be initialized should |
|
2265 |
// be initialized in the method initTransient() |
|
2266 |
private transient Map<String, Object> env; |
|
2267 |
private transient ClassLoader defaultClassLoader; |
|
2268 |
private transient RMIConnection connection; |
|
2269 |
private transient String connectionId; |
|
2270 |
||
2271 |
private transient long clientNotifSeqNo = 0; |
|
2272 |
||
19791
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
18206
diff
changeset
|
2273 |
private transient WeakHashMap<Subject, WeakReference<MBeanServerConnection>> rmbscMap; |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
18206
diff
changeset
|
2274 |
private transient WeakReference<MBeanServerConnection> nullSubjectConnRef = null; |
2 | 2275 |
|
2276 |
private transient RMINotifClient rmiNotifClient; |
|
2277 |
// = new RMINotifClient(new Integer(0)); |
|
2278 |
||
2279 |
private transient long clientNotifCounter = 0; |
|
2280 |
||
2281 |
private transient boolean connected; |
|
2282 |
// = false; |
|
2283 |
private transient boolean terminated; |
|
2284 |
// = false; |
|
2285 |
||
2286 |
private transient Exception closeException; |
|
2287 |
||
2288 |
private transient NotificationBroadcasterSupport connectionBroadcaster; |
|
2289 |
||
2290 |
private transient ClientCommunicatorAdmin communicatorAdmin; |
|
2291 |
||
2292 |
/** |
|
2293 |
* A static WeakReference to an {@link org.omg.CORBA.ORB ORB} to |
|
2294 |
* connect unconnected stubs. |
|
2295 |
**/ |
|
4167 | 2296 |
private static volatile WeakReference<Object> orb = null; |
2 | 2297 |
|
2298 |
// TRACES & DEBUG |
|
2299 |
//--------------- |
|
2300 |
private static String objects(final Object[] objs) { |
|
2301 |
if (objs == null) |
|
2302 |
return "null"; |
|
2303 |
else |
|
2304 |
return Arrays.asList(objs).toString(); |
|
2305 |
} |
|
2306 |
||
2307 |
private static String strings(final String[] strs) { |
|
2308 |
return objects(strs); |
|
2309 |
} |
|
35282 | 2310 |
|
2311 |
static String getAttributesNames(AttributeList attributes) { |
|
2312 |
return attributes != null ? |
|
2313 |
attributes.asList().stream() |
|
2314 |
.map(Attribute::getName) |
|
35310
24e6bd6c0b75
8147857: RMIConnector logs attribute names incorrectly
sgehwolf
parents:
35282
diff
changeset
|
2315 |
.collect(Collectors.joining(", ", "[", "]")) |
35282 | 2316 |
: "[]"; |
2317 |
} |
|
2 | 2318 |
} |