2
|
1 |
/*
|
|
2 |
* Copyright 2002-2007 Sun Microsystems, Inc. All Rights Reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation. Sun designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Sun in the LICENSE file that accompanied this code.
|
|
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 |
*
|
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
23 |
* have any questions.
|
|
24 |
*/
|
|
25 |
|
|
26 |
package javax.management.remote.rmi;
|
|
27 |
|
1004
|
28 |
import com.sun.jmx.mbeanserver.Util;
|
2
|
29 |
import static com.sun.jmx.mbeanserver.Util.cast;
|
|
30 |
import com.sun.jmx.remote.internal.ServerCommunicatorAdmin;
|
|
31 |
import com.sun.jmx.remote.internal.ServerNotifForwarder;
|
|
32 |
import com.sun.jmx.remote.security.JMXSubjectDomainCombiner;
|
1004
|
33 |
import com.sun.jmx.remote.security.NotificationAccessController;
|
2
|
34 |
import com.sun.jmx.remote.security.SubjectDelegator;
|
|
35 |
import com.sun.jmx.remote.util.ClassLoaderWithRepository;
|
|
36 |
import com.sun.jmx.remote.util.ClassLogger;
|
|
37 |
import com.sun.jmx.remote.util.EnvHelp;
|
|
38 |
import com.sun.jmx.remote.util.OrderClassLoaders;
|
|
39 |
|
|
40 |
import java.io.IOException;
|
1004
|
41 |
import java.lang.reflect.UndeclaredThrowableException;
|
2
|
42 |
import java.rmi.MarshalledObject;
|
|
43 |
import java.rmi.UnmarshalException;
|
|
44 |
import java.rmi.server.Unreferenced;
|
|
45 |
import java.security.AccessControlContext;
|
|
46 |
import java.security.AccessController;
|
|
47 |
import java.security.PrivilegedAction;
|
|
48 |
import java.security.PrivilegedActionException;
|
|
49 |
import java.security.PrivilegedExceptionAction;
|
|
50 |
import java.util.Arrays;
|
|
51 |
import java.util.Collections;
|
|
52 |
import java.util.Map;
|
|
53 |
import java.util.Set;
|
|
54 |
|
|
55 |
import javax.management.Attribute;
|
|
56 |
import javax.management.AttributeList;
|
|
57 |
import javax.management.AttributeNotFoundException;
|
|
58 |
import javax.management.InstanceAlreadyExistsException;
|
|
59 |
import javax.management.InstanceNotFoundException;
|
|
60 |
import javax.management.IntrospectionException;
|
|
61 |
import javax.management.InvalidAttributeValueException;
|
1004
|
62 |
import javax.management.JMX;
|
2
|
63 |
import javax.management.ListenerNotFoundException;
|
|
64 |
import javax.management.MBeanException;
|
|
65 |
import javax.management.MBeanInfo;
|
|
66 |
import javax.management.MBeanRegistrationException;
|
|
67 |
import javax.management.MBeanServer;
|
|
68 |
import javax.management.NotCompliantMBeanException;
|
1004
|
69 |
import javax.management.Notification;
|
2
|
70 |
import javax.management.NotificationFilter;
|
|
71 |
import javax.management.ObjectInstance;
|
|
72 |
import javax.management.ObjectName;
|
|
73 |
import javax.management.QueryExp;
|
|
74 |
import javax.management.ReflectionException;
|
|
75 |
import javax.management.RuntimeOperationsException;
|
1004
|
76 |
import javax.management.event.EventClientDelegate;
|
|
77 |
import javax.management.event.EventClientDelegateMBean;
|
|
78 |
import javax.management.event.EventClientNotFoundException;
|
|
79 |
import javax.management.event.FetchingEventForwarder;
|
2
|
80 |
import javax.management.remote.JMXServerErrorException;
|
|
81 |
import javax.management.remote.NotificationResult;
|
|
82 |
import javax.management.remote.TargetedNotification;
|
|
83 |
import javax.security.auth.Subject;
|
|
84 |
|
|
85 |
/**
|
|
86 |
* <p>Implementation of the {@link RMIConnection} interface. User
|
|
87 |
* code will not usually reference this class.</p>
|
|
88 |
*
|
|
89 |
* @since 1.5
|
|
90 |
*/
|
|
91 |
/*
|
|
92 |
* Notice that we omit the type parameter from MarshalledObject everywhere,
|
|
93 |
* even though it would add useful information to the documentation. The
|
|
94 |
* reason is that it was only added in Mustang (Java SE 6), whereas versions
|
|
95 |
* 1.4 and 2.0 of the JMX API must be implementable on Tiger per our
|
|
96 |
* commitments for JSR 255.
|
|
97 |
*/
|
|
98 |
public class RMIConnectionImpl implements RMIConnection, Unreferenced {
|
|
99 |
|
|
100 |
/**
|
|
101 |
* Constructs a new {@link RMIConnection}. This connection can be
|
|
102 |
* used with either the JRMP or IIOP transport. This object does
|
|
103 |
* not export itself: it is the responsibility of the caller to
|
|
104 |
* export it appropriately (see {@link
|
|
105 |
* RMIJRMPServerImpl#makeClient(String,Subject)} and {@link
|
|
106 |
* RMIIIOPServerImpl#makeClient(String,Subject)}.
|
|
107 |
*
|
|
108 |
* @param rmiServer The RMIServerImpl object for which this
|
|
109 |
* connection is created. The behavior is unspecified if this
|
|
110 |
* parameter is null.
|
|
111 |
* @param connectionId The ID for this connection. The behavior
|
|
112 |
* is unspecified if this parameter is null.
|
|
113 |
* @param defaultClassLoader The default ClassLoader to be used
|
|
114 |
* when deserializing marshalled objects. Can be null, to signify
|
|
115 |
* the bootstrap class loader.
|
|
116 |
* @param subject the authenticated subject to be used for
|
|
117 |
* authorization. Can be null, to signify that no subject has
|
|
118 |
* been authenticated.
|
|
119 |
* @param env the environment containing attributes for the new
|
|
120 |
* <code>RMIServerImpl</code>. Can be null, equivalent to an
|
|
121 |
* empty map.
|
|
122 |
*/
|
|
123 |
public RMIConnectionImpl(RMIServerImpl rmiServer,
|
|
124 |
String connectionId,
|
|
125 |
ClassLoader defaultClassLoader,
|
|
126 |
Subject subject,
|
|
127 |
Map<String,?> env) {
|
|
128 |
if (rmiServer == null || connectionId == null)
|
|
129 |
throw new NullPointerException("Illegal null argument");
|
|
130 |
if (env == null)
|
|
131 |
env = Collections.emptyMap();
|
|
132 |
this.rmiServer = rmiServer;
|
|
133 |
this.connectionId = connectionId;
|
|
134 |
this.defaultClassLoader = defaultClassLoader;
|
|
135 |
|
|
136 |
this.subjectDelegator = new SubjectDelegator();
|
|
137 |
this.subject = subject;
|
|
138 |
if (subject == null) {
|
|
139 |
this.acc = null;
|
|
140 |
this.removeCallerContext = false;
|
|
141 |
} else {
|
|
142 |
this.removeCallerContext =
|
|
143 |
SubjectDelegator.checkRemoveCallerContext(subject);
|
|
144 |
if (this.removeCallerContext) {
|
|
145 |
this.acc =
|
|
146 |
JMXSubjectDomainCombiner.getDomainCombinerContext(subject);
|
|
147 |
} else {
|
|
148 |
this.acc =
|
|
149 |
JMXSubjectDomainCombiner.getContext(subject);
|
|
150 |
}
|
|
151 |
}
|
|
152 |
this.mbeanServer = rmiServer.getMBeanServer();
|
|
153 |
|
|
154 |
final ClassLoader dcl = defaultClassLoader;
|
|
155 |
this.classLoaderWithRepository =
|
|
156 |
AccessController.doPrivileged(
|
|
157 |
new PrivilegedAction<ClassLoaderWithRepository>() {
|
|
158 |
public ClassLoaderWithRepository run() {
|
|
159 |
return new ClassLoaderWithRepository(
|
1004
|
160 |
mbeanServer.getClassLoaderRepository(),
|
|
161 |
dcl);
|
2
|
162 |
}
|
|
163 |
});
|
|
164 |
serverCommunicatorAdmin = new
|
|
165 |
RMIServerCommunicatorAdmin(EnvHelp.getServerConnectionTimeout(env));
|
|
166 |
|
|
167 |
this.env = env;
|
|
168 |
}
|
|
169 |
|
|
170 |
|
|
171 |
public String getConnectionId() throws IOException {
|
|
172 |
// We should call reqIncomming() here... shouldn't we?
|
|
173 |
return connectionId;
|
|
174 |
}
|
|
175 |
|
|
176 |
public void close() throws IOException {
|
|
177 |
final boolean debug = logger.debugOn();
|
|
178 |
final String idstr = (debug?"["+this.toString()+"]":null);
|
|
179 |
|
1004
|
180 |
final SubscriptionManager mgr;
|
2
|
181 |
synchronized (this) {
|
|
182 |
if (terminated) {
|
|
183 |
if (debug) logger.debug("close",idstr + " already terminated.");
|
|
184 |
return;
|
|
185 |
}
|
|
186 |
|
|
187 |
if (debug) logger.debug("close",idstr + " closing.");
|
|
188 |
|
|
189 |
terminated = true;
|
|
190 |
|
|
191 |
if (serverCommunicatorAdmin != null) {
|
|
192 |
serverCommunicatorAdmin.terminate();
|
|
193 |
}
|
|
194 |
|
1004
|
195 |
mgr = subscriptionManager;
|
|
196 |
subscriptionManager = null;
|
2
|
197 |
}
|
|
198 |
|
1004
|
199 |
if (mgr != null) mgr.terminate();
|
|
200 |
|
2
|
201 |
rmiServer.clientClosed(this);
|
|
202 |
|
|
203 |
if (debug) logger.debug("close",idstr + " closed.");
|
|
204 |
}
|
|
205 |
|
|
206 |
public void unreferenced() {
|
|
207 |
logger.debug("unreferenced", "called");
|
|
208 |
try {
|
|
209 |
close();
|
|
210 |
logger.debug("unreferenced", "done");
|
|
211 |
} catch (IOException e) {
|
|
212 |
logger.fine("unreferenced", e);
|
|
213 |
}
|
|
214 |
}
|
|
215 |
|
|
216 |
//-------------------------------------------------------------------------
|
|
217 |
// MBeanServerConnection Wrapper
|
|
218 |
//-------------------------------------------------------------------------
|
|
219 |
|
|
220 |
public ObjectInstance createMBean(String className,
|
|
221 |
ObjectName name,
|
|
222 |
Subject delegationSubject)
|
|
223 |
throws
|
|
224 |
ReflectionException,
|
|
225 |
InstanceAlreadyExistsException,
|
|
226 |
MBeanRegistrationException,
|
|
227 |
MBeanException,
|
|
228 |
NotCompliantMBeanException,
|
|
229 |
IOException {
|
|
230 |
try {
|
|
231 |
final Object params[] =
|
|
232 |
new Object[] { className, name };
|
|
233 |
|
|
234 |
if (logger.debugOn())
|
|
235 |
logger.debug("createMBean(String,ObjectName)",
|
|
236 |
"connectionId=" + connectionId +", className=" +
|
|
237 |
className+", name=" + name);
|
|
238 |
|
|
239 |
return (ObjectInstance)
|
|
240 |
doPrivilegedOperation(
|
|
241 |
CREATE_MBEAN,
|
|
242 |
params,
|
|
243 |
delegationSubject);
|
|
244 |
} catch (PrivilegedActionException pe) {
|
|
245 |
Exception e = extractException(pe);
|
|
246 |
if (e instanceof ReflectionException)
|
|
247 |
throw (ReflectionException) e;
|
|
248 |
if (e instanceof InstanceAlreadyExistsException)
|
|
249 |
throw (InstanceAlreadyExistsException) e;
|
|
250 |
if (e instanceof MBeanRegistrationException)
|
|
251 |
throw (MBeanRegistrationException) e;
|
|
252 |
if (e instanceof MBeanException)
|
|
253 |
throw (MBeanException) e;
|
|
254 |
if (e instanceof NotCompliantMBeanException)
|
|
255 |
throw (NotCompliantMBeanException) e;
|
|
256 |
if (e instanceof IOException)
|
|
257 |
throw (IOException) e;
|
|
258 |
throw newIOException("Got unexpected server exception: " + e, e);
|
|
259 |
}
|
|
260 |
}
|
|
261 |
|
|
262 |
public ObjectInstance createMBean(String className,
|
|
263 |
ObjectName name,
|
|
264 |
ObjectName loaderName,
|
|
265 |
Subject delegationSubject)
|
|
266 |
throws
|
|
267 |
ReflectionException,
|
|
268 |
InstanceAlreadyExistsException,
|
|
269 |
MBeanRegistrationException,
|
|
270 |
MBeanException,
|
|
271 |
NotCompliantMBeanException,
|
|
272 |
InstanceNotFoundException,
|
|
273 |
IOException {
|
|
274 |
try {
|
|
275 |
final Object params[] =
|
|
276 |
new Object[] { className, name, loaderName };
|
|
277 |
|
|
278 |
if (logger.debugOn())
|
|
279 |
logger.debug("createMBean(String,ObjectName,ObjectName)",
|
|
280 |
"connectionId=" + connectionId
|
|
281 |
+", className=" + className
|
|
282 |
+", name=" + name
|
|
283 |
+", loaderName=" + loaderName);
|
|
284 |
|
|
285 |
return (ObjectInstance)
|
|
286 |
doPrivilegedOperation(
|
|
287 |
CREATE_MBEAN_LOADER,
|
|
288 |
params,
|
|
289 |
delegationSubject);
|
|
290 |
} catch (PrivilegedActionException pe) {
|
|
291 |
Exception e = extractException(pe);
|
|
292 |
if (e instanceof ReflectionException)
|
|
293 |
throw (ReflectionException) e;
|
|
294 |
if (e instanceof InstanceAlreadyExistsException)
|
|
295 |
throw (InstanceAlreadyExistsException) e;
|
|
296 |
if (e instanceof MBeanRegistrationException)
|
|
297 |
throw (MBeanRegistrationException) e;
|
|
298 |
if (e instanceof MBeanException)
|
|
299 |
throw (MBeanException) e;
|
|
300 |
if (e instanceof NotCompliantMBeanException)
|
|
301 |
throw (NotCompliantMBeanException) e;
|
|
302 |
if (e instanceof InstanceNotFoundException)
|
|
303 |
throw (InstanceNotFoundException) e;
|
|
304 |
if (e instanceof IOException)
|
|
305 |
throw (IOException) e;
|
|
306 |
throw newIOException("Got unexpected server exception: " + e, e);
|
|
307 |
}
|
|
308 |
}
|
|
309 |
|
|
310 |
public ObjectInstance createMBean(String className,
|
|
311 |
ObjectName name,
|
|
312 |
MarshalledObject params,
|
|
313 |
String signature[],
|
|
314 |
Subject delegationSubject)
|
|
315 |
throws
|
|
316 |
ReflectionException,
|
|
317 |
InstanceAlreadyExistsException,
|
|
318 |
MBeanRegistrationException,
|
|
319 |
MBeanException,
|
|
320 |
NotCompliantMBeanException,
|
|
321 |
IOException {
|
|
322 |
|
|
323 |
final Object[] values;
|
|
324 |
final boolean debug = logger.debugOn();
|
|
325 |
|
|
326 |
if (debug) logger.debug(
|
|
327 |
"createMBean(String,ObjectName,Object[],String[])",
|
|
328 |
"connectionId=" + connectionId
|
|
329 |
+", unwrapping parameters using classLoaderWithRepository.");
|
|
330 |
|
|
331 |
values =
|
|
332 |
nullIsEmpty(unwrap(params, classLoaderWithRepository, Object[].class));
|
|
333 |
|
|
334 |
try {
|
|
335 |
final Object params2[] =
|
|
336 |
new Object[] { className, name, values,
|
|
337 |
nullIsEmpty(signature) };
|
|
338 |
|
|
339 |
if (debug)
|
|
340 |
logger.debug("createMBean(String,ObjectName,Object[],String[])",
|
|
341 |
"connectionId=" + connectionId
|
|
342 |
+", className=" + className
|
|
343 |
+", name=" + name
|
|
344 |
+", params=" + objects(values)
|
|
345 |
+", signature=" + strings(signature));
|
|
346 |
|
|
347 |
return (ObjectInstance)
|
|
348 |
doPrivilegedOperation(
|
|
349 |
CREATE_MBEAN_PARAMS,
|
|
350 |
params2,
|
|
351 |
delegationSubject);
|
|
352 |
} catch (PrivilegedActionException pe) {
|
|
353 |
Exception e = extractException(pe);
|
|
354 |
if (e instanceof ReflectionException)
|
|
355 |
throw (ReflectionException) e;
|
|
356 |
if (e instanceof InstanceAlreadyExistsException)
|
|
357 |
throw (InstanceAlreadyExistsException) e;
|
|
358 |
if (e instanceof MBeanRegistrationException)
|
|
359 |
throw (MBeanRegistrationException) e;
|
|
360 |
if (e instanceof MBeanException)
|
|
361 |
throw (MBeanException) e;
|
|
362 |
if (e instanceof NotCompliantMBeanException)
|
|
363 |
throw (NotCompliantMBeanException) e;
|
|
364 |
if (e instanceof IOException)
|
|
365 |
throw (IOException) e;
|
|
366 |
throw newIOException("Got unexpected server exception: " + e, e);
|
|
367 |
}
|
|
368 |
}
|
|
369 |
|
|
370 |
public ObjectInstance createMBean(String className,
|
|
371 |
ObjectName name,
|
|
372 |
ObjectName loaderName,
|
|
373 |
MarshalledObject params,
|
|
374 |
String signature[],
|
|
375 |
Subject delegationSubject)
|
|
376 |
throws
|
|
377 |
ReflectionException,
|
|
378 |
InstanceAlreadyExistsException,
|
|
379 |
MBeanRegistrationException,
|
|
380 |
MBeanException,
|
|
381 |
NotCompliantMBeanException,
|
|
382 |
InstanceNotFoundException,
|
|
383 |
IOException {
|
|
384 |
|
|
385 |
final Object[] values;
|
|
386 |
final boolean debug = logger.debugOn();
|
|
387 |
|
|
388 |
if (debug) logger.debug(
|
|
389 |
"createMBean(String,ObjectName,ObjectName,Object[],String[])",
|
|
390 |
"connectionId=" + connectionId
|
|
391 |
+", unwrapping params with MBean extended ClassLoader.");
|
|
392 |
|
|
393 |
values = nullIsEmpty(unwrap(params,
|
|
394 |
getClassLoader(loaderName),
|
|
395 |
defaultClassLoader,
|
|
396 |
Object[].class));
|
|
397 |
|
|
398 |
try {
|
|
399 |
final Object params2[] =
|
|
400 |
new Object[] { className, name, loaderName, values,
|
|
401 |
nullIsEmpty(signature) };
|
|
402 |
|
|
403 |
if (debug) logger.debug(
|
|
404 |
"createMBean(String,ObjectName,ObjectName,Object[],String[])",
|
|
405 |
"connectionId=" + connectionId
|
|
406 |
+", className=" + className
|
|
407 |
+", name=" + name
|
|
408 |
+", loaderName=" + loaderName
|
|
409 |
+", params=" + objects(values)
|
|
410 |
+", signature=" + strings(signature));
|
|
411 |
|
|
412 |
return (ObjectInstance)
|
|
413 |
doPrivilegedOperation(
|
|
414 |
CREATE_MBEAN_LOADER_PARAMS,
|
|
415 |
params2,
|
|
416 |
delegationSubject);
|
|
417 |
} catch (PrivilegedActionException pe) {
|
|
418 |
Exception e = extractException(pe);
|
|
419 |
if (e instanceof ReflectionException)
|
|
420 |
throw (ReflectionException) e;
|
|
421 |
if (e instanceof InstanceAlreadyExistsException)
|
|
422 |
throw (InstanceAlreadyExistsException) e;
|
|
423 |
if (e instanceof MBeanRegistrationException)
|
|
424 |
throw (MBeanRegistrationException) e;
|
|
425 |
if (e instanceof MBeanException)
|
|
426 |
throw (MBeanException) e;
|
|
427 |
if (e instanceof NotCompliantMBeanException)
|
|
428 |
throw (NotCompliantMBeanException) e;
|
|
429 |
if (e instanceof InstanceNotFoundException)
|
|
430 |
throw (InstanceNotFoundException) e;
|
|
431 |
if (e instanceof IOException)
|
|
432 |
throw (IOException) e;
|
|
433 |
throw newIOException("Got unexpected server exception: " + e, e);
|
|
434 |
}
|
|
435 |
}
|
|
436 |
|
|
437 |
public void unregisterMBean(ObjectName name, Subject delegationSubject)
|
|
438 |
throws
|
|
439 |
InstanceNotFoundException,
|
|
440 |
MBeanRegistrationException,
|
|
441 |
IOException {
|
|
442 |
try {
|
|
443 |
final Object params[] = new Object[] { name };
|
|
444 |
|
|
445 |
if (logger.debugOn()) logger.debug("unregisterMBean",
|
|
446 |
"connectionId=" + connectionId
|
|
447 |
+", name="+name);
|
|
448 |
|
|
449 |
doPrivilegedOperation(
|
|
450 |
UNREGISTER_MBEAN,
|
|
451 |
params,
|
|
452 |
delegationSubject);
|
|
453 |
} catch (PrivilegedActionException pe) {
|
|
454 |
Exception e = extractException(pe);
|
|
455 |
if (e instanceof InstanceNotFoundException)
|
|
456 |
throw (InstanceNotFoundException) e;
|
|
457 |
if (e instanceof MBeanRegistrationException)
|
|
458 |
throw (MBeanRegistrationException) e;
|
|
459 |
if (e instanceof IOException)
|
|
460 |
throw (IOException) e;
|
|
461 |
throw newIOException("Got unexpected server exception: " + e, e);
|
|
462 |
}
|
|
463 |
}
|
|
464 |
|
|
465 |
public ObjectInstance getObjectInstance(ObjectName name,
|
|
466 |
Subject delegationSubject)
|
|
467 |
throws
|
|
468 |
InstanceNotFoundException,
|
|
469 |
IOException {
|
|
470 |
|
|
471 |
checkNonNull("ObjectName", name);
|
|
472 |
|
|
473 |
try {
|
|
474 |
final Object params[] = new Object[] { name };
|
|
475 |
|
|
476 |
if (logger.debugOn()) logger.debug("getObjectInstance",
|
|
477 |
"connectionId=" + connectionId
|
|
478 |
+", name="+name);
|
|
479 |
|
|
480 |
return (ObjectInstance)
|
|
481 |
doPrivilegedOperation(
|
|
482 |
GET_OBJECT_INSTANCE,
|
|
483 |
params,
|
|
484 |
delegationSubject);
|
|
485 |
} catch (PrivilegedActionException pe) {
|
|
486 |
Exception e = extractException(pe);
|
|
487 |
if (e instanceof InstanceNotFoundException)
|
|
488 |
throw (InstanceNotFoundException) e;
|
|
489 |
if (e instanceof IOException)
|
|
490 |
throw (IOException) e;
|
|
491 |
throw newIOException("Got unexpected server exception: " + e, e);
|
|
492 |
}
|
|
493 |
}
|
|
494 |
|
|
495 |
public Set<ObjectInstance>
|
|
496 |
queryMBeans(ObjectName name,
|
|
497 |
MarshalledObject query,
|
|
498 |
Subject delegationSubject)
|
|
499 |
throws IOException {
|
|
500 |
final QueryExp queryValue;
|
|
501 |
final boolean debug=logger.debugOn();
|
|
502 |
|
|
503 |
if (debug) logger.debug("queryMBeans",
|
|
504 |
"connectionId=" + connectionId
|
|
505 |
+" unwrapping query with defaultClassLoader.");
|
|
506 |
|
|
507 |
queryValue = unwrap(query, defaultClassLoader, QueryExp.class);
|
|
508 |
|
|
509 |
try {
|
|
510 |
final Object params[] = new Object[] { name, queryValue };
|
|
511 |
|
|
512 |
if (debug) logger.debug("queryMBeans",
|
|
513 |
"connectionId=" + connectionId
|
|
514 |
+", name="+name +", query="+query);
|
|
515 |
|
|
516 |
return cast(
|
|
517 |
doPrivilegedOperation(
|
|
518 |
QUERY_MBEANS,
|
|
519 |
params,
|
|
520 |
delegationSubject));
|
|
521 |
} catch (PrivilegedActionException pe) {
|
|
522 |
Exception e = extractException(pe);
|
|
523 |
if (e instanceof IOException)
|
|
524 |
throw (IOException) e;
|
|
525 |
throw newIOException("Got unexpected server exception: " + e, e);
|
|
526 |
}
|
|
527 |
}
|
|
528 |
|
|
529 |
public Set<ObjectName>
|
|
530 |
queryNames(ObjectName name,
|
|
531 |
MarshalledObject query,
|
|
532 |
Subject delegationSubject)
|
|
533 |
throws IOException {
|
|
534 |
final QueryExp queryValue;
|
|
535 |
final boolean debug=logger.debugOn();
|
|
536 |
|
|
537 |
if (debug) logger.debug("queryNames",
|
|
538 |
"connectionId=" + connectionId
|
|
539 |
+" unwrapping query with defaultClassLoader.");
|
|
540 |
|
|
541 |
queryValue = unwrap(query, defaultClassLoader, QueryExp.class);
|
|
542 |
|
|
543 |
try {
|
|
544 |
final Object params[] = new Object[] { name, queryValue };
|
|
545 |
|
|
546 |
if (debug) logger.debug("queryNames",
|
|
547 |
"connectionId=" + connectionId
|
|
548 |
+", name="+name +", query="+query);
|
|
549 |
|
|
550 |
return cast(
|
|
551 |
doPrivilegedOperation(
|
|
552 |
QUERY_NAMES,
|
|
553 |
params,
|
|
554 |
delegationSubject));
|
|
555 |
} catch (PrivilegedActionException pe) {
|
|
556 |
Exception e = extractException(pe);
|
|
557 |
if (e instanceof IOException)
|
|
558 |
throw (IOException) e;
|
|
559 |
throw newIOException("Got unexpected server exception: " + e, e);
|
|
560 |
}
|
|
561 |
}
|
|
562 |
|
|
563 |
public boolean isRegistered(ObjectName name,
|
|
564 |
Subject delegationSubject) throws IOException {
|
|
565 |
try {
|
|
566 |
final Object params[] = new Object[] { name };
|
|
567 |
return ((Boolean)
|
|
568 |
doPrivilegedOperation(
|
|
569 |
IS_REGISTERED,
|
|
570 |
params,
|
|
571 |
delegationSubject)).booleanValue();
|
|
572 |
} catch (PrivilegedActionException pe) {
|
|
573 |
Exception e = extractException(pe);
|
|
574 |
if (e instanceof IOException)
|
|
575 |
throw (IOException) e;
|
|
576 |
throw newIOException("Got unexpected server exception: " + e, e);
|
|
577 |
}
|
|
578 |
}
|
|
579 |
|
|
580 |
public Integer getMBeanCount(Subject delegationSubject)
|
|
581 |
throws IOException {
|
|
582 |
try {
|
|
583 |
final Object params[] = new Object[] { };
|
|
584 |
|
|
585 |
if (logger.debugOn()) logger.debug("getMBeanCount",
|
|
586 |
"connectionId=" + connectionId);
|
|
587 |
|
|
588 |
return (Integer)
|
|
589 |
doPrivilegedOperation(
|
|
590 |
GET_MBEAN_COUNT,
|
|
591 |
params,
|
|
592 |
delegationSubject);
|
|
593 |
} catch (PrivilegedActionException pe) {
|
|
594 |
Exception e = extractException(pe);
|
|
595 |
if (e instanceof IOException)
|
|
596 |
throw (IOException) e;
|
|
597 |
throw newIOException("Got unexpected server exception: " + e, e);
|
|
598 |
}
|
|
599 |
}
|
|
600 |
|
|
601 |
public Object getAttribute(ObjectName name,
|
|
602 |
String attribute,
|
|
603 |
Subject delegationSubject)
|
|
604 |
throws
|
|
605 |
MBeanException,
|
|
606 |
AttributeNotFoundException,
|
|
607 |
InstanceNotFoundException,
|
|
608 |
ReflectionException,
|
|
609 |
IOException {
|
|
610 |
try {
|
|
611 |
final Object params[] = new Object[] { name, attribute };
|
|
612 |
if (logger.debugOn()) logger.debug("getAttribute",
|
|
613 |
"connectionId=" + connectionId
|
|
614 |
+", name=" + name
|
|
615 |
+", attribute="+ attribute);
|
|
616 |
|
|
617 |
return
|
|
618 |
doPrivilegedOperation(
|
|
619 |
GET_ATTRIBUTE,
|
|
620 |
params,
|
|
621 |
delegationSubject);
|
|
622 |
} catch (PrivilegedActionException pe) {
|
|
623 |
Exception e = extractException(pe);
|
|
624 |
if (e instanceof MBeanException)
|
|
625 |
throw (MBeanException) e;
|
|
626 |
if (e instanceof AttributeNotFoundException)
|
|
627 |
throw (AttributeNotFoundException) e;
|
|
628 |
if (e instanceof InstanceNotFoundException)
|
|
629 |
throw (InstanceNotFoundException) e;
|
|
630 |
if (e instanceof ReflectionException)
|
|
631 |
throw (ReflectionException) e;
|
|
632 |
if (e instanceof IOException)
|
|
633 |
throw (IOException) e;
|
|
634 |
throw newIOException("Got unexpected server exception: " + e, e);
|
|
635 |
}
|
|
636 |
}
|
|
637 |
|
|
638 |
public AttributeList getAttributes(ObjectName name,
|
|
639 |
String[] attributes,
|
|
640 |
Subject delegationSubject)
|
|
641 |
throws
|
|
642 |
InstanceNotFoundException,
|
|
643 |
ReflectionException,
|
|
644 |
IOException {
|
|
645 |
try {
|
|
646 |
final Object params[] = new Object[] { name, attributes };
|
|
647 |
|
|
648 |
if (logger.debugOn()) logger.debug("getAttributes",
|
|
649 |
"connectionId=" + connectionId
|
|
650 |
+", name=" + name
|
|
651 |
+", attributes="+ strings(attributes));
|
|
652 |
|
|
653 |
return (AttributeList)
|
|
654 |
doPrivilegedOperation(
|
|
655 |
GET_ATTRIBUTES,
|
|
656 |
params,
|
|
657 |
delegationSubject);
|
|
658 |
} catch (PrivilegedActionException pe) {
|
|
659 |
Exception e = extractException(pe);
|
|
660 |
if (e instanceof InstanceNotFoundException)
|
|
661 |
throw (InstanceNotFoundException) e;
|
|
662 |
if (e instanceof ReflectionException)
|
|
663 |
throw (ReflectionException) e;
|
|
664 |
if (e instanceof IOException)
|
|
665 |
throw (IOException) e;
|
|
666 |
throw newIOException("Got unexpected server exception: " + e, e);
|
|
667 |
}
|
|
668 |
}
|
|
669 |
|
|
670 |
public void setAttribute(ObjectName name,
|
|
671 |
MarshalledObject attribute,
|
|
672 |
Subject delegationSubject)
|
|
673 |
throws
|
|
674 |
InstanceNotFoundException,
|
|
675 |
AttributeNotFoundException,
|
|
676 |
InvalidAttributeValueException,
|
|
677 |
MBeanException,
|
|
678 |
ReflectionException,
|
|
679 |
IOException {
|
|
680 |
final Attribute attr;
|
|
681 |
final boolean debug=logger.debugOn();
|
|
682 |
|
|
683 |
if (debug) logger.debug("setAttribute",
|
|
684 |
"connectionId=" + connectionId
|
|
685 |
+" unwrapping attribute with MBean extended ClassLoader.");
|
|
686 |
|
|
687 |
attr = unwrap(attribute,
|
|
688 |
getClassLoaderFor(name),
|
|
689 |
defaultClassLoader,
|
|
690 |
Attribute.class);
|
|
691 |
|
|
692 |
try {
|
|
693 |
final Object params[] = new Object[] { name, attr };
|
|
694 |
|
|
695 |
if (debug) logger.debug("setAttribute",
|
|
696 |
"connectionId=" + connectionId
|
|
697 |
+", name="+name
|
|
698 |
+", attribute="+attr);
|
|
699 |
|
|
700 |
doPrivilegedOperation(
|
|
701 |
SET_ATTRIBUTE,
|
|
702 |
params,
|
|
703 |
delegationSubject);
|
|
704 |
} catch (PrivilegedActionException pe) {
|
|
705 |
Exception e = extractException(pe);
|
|
706 |
if (e instanceof InstanceNotFoundException)
|
|
707 |
throw (InstanceNotFoundException) e;
|
|
708 |
if (e instanceof AttributeNotFoundException)
|
|
709 |
throw (AttributeNotFoundException) e;
|
|
710 |
if (e instanceof InvalidAttributeValueException)
|
|
711 |
throw (InvalidAttributeValueException) e;
|
|
712 |
if (e instanceof MBeanException)
|
|
713 |
throw (MBeanException) e;
|
|
714 |
if (e instanceof ReflectionException)
|
|
715 |
throw (ReflectionException) e;
|
|
716 |
if (e instanceof IOException)
|
|
717 |
throw (IOException) e;
|
|
718 |
throw newIOException("Got unexpected server exception: " + e, e);
|
|
719 |
}
|
|
720 |
}
|
|
721 |
|
|
722 |
public AttributeList setAttributes(ObjectName name,
|
|
723 |
MarshalledObject attributes,
|
|
724 |
Subject delegationSubject)
|
|
725 |
throws
|
|
726 |
InstanceNotFoundException,
|
|
727 |
ReflectionException,
|
|
728 |
IOException {
|
|
729 |
final AttributeList attrlist;
|
|
730 |
final boolean debug=logger.debugOn();
|
|
731 |
|
|
732 |
if (debug) logger.debug("setAttributes",
|
|
733 |
"connectionId=" + connectionId
|
|
734 |
+" unwrapping attributes with MBean extended ClassLoader.");
|
|
735 |
|
|
736 |
attrlist =
|
|
737 |
unwrap(attributes,
|
|
738 |
getClassLoaderFor(name),
|
|
739 |
defaultClassLoader,
|
|
740 |
AttributeList.class);
|
|
741 |
|
|
742 |
try {
|
|
743 |
final Object params[] = new Object[] { name, attrlist };
|
|
744 |
|
|
745 |
if (debug) logger.debug("setAttributes",
|
|
746 |
"connectionId=" + connectionId
|
|
747 |
+", name="+name
|
|
748 |
+", attributes="+attrlist);
|
|
749 |
|
|
750 |
return (AttributeList)
|
|
751 |
doPrivilegedOperation(
|
|
752 |
SET_ATTRIBUTES,
|
|
753 |
params,
|
|
754 |
delegationSubject);
|
|
755 |
} catch (PrivilegedActionException pe) {
|
|
756 |
Exception e = extractException(pe);
|
|
757 |
if (e instanceof InstanceNotFoundException)
|
|
758 |
throw (InstanceNotFoundException) e;
|
|
759 |
if (e instanceof ReflectionException)
|
|
760 |
throw (ReflectionException) e;
|
|
761 |
if (e instanceof IOException)
|
|
762 |
throw (IOException) e;
|
|
763 |
throw newIOException("Got unexpected server exception: " + e, e);
|
|
764 |
}
|
|
765 |
}
|
|
766 |
|
|
767 |
public Object invoke(ObjectName name,
|
|
768 |
String operationName,
|
|
769 |
MarshalledObject params,
|
|
770 |
String signature[],
|
|
771 |
Subject delegationSubject)
|
|
772 |
throws
|
|
773 |
InstanceNotFoundException,
|
|
774 |
MBeanException,
|
|
775 |
ReflectionException,
|
|
776 |
IOException {
|
|
777 |
|
|
778 |
checkNonNull("ObjectName", name);
|
|
779 |
checkNonNull("Operation name", operationName);
|
|
780 |
|
|
781 |
final Object[] values;
|
|
782 |
final boolean debug=logger.debugOn();
|
|
783 |
|
|
784 |
if (debug) logger.debug("invoke",
|
|
785 |
"connectionId=" + connectionId
|
|
786 |
+" unwrapping params with MBean extended ClassLoader.");
|
|
787 |
|
|
788 |
values = nullIsEmpty(unwrap(params,
|
|
789 |
getClassLoaderFor(name),
|
|
790 |
defaultClassLoader,
|
|
791 |
Object[].class));
|
|
792 |
|
|
793 |
try {
|
|
794 |
final Object params2[] =
|
|
795 |
new Object[] { name, operationName, values,
|
|
796 |
nullIsEmpty(signature) };
|
|
797 |
|
|
798 |
if (debug) logger.debug("invoke",
|
|
799 |
"connectionId=" + connectionId
|
|
800 |
+", name="+name
|
|
801 |
+", operationName="+operationName
|
|
802 |
+", params="+objects(values)
|
|
803 |
+", signature="+strings(signature));
|
|
804 |
|
|
805 |
return
|
|
806 |
doPrivilegedOperation(
|
|
807 |
INVOKE,
|
|
808 |
params2,
|
|
809 |
delegationSubject);
|
|
810 |
} catch (PrivilegedActionException pe) {
|
|
811 |
Exception e = extractException(pe);
|
|
812 |
if (e instanceof InstanceNotFoundException)
|
|
813 |
throw (InstanceNotFoundException) e;
|
|
814 |
if (e instanceof MBeanException)
|
|
815 |
throw (MBeanException) e;
|
|
816 |
if (e instanceof ReflectionException)
|
|
817 |
throw (ReflectionException) e;
|
|
818 |
if (e instanceof IOException)
|
|
819 |
throw (IOException) e;
|
|
820 |
throw newIOException("Got unexpected server exception: " + e, e);
|
|
821 |
}
|
|
822 |
}
|
|
823 |
|
|
824 |
public String getDefaultDomain(Subject delegationSubject)
|
|
825 |
throws IOException {
|
|
826 |
try {
|
|
827 |
final Object params[] = new Object[] { };
|
|
828 |
|
|
829 |
if (logger.debugOn()) logger.debug("getDefaultDomain",
|
|
830 |
"connectionId=" + connectionId);
|
|
831 |
|
|
832 |
return (String)
|
|
833 |
doPrivilegedOperation(
|
|
834 |
GET_DEFAULT_DOMAIN,
|
|
835 |
params,
|
|
836 |
delegationSubject);
|
|
837 |
} catch (PrivilegedActionException pe) {
|
|
838 |
Exception e = extractException(pe);
|
|
839 |
if (e instanceof IOException)
|
|
840 |
throw (IOException) e;
|
|
841 |
throw newIOException("Got unexpected server exception: " + e, e);
|
|
842 |
}
|
|
843 |
}
|
|
844 |
|
|
845 |
public String[] getDomains(Subject delegationSubject) throws IOException {
|
|
846 |
try {
|
|
847 |
final Object params[] = new Object[] { };
|
|
848 |
|
|
849 |
if (logger.debugOn()) logger.debug("getDomains",
|
|
850 |
"connectionId=" + connectionId);
|
|
851 |
|
|
852 |
return (String[])
|
|
853 |
doPrivilegedOperation(
|
|
854 |
GET_DOMAINS,
|
|
855 |
params,
|
|
856 |
delegationSubject);
|
|
857 |
} catch (PrivilegedActionException pe) {
|
|
858 |
Exception e = extractException(pe);
|
|
859 |
if (e instanceof IOException)
|
|
860 |
throw (IOException) e;
|
|
861 |
throw newIOException("Got unexpected server exception: " + e, e);
|
|
862 |
}
|
|
863 |
}
|
|
864 |
|
|
865 |
public MBeanInfo getMBeanInfo(ObjectName name, Subject delegationSubject)
|
|
866 |
throws
|
|
867 |
InstanceNotFoundException,
|
|
868 |
IntrospectionException,
|
|
869 |
ReflectionException,
|
|
870 |
IOException {
|
|
871 |
|
|
872 |
checkNonNull("ObjectName", name);
|
|
873 |
|
|
874 |
try {
|
|
875 |
final Object params[] = new Object[] { name };
|
|
876 |
|
|
877 |
if (logger.debugOn()) logger.debug("getMBeanInfo",
|
|
878 |
"connectionId=" + connectionId
|
|
879 |
+", name="+name);
|
|
880 |
|
|
881 |
return (MBeanInfo)
|
|
882 |
doPrivilegedOperation(
|
|
883 |
GET_MBEAN_INFO,
|
|
884 |
params,
|
|
885 |
delegationSubject);
|
|
886 |
} catch (PrivilegedActionException pe) {
|
|
887 |
Exception e = extractException(pe);
|
|
888 |
if (e instanceof InstanceNotFoundException)
|
|
889 |
throw (InstanceNotFoundException) e;
|
|
890 |
if (e instanceof IntrospectionException)
|
|
891 |
throw (IntrospectionException) e;
|
|
892 |
if (e instanceof ReflectionException)
|
|
893 |
throw (ReflectionException) e;
|
|
894 |
if (e instanceof IOException)
|
|
895 |
throw (IOException) e;
|
|
896 |
throw newIOException("Got unexpected server exception: " + e, e);
|
|
897 |
}
|
|
898 |
}
|
|
899 |
|
|
900 |
public boolean isInstanceOf(ObjectName name,
|
|
901 |
String className,
|
|
902 |
Subject delegationSubject)
|
|
903 |
throws InstanceNotFoundException, IOException {
|
|
904 |
|
|
905 |
checkNonNull("ObjectName", name);
|
|
906 |
|
|
907 |
try {
|
|
908 |
final Object params[] = new Object[] { name, className };
|
|
909 |
|
|
910 |
if (logger.debugOn()) logger.debug("isInstanceOf",
|
|
911 |
"connectionId=" + connectionId
|
|
912 |
+", name="+name
|
|
913 |
+", className="+className);
|
|
914 |
|
|
915 |
return ((Boolean)
|
|
916 |
doPrivilegedOperation(
|
|
917 |
IS_INSTANCE_OF,
|
|
918 |
params,
|
|
919 |
delegationSubject)).booleanValue();
|
|
920 |
} catch (PrivilegedActionException pe) {
|
|
921 |
Exception e = extractException(pe);
|
|
922 |
if (e instanceof InstanceNotFoundException)
|
|
923 |
throw (InstanceNotFoundException) e;
|
|
924 |
if (e instanceof IOException)
|
|
925 |
throw (IOException) e;
|
|
926 |
throw newIOException("Got unexpected server exception: " + e, e);
|
|
927 |
}
|
|
928 |
}
|
|
929 |
|
|
930 |
public Integer[] addNotificationListeners(ObjectName[] names,
|
|
931 |
MarshalledObject[] filters,
|
|
932 |
Subject[] delegationSubjects)
|
|
933 |
throws InstanceNotFoundException, IOException {
|
|
934 |
|
|
935 |
if (names == null || filters == null) {
|
|
936 |
throw new IllegalArgumentException("Got null arguments.");
|
|
937 |
}
|
|
938 |
|
|
939 |
Subject[] sbjs = (delegationSubjects != null) ? delegationSubjects :
|
|
940 |
new Subject[names.length];
|
|
941 |
if (names.length != filters.length || filters.length != sbjs.length) {
|
|
942 |
final String msg =
|
|
943 |
"The value lengths of 3 parameters are not same.";
|
|
944 |
throw new IllegalArgumentException(msg);
|
|
945 |
}
|
|
946 |
|
|
947 |
for (int i=0; i<names.length; i++) {
|
|
948 |
if (names[i] == null) {
|
|
949 |
throw new IllegalArgumentException("Null Object name.");
|
|
950 |
}
|
|
951 |
}
|
|
952 |
|
|
953 |
int i=0;
|
|
954 |
ClassLoader targetCl;
|
|
955 |
NotificationFilter[] filterValues =
|
1004
|
956 |
new NotificationFilter[names.length];
|
2
|
957 |
Integer[] ids = new Integer[names.length];
|
|
958 |
final boolean debug=logger.debugOn();
|
|
959 |
|
|
960 |
try {
|
|
961 |
for (; i<names.length; i++) {
|
|
962 |
targetCl = getClassLoaderFor(names[i]);
|
|
963 |
|
|
964 |
if (debug) logger.debug("addNotificationListener"+
|
|
965 |
"(ObjectName,NotificationFilter)",
|
|
966 |
"connectionId=" + connectionId +
|
|
967 |
" unwrapping filter with target extended ClassLoader.");
|
|
968 |
|
|
969 |
filterValues[i] =
|
|
970 |
unwrap(filters[i], targetCl, defaultClassLoader,
|
|
971 |
NotificationFilter.class);
|
|
972 |
|
|
973 |
if (debug) logger.debug("addNotificationListener"+
|
|
974 |
"(ObjectName,NotificationFilter)",
|
|
975 |
"connectionId=" + connectionId
|
|
976 |
+", name=" + names[i]
|
|
977 |
+", filter=" + filterValues[i]);
|
|
978 |
|
|
979 |
ids[i] = (Integer)
|
|
980 |
doPrivilegedOperation(ADD_NOTIFICATION_LISTENERS,
|
|
981 |
new Object[] { names[i],
|
|
982 |
filterValues[i] },
|
|
983 |
sbjs[i]);
|
|
984 |
}
|
|
985 |
|
|
986 |
return ids;
|
|
987 |
} catch (Exception e) {
|
|
988 |
// remove all registered listeners
|
|
989 |
for (int j=0; j<i; j++) {
|
|
990 |
try {
|
1004
|
991 |
doRemoveListener(names[j],ids[j]);
|
2
|
992 |
} catch (Exception eee) {
|
|
993 |
// strange
|
|
994 |
}
|
|
995 |
}
|
|
996 |
|
|
997 |
if (e instanceof PrivilegedActionException) {
|
|
998 |
e = extractException(e);
|
|
999 |
}
|
|
1000 |
|
|
1001 |
if (e instanceof ClassCastException) {
|
|
1002 |
throw (ClassCastException) e;
|
|
1003 |
} else if (e instanceof IOException) {
|
|
1004 |
throw (IOException)e;
|
|
1005 |
} else if (e instanceof InstanceNotFoundException) {
|
|
1006 |
throw (InstanceNotFoundException) e;
|
|
1007 |
} else if (e instanceof RuntimeException) {
|
|
1008 |
throw (RuntimeException) e;
|
|
1009 |
} else {
|
|
1010 |
throw newIOException("Got unexpected server exception: "+e,e);
|
|
1011 |
}
|
|
1012 |
}
|
|
1013 |
}
|
|
1014 |
|
|
1015 |
public void addNotificationListener(ObjectName name,
|
|
1016 |
ObjectName listener,
|
|
1017 |
MarshalledObject filter,
|
|
1018 |
MarshalledObject handback,
|
|
1019 |
Subject delegationSubject)
|
|
1020 |
throws InstanceNotFoundException, IOException {
|
|
1021 |
|
|
1022 |
checkNonNull("Target MBean name", name);
|
|
1023 |
checkNonNull("Listener MBean name", listener);
|
|
1024 |
|
|
1025 |
final NotificationFilter filterValue;
|
|
1026 |
final Object handbackValue;
|
|
1027 |
final boolean debug=logger.debugOn();
|
|
1028 |
|
|
1029 |
final ClassLoader targetCl = getClassLoaderFor(name);
|
|
1030 |
|
|
1031 |
if (debug) logger.debug("addNotificationListener"+
|
|
1032 |
"(ObjectName,ObjectName,NotificationFilter,Object)",
|
|
1033 |
"connectionId=" + connectionId
|
|
1034 |
+" unwrapping filter with target extended ClassLoader.");
|
|
1035 |
|
|
1036 |
filterValue =
|
|
1037 |
unwrap(filter, targetCl, defaultClassLoader, NotificationFilter.class);
|
|
1038 |
|
|
1039 |
if (debug) logger.debug("addNotificationListener"+
|
|
1040 |
"(ObjectName,ObjectName,NotificationFilter,Object)",
|
|
1041 |
"connectionId=" + connectionId
|
|
1042 |
+" unwrapping handback with target extended ClassLoader.");
|
|
1043 |
|
|
1044 |
handbackValue =
|
|
1045 |
unwrap(handback, targetCl, defaultClassLoader, Object.class);
|
|
1046 |
|
|
1047 |
try {
|
|
1048 |
final Object params[] =
|
|
1049 |
new Object[] { name, listener, filterValue, handbackValue };
|
|
1050 |
|
|
1051 |
if (debug) logger.debug("addNotificationListener"+
|
|
1052 |
"(ObjectName,ObjectName,NotificationFilter,Object)",
|
|
1053 |
"connectionId=" + connectionId
|
|
1054 |
+", name=" + name
|
|
1055 |
+", listenerName=" + listener
|
|
1056 |
+", filter=" + filterValue
|
|
1057 |
+", handback=" + handbackValue);
|
|
1058 |
|
|
1059 |
doPrivilegedOperation(
|
|
1060 |
ADD_NOTIFICATION_LISTENER_OBJECTNAME,
|
|
1061 |
params,
|
|
1062 |
delegationSubject);
|
|
1063 |
} catch (PrivilegedActionException pe) {
|
|
1064 |
Exception e = extractException(pe);
|
|
1065 |
if (e instanceof InstanceNotFoundException)
|
|
1066 |
throw (InstanceNotFoundException) e;
|
|
1067 |
if (e instanceof IOException)
|
|
1068 |
throw (IOException) e;
|
|
1069 |
throw newIOException("Got unexpected server exception: " + e, e);
|
|
1070 |
}
|
|
1071 |
}
|
|
1072 |
|
|
1073 |
public void removeNotificationListeners(ObjectName name,
|
|
1074 |
Integer[] listenerIDs,
|
|
1075 |
Subject delegationSubject)
|
|
1076 |
throws
|
|
1077 |
InstanceNotFoundException,
|
|
1078 |
ListenerNotFoundException,
|
|
1079 |
IOException {
|
|
1080 |
|
|
1081 |
if (name == null || listenerIDs == null)
|
|
1082 |
throw new IllegalArgumentException("Illegal null parameter");
|
|
1083 |
|
|
1084 |
for (int i = 0; i < listenerIDs.length; i++) {
|
|
1085 |
if (listenerIDs[i] == null)
|
|
1086 |
throw new IllegalArgumentException("Null listener ID");
|
|
1087 |
}
|
|
1088 |
|
|
1089 |
try {
|
|
1090 |
final Object params[] = new Object[] { name, listenerIDs };
|
|
1091 |
|
|
1092 |
if (logger.debugOn()) logger.debug("removeNotificationListener"+
|
|
1093 |
"(ObjectName,Integer[])",
|
|
1094 |
"connectionId=" + connectionId
|
|
1095 |
+", name=" + name
|
|
1096 |
+", listenerIDs=" + objects(listenerIDs));
|
|
1097 |
|
|
1098 |
doPrivilegedOperation(
|
|
1099 |
REMOVE_NOTIFICATION_LISTENER,
|
|
1100 |
params,
|
|
1101 |
delegationSubject);
|
|
1102 |
} catch (PrivilegedActionException pe) {
|
|
1103 |
Exception e = extractException(pe);
|
|
1104 |
if (e instanceof InstanceNotFoundException)
|
|
1105 |
throw (InstanceNotFoundException) e;
|
|
1106 |
if (e instanceof ListenerNotFoundException)
|
|
1107 |
throw (ListenerNotFoundException) e;
|
|
1108 |
if (e instanceof IOException)
|
|
1109 |
throw (IOException) e;
|
|
1110 |
throw newIOException("Got unexpected server exception: " + e, e);
|
|
1111 |
}
|
|
1112 |
}
|
|
1113 |
|
|
1114 |
public void removeNotificationListener(ObjectName name,
|
|
1115 |
ObjectName listener,
|
|
1116 |
Subject delegationSubject)
|
|
1117 |
throws
|
|
1118 |
InstanceNotFoundException,
|
|
1119 |
ListenerNotFoundException,
|
|
1120 |
IOException {
|
|
1121 |
|
|
1122 |
checkNonNull("Target MBean name", name);
|
|
1123 |
checkNonNull("Listener MBean name", listener);
|
|
1124 |
|
|
1125 |
try {
|
|
1126 |
final Object params[] = new Object[] { name, listener };
|
|
1127 |
|
|
1128 |
if (logger.debugOn()) logger.debug("removeNotificationListener"+
|
|
1129 |
"(ObjectName,ObjectName)",
|
|
1130 |
"connectionId=" + connectionId
|
|
1131 |
+", name=" + name
|
|
1132 |
+", listenerName=" + listener);
|
|
1133 |
|
|
1134 |
doPrivilegedOperation(
|
|
1135 |
REMOVE_NOTIFICATION_LISTENER_OBJECTNAME,
|
|
1136 |
params,
|
|
1137 |
delegationSubject);
|
|
1138 |
} catch (PrivilegedActionException pe) {
|
|
1139 |
Exception e = extractException(pe);
|
|
1140 |
if (e instanceof InstanceNotFoundException)
|
|
1141 |
throw (InstanceNotFoundException) e;
|
|
1142 |
if (e instanceof ListenerNotFoundException)
|
|
1143 |
throw (ListenerNotFoundException) e;
|
|
1144 |
if (e instanceof IOException)
|
|
1145 |
throw (IOException) e;
|
|
1146 |
throw newIOException("Got unexpected server exception: " + e, e);
|
|
1147 |
}
|
|
1148 |
}
|
|
1149 |
|
|
1150 |
public void removeNotificationListener(ObjectName name,
|
|
1151 |
ObjectName listener,
|
|
1152 |
MarshalledObject filter,
|
|
1153 |
MarshalledObject handback,
|
|
1154 |
Subject delegationSubject)
|
|
1155 |
throws
|
|
1156 |
InstanceNotFoundException,
|
|
1157 |
ListenerNotFoundException,
|
|
1158 |
IOException {
|
|
1159 |
|
|
1160 |
checkNonNull("Target MBean name", name);
|
|
1161 |
checkNonNull("Listener MBean name", listener);
|
|
1162 |
|
|
1163 |
final NotificationFilter filterValue;
|
|
1164 |
final Object handbackValue;
|
|
1165 |
final boolean debug=logger.debugOn();
|
|
1166 |
|
|
1167 |
final ClassLoader targetCl = getClassLoaderFor(name);
|
|
1168 |
|
|
1169 |
if (debug) logger.debug("removeNotificationListener"+
|
|
1170 |
"(ObjectName,ObjectName,NotificationFilter,Object)",
|
|
1171 |
"connectionId=" + connectionId
|
|
1172 |
+" unwrapping filter with target extended ClassLoader.");
|
|
1173 |
|
|
1174 |
filterValue =
|
|
1175 |
unwrap(filter, targetCl, defaultClassLoader, NotificationFilter.class);
|
|
1176 |
|
|
1177 |
if (debug) logger.debug("removeNotificationListener"+
|
|
1178 |
"(ObjectName,ObjectName,NotificationFilter,Object)",
|
|
1179 |
"connectionId=" + connectionId
|
|
1180 |
+" unwrapping handback with target extended ClassLoader.");
|
|
1181 |
|
|
1182 |
handbackValue =
|
|
1183 |
unwrap(handback, targetCl, defaultClassLoader, Object.class);
|
|
1184 |
|
|
1185 |
try {
|
|
1186 |
final Object params[] =
|
|
1187 |
new Object[] { name, listener, filterValue, handbackValue };
|
|
1188 |
|
|
1189 |
if (debug) logger.debug("removeNotificationListener"+
|
|
1190 |
"(ObjectName,ObjectName,NotificationFilter,Object)",
|
|
1191 |
"connectionId=" + connectionId
|
|
1192 |
+", name=" + name
|
|
1193 |
+", listenerName=" + listener
|
|
1194 |
+", filter=" + filterValue
|
|
1195 |
+", handback=" + handbackValue);
|
|
1196 |
|
|
1197 |
doPrivilegedOperation(
|
|
1198 |
REMOVE_NOTIFICATION_LISTENER_OBJECTNAME_FILTER_HANDBACK,
|
|
1199 |
params,
|
|
1200 |
delegationSubject);
|
|
1201 |
} catch (PrivilegedActionException pe) {
|
|
1202 |
Exception e = extractException(pe);
|
|
1203 |
if (e instanceof InstanceNotFoundException)
|
|
1204 |
throw (InstanceNotFoundException) e;
|
|
1205 |
if (e instanceof ListenerNotFoundException)
|
|
1206 |
throw (ListenerNotFoundException) e;
|
|
1207 |
if (e instanceof IOException)
|
|
1208 |
throw (IOException) e;
|
|
1209 |
throw newIOException("Got unexpected server exception: " + e, e);
|
|
1210 |
}
|
|
1211 |
}
|
|
1212 |
|
|
1213 |
public NotificationResult fetchNotifications(long clientSequenceNumber,
|
|
1214 |
int maxNotifications,
|
|
1215 |
long timeout)
|
|
1216 |
throws IOException {
|
|
1217 |
|
|
1218 |
if (logger.debugOn()) logger.debug("fetchNotifications",
|
|
1219 |
"connectionId=" + connectionId
|
|
1220 |
+", timeout=" + timeout);
|
|
1221 |
|
|
1222 |
if (maxNotifications < 0 || timeout < 0)
|
|
1223 |
throw new IllegalArgumentException("Illegal negative argument");
|
|
1224 |
|
|
1225 |
final boolean serverTerminated =
|
|
1226 |
serverCommunicatorAdmin.reqIncoming();
|
|
1227 |
try {
|
|
1228 |
if (serverTerminated) {
|
|
1229 |
// we must not call fetchNotifs() if the server is
|
|
1230 |
// terminated (timeout elapsed).
|
|
1231 |
//
|
|
1232 |
return new NotificationResult(0L, 0L,
|
|
1233 |
new TargetedNotification[0]);
|
|
1234 |
|
|
1235 |
}
|
|
1236 |
final long csn = clientSequenceNumber;
|
|
1237 |
final int mn = maxNotifications;
|
|
1238 |
final long t = timeout;
|
1004
|
1239 |
|
|
1240 |
final PrivilegedExceptionAction<NotificationResult> action =
|
|
1241 |
new PrivilegedExceptionAction<NotificationResult>() {
|
|
1242 |
public NotificationResult run() throws IOException {
|
|
1243 |
return doFetchNotifs(csn, t, mn);
|
2
|
1244 |
}
|
|
1245 |
};
|
1004
|
1246 |
try {
|
|
1247 |
if (acc == null)
|
|
1248 |
return action.run();
|
|
1249 |
else
|
|
1250 |
return AccessController.doPrivileged(action, acc);
|
|
1251 |
} catch (IOException x) {
|
|
1252 |
throw x;
|
|
1253 |
} catch (RuntimeException x) {
|
|
1254 |
throw x;
|
|
1255 |
} catch (Exception x) {
|
|
1256 |
// should not happen
|
|
1257 |
throw new UndeclaredThrowableException(x);
|
|
1258 |
}
|
|
1259 |
|
2
|
1260 |
} finally {
|
|
1261 |
serverCommunicatorAdmin.rspOutgoing();
|
|
1262 |
}
|
|
1263 |
}
|
|
1264 |
|
|
1265 |
/**
|
1004
|
1266 |
* This is an abstraction class that let us use the legacy
|
|
1267 |
* ServerNotifForwarder and the new EventClientDelegateMBean
|
|
1268 |
* indifferently.
|
|
1269 |
**/
|
|
1270 |
private static interface SubscriptionManager {
|
|
1271 |
public void removeNotificationListener(ObjectName name, Integer id)
|
|
1272 |
throws InstanceNotFoundException, ListenerNotFoundException, IOException;
|
|
1273 |
public void removeNotificationListener(ObjectName name, Integer[] ids)
|
|
1274 |
throws Exception;
|
|
1275 |
public NotificationResult fetchNotifications(long csn, long timeout, int maxcount)
|
|
1276 |
throws IOException;
|
|
1277 |
public Integer addNotificationListener(ObjectName name, NotificationFilter filter)
|
|
1278 |
throws InstanceNotFoundException, IOException;
|
|
1279 |
public void terminate()
|
|
1280 |
throws IOException;
|
|
1281 |
}
|
|
1282 |
|
|
1283 |
/**
|
|
1284 |
* A SubscriptionManager that uses a ServerNotifForwarder.
|
|
1285 |
**/
|
|
1286 |
private static class LegacySubscriptionManager implements SubscriptionManager {
|
|
1287 |
private final ServerNotifForwarder forwarder;
|
|
1288 |
LegacySubscriptionManager(ServerNotifForwarder forwarder) {
|
|
1289 |
this.forwarder = forwarder;
|
|
1290 |
}
|
|
1291 |
|
|
1292 |
public void removeNotificationListener(ObjectName name, Integer id)
|
|
1293 |
throws InstanceNotFoundException, ListenerNotFoundException,
|
|
1294 |
IOException {
|
|
1295 |
forwarder.removeNotificationListener(name,id);
|
|
1296 |
}
|
|
1297 |
|
|
1298 |
public void removeNotificationListener(ObjectName name, Integer[] ids)
|
|
1299 |
throws Exception {
|
|
1300 |
forwarder.removeNotificationListener(name,ids);
|
|
1301 |
}
|
|
1302 |
|
|
1303 |
public NotificationResult fetchNotifications(long csn, long timeout, int maxcount) {
|
|
1304 |
return forwarder.fetchNotifs(csn,timeout,maxcount);
|
|
1305 |
}
|
|
1306 |
|
|
1307 |
public Integer addNotificationListener(ObjectName name,
|
|
1308 |
NotificationFilter filter)
|
|
1309 |
throws InstanceNotFoundException, IOException {
|
|
1310 |
return forwarder.addNotificationListener(name,filter);
|
|
1311 |
}
|
|
1312 |
|
|
1313 |
public void terminate() {
|
|
1314 |
forwarder.terminate();
|
|
1315 |
}
|
|
1316 |
}
|
|
1317 |
|
|
1318 |
/**
|
|
1319 |
* A SubscriptionManager that uses an EventClientDelegateMBean.
|
|
1320 |
**/
|
|
1321 |
private static class EventSubscriptionManager
|
|
1322 |
implements SubscriptionManager {
|
|
1323 |
private final MBeanServer mbeanServer;
|
|
1324 |
private final EventClientDelegateMBean delegate;
|
|
1325 |
private final NotificationAccessController notifAC;
|
|
1326 |
private final boolean checkNotificationEmission;
|
|
1327 |
private final String clientId;
|
|
1328 |
private final String connectionId;
|
|
1329 |
|
|
1330 |
EventSubscriptionManager(
|
|
1331 |
MBeanServer mbeanServer,
|
|
1332 |
EventClientDelegateMBean delegate,
|
|
1333 |
Map<String, ?> env,
|
|
1334 |
String clientId,
|
|
1335 |
String connectionId) {
|
|
1336 |
this.mbeanServer = mbeanServer;
|
|
1337 |
this.delegate = delegate;
|
|
1338 |
this.notifAC = EnvHelp.getNotificationAccessController(env);
|
|
1339 |
this.checkNotificationEmission =
|
|
1340 |
EnvHelp.computeBooleanFromString(
|
|
1341 |
env, "jmx.remote.x.check.notification.emission", false);
|
|
1342 |
this.clientId = clientId;
|
|
1343 |
this.connectionId = connectionId;
|
|
1344 |
}
|
|
1345 |
|
|
1346 |
@SuppressWarnings("serial") // no serialVersionUID
|
|
1347 |
private class AccessControlFilter implements NotificationFilter {
|
|
1348 |
private final NotificationFilter wrapped;
|
|
1349 |
private final ObjectName name;
|
|
1350 |
|
|
1351 |
AccessControlFilter(ObjectName name, NotificationFilter wrapped) {
|
|
1352 |
this.name = name;
|
|
1353 |
this.wrapped = wrapped;
|
|
1354 |
}
|
|
1355 |
|
|
1356 |
public boolean isNotificationEnabled(Notification notification) {
|
|
1357 |
try {
|
|
1358 |
if (checkNotificationEmission) {
|
|
1359 |
ServerNotifForwarder.checkMBeanPermission(
|
|
1360 |
mbeanServer, name, "addNotificationListener");
|
|
1361 |
}
|
|
1362 |
notifAC.fetchNotification(
|
|
1363 |
connectionId, name, notification, getSubject());
|
|
1364 |
return (wrapped == null) ? true :
|
|
1365 |
wrapped.isNotificationEnabled(notification);
|
|
1366 |
} catch (InstanceNotFoundException e) {
|
|
1367 |
return false;
|
|
1368 |
} catch (SecurityException e) {
|
|
1369 |
return false;
|
|
1370 |
}
|
|
1371 |
}
|
|
1372 |
|
|
1373 |
}
|
|
1374 |
|
|
1375 |
public Integer addNotificationListener(
|
|
1376 |
ObjectName name, NotificationFilter filter)
|
|
1377 |
throws InstanceNotFoundException, IOException {
|
|
1378 |
if (notifAC != null) {
|
|
1379 |
notifAC.addNotificationListener(connectionId, name, getSubject());
|
|
1380 |
filter = new AccessControlFilter(name, filter);
|
|
1381 |
}
|
|
1382 |
try {
|
|
1383 |
return delegate.addListener(clientId,name,filter);
|
|
1384 |
} catch (EventClientNotFoundException x) {
|
|
1385 |
throw new IOException("Unknown clientId: "+clientId,x);
|
|
1386 |
}
|
|
1387 |
}
|
|
1388 |
|
|
1389 |
public void removeNotificationListener(ObjectName name, Integer id)
|
|
1390 |
throws InstanceNotFoundException, ListenerNotFoundException,
|
|
1391 |
IOException {
|
|
1392 |
if (notifAC != null)
|
|
1393 |
notifAC.removeNotificationListener(connectionId, name, getSubject());
|
|
1394 |
try {
|
|
1395 |
delegate.removeListenerOrSubscriber(clientId,id);
|
|
1396 |
} catch (EventClientNotFoundException x) {
|
|
1397 |
throw new IOException("Unknown clientId: "+clientId,x);
|
|
1398 |
}
|
|
1399 |
}
|
|
1400 |
|
|
1401 |
public void removeNotificationListener(ObjectName name, Integer[] ids)
|
|
1402 |
throws InstanceNotFoundException, ListenerNotFoundException,
|
|
1403 |
IOException {
|
|
1404 |
if (notifAC != null)
|
|
1405 |
notifAC.removeNotificationListener(connectionId, name, getSubject());
|
|
1406 |
try {
|
|
1407 |
for (Integer id : ids)
|
|
1408 |
delegate.removeListenerOrSubscriber(clientId,id);
|
|
1409 |
} catch (EventClientNotFoundException x) {
|
|
1410 |
throw new IOException("Unknown clientId: "+clientId,x);
|
|
1411 |
}
|
|
1412 |
}
|
|
1413 |
|
|
1414 |
public NotificationResult fetchNotifications(long csn, long timeout,
|
|
1415 |
int maxcount)
|
|
1416 |
throws IOException {
|
|
1417 |
try {
|
|
1418 |
// For some reason the delegate doesn't accept a negative
|
|
1419 |
// sequence number. However legacy clients will always call
|
|
1420 |
// fetchNotifications with a negative sequence number, when
|
|
1421 |
// they call it for the first time.
|
|
1422 |
// In that case, we will use 0 instead.
|
|
1423 |
//
|
|
1424 |
return delegate.fetchNotifications(
|
|
1425 |
clientId, Math.max(csn, 0), maxcount, timeout);
|
|
1426 |
} catch (EventClientNotFoundException x) {
|
|
1427 |
throw new IOException("Unknown clientId: "+clientId,x);
|
|
1428 |
}
|
|
1429 |
}
|
|
1430 |
|
|
1431 |
public void terminate()
|
|
1432 |
throws IOException {
|
|
1433 |
try {
|
|
1434 |
delegate.removeClient(clientId);
|
|
1435 |
} catch (EventClientNotFoundException x) {
|
|
1436 |
throw new IOException("Unknown clientId: "+clientId,x);
|
|
1437 |
}
|
|
1438 |
}
|
|
1439 |
|
|
1440 |
private static Subject getSubject() {
|
|
1441 |
return Subject.getSubject(AccessController.getContext());
|
|
1442 |
}
|
|
1443 |
}
|
|
1444 |
|
|
1445 |
/**
|
|
1446 |
* Creates a SubscriptionManager that uses either the legacy notifications
|
|
1447 |
* mechanism (ServerNotifForwarder) or the new event service
|
|
1448 |
* (EventClientDelegateMBean) depending on which option was passed in
|
|
1449 |
* the connector's map.
|
|
1450 |
**/
|
|
1451 |
private SubscriptionManager createSubscriptionManager()
|
|
1452 |
throws IOException {
|
|
1453 |
if (EnvHelp.delegateToEventService(env) &&
|
|
1454 |
mbeanServer.isRegistered(EventClientDelegate.OBJECT_NAME)) {
|
|
1455 |
final EventClientDelegateMBean mbean =
|
|
1456 |
JMX.newMBeanProxy(mbeanServer,
|
|
1457 |
EventClientDelegate.OBJECT_NAME,
|
|
1458 |
EventClientDelegateMBean.class);
|
|
1459 |
String clientId;
|
|
1460 |
try {
|
|
1461 |
clientId =
|
|
1462 |
mbean.addClient(
|
|
1463 |
FetchingEventForwarder.class.getName(),
|
|
1464 |
new Object[] {EnvHelp.getNotifBufferSize(env)},
|
|
1465 |
new String[] {int.class.getName()});
|
|
1466 |
} catch (Exception e) {
|
|
1467 |
if (e instanceof IOException)
|
|
1468 |
throw (IOException) e;
|
|
1469 |
else
|
|
1470 |
throw new IOException(e);
|
|
1471 |
}
|
|
1472 |
|
|
1473 |
// we're going to call remove client...
|
|
1474 |
try {
|
|
1475 |
mbean.lease(clientId, Long.MAX_VALUE);
|
|
1476 |
} catch (EventClientNotFoundException x) {
|
|
1477 |
throw new IOException("Unknown clientId: "+clientId,x);
|
|
1478 |
}
|
|
1479 |
return new EventSubscriptionManager(mbeanServer, mbean, env,
|
|
1480 |
clientId, connectionId);
|
|
1481 |
} else {
|
|
1482 |
final ServerNotifForwarder serverNotifForwarder =
|
|
1483 |
new ServerNotifForwarder(mbeanServer,
|
|
1484 |
env,
|
|
1485 |
rmiServer.getNotifBuffer(),
|
|
1486 |
connectionId);
|
|
1487 |
return new LegacySubscriptionManager(serverNotifForwarder);
|
|
1488 |
}
|
|
1489 |
}
|
|
1490 |
|
|
1491 |
/**
|
|
1492 |
* Lazy creation of a SubscriptionManager.
|
|
1493 |
**/
|
|
1494 |
private synchronized SubscriptionManager getSubscriptionManager()
|
|
1495 |
throws IOException {
|
|
1496 |
// Lazily created when first use. Mainly when
|
|
1497 |
// addNotificationListener is first called.
|
|
1498 |
|
|
1499 |
if (subscriptionManager == null) {
|
|
1500 |
subscriptionManager = createSubscriptionManager();
|
|
1501 |
}
|
|
1502 |
return subscriptionManager;
|
|
1503 |
}
|
|
1504 |
|
|
1505 |
// calls SubscriptionManager.
|
|
1506 |
private void doRemoveListener(ObjectName name, Integer id)
|
|
1507 |
throws InstanceNotFoundException, ListenerNotFoundException,
|
|
1508 |
IOException {
|
|
1509 |
getSubscriptionManager().removeNotificationListener(name,id);
|
|
1510 |
}
|
|
1511 |
|
|
1512 |
// calls SubscriptionManager.
|
|
1513 |
private void doRemoveListener(ObjectName name, Integer[] ids)
|
|
1514 |
throws Exception {
|
|
1515 |
getSubscriptionManager().removeNotificationListener(name,ids);
|
|
1516 |
}
|
|
1517 |
|
|
1518 |
// calls SubscriptionManager.
|
|
1519 |
private NotificationResult doFetchNotifs(long csn, long timeout, int maxcount)
|
|
1520 |
throws IOException {
|
|
1521 |
return getSubscriptionManager().fetchNotifications(csn, timeout, maxcount);
|
|
1522 |
}
|
|
1523 |
|
|
1524 |
// calls SubscriptionManager.
|
|
1525 |
private Integer doAddListener(ObjectName name, NotificationFilter filter)
|
|
1526 |
throws InstanceNotFoundException, IOException {
|
|
1527 |
return getSubscriptionManager().addNotificationListener(name,filter);
|
|
1528 |
}
|
|
1529 |
|
|
1530 |
|
|
1531 |
/**
|
2
|
1532 |
* <p>Returns a string representation of this object. In general,
|
|
1533 |
* the <code>toString</code> method returns a string that
|
|
1534 |
* "textually represents" this object. The result should be a
|
|
1535 |
* concise but informative representation that is easy for a
|
|
1536 |
* person to read.</p>
|
|
1537 |
*
|
|
1538 |
* @return a String representation of this object.
|
|
1539 |
**/
|
|
1540 |
public String toString() {
|
|
1541 |
return super.toString() + ": connectionId=" + connectionId;
|
|
1542 |
}
|
|
1543 |
|
|
1544 |
//------------------------------------------------------------------------
|
|
1545 |
// private classes
|
|
1546 |
//------------------------------------------------------------------------
|
|
1547 |
|
|
1548 |
private class PrivilegedOperation
|
|
1549 |
implements PrivilegedExceptionAction<Object> {
|
|
1550 |
|
|
1551 |
public PrivilegedOperation(int operation, Object[] params) {
|
|
1552 |
this.operation = operation;
|
|
1553 |
this.params = params;
|
|
1554 |
}
|
|
1555 |
|
|
1556 |
public Object run() throws Exception {
|
|
1557 |
return doOperation(operation, params);
|
|
1558 |
}
|
|
1559 |
|
|
1560 |
private int operation;
|
|
1561 |
private Object[] params;
|
|
1562 |
}
|
|
1563 |
|
|
1564 |
//------------------------------------------------------------------------
|
|
1565 |
// private classes
|
|
1566 |
//------------------------------------------------------------------------
|
|
1567 |
private class RMIServerCommunicatorAdmin extends ServerCommunicatorAdmin {
|
|
1568 |
public RMIServerCommunicatorAdmin(long timeout) {
|
|
1569 |
super(timeout);
|
|
1570 |
}
|
|
1571 |
|
|
1572 |
protected void doStop() {
|
|
1573 |
try {
|
|
1574 |
close();
|
|
1575 |
} catch (IOException ie) {
|
|
1576 |
logger.warning("RMIServerCommunicatorAdmin-doStop",
|
|
1577 |
"Failed to close: " + ie);
|
|
1578 |
logger.debug("RMIServerCommunicatorAdmin-doStop",ie);
|
|
1579 |
}
|
|
1580 |
}
|
|
1581 |
|
|
1582 |
}
|
|
1583 |
|
|
1584 |
|
|
1585 |
//------------------------------------------------------------------------
|
|
1586 |
// private methods
|
|
1587 |
//------------------------------------------------------------------------
|
|
1588 |
|
|
1589 |
private ClassLoader getClassLoader(final ObjectName name)
|
|
1590 |
throws InstanceNotFoundException {
|
|
1591 |
try {
|
|
1592 |
return
|
|
1593 |
AccessController.doPrivileged(
|
|
1594 |
new PrivilegedExceptionAction<ClassLoader>() {
|
|
1595 |
public ClassLoader run() throws InstanceNotFoundException {
|
|
1596 |
return mbeanServer.getClassLoader(name);
|
|
1597 |
}
|
|
1598 |
});
|
|
1599 |
} catch (PrivilegedActionException pe) {
|
|
1600 |
throw (InstanceNotFoundException) extractException(pe);
|
|
1601 |
}
|
|
1602 |
}
|
|
1603 |
|
|
1604 |
private ClassLoader getClassLoaderFor(final ObjectName name)
|
|
1605 |
throws InstanceNotFoundException {
|
|
1606 |
try {
|
|
1607 |
return (ClassLoader)
|
|
1608 |
AccessController.doPrivileged(
|
|
1609 |
new PrivilegedExceptionAction<Object>() {
|
|
1610 |
public Object run() throws InstanceNotFoundException {
|
|
1611 |
return mbeanServer.getClassLoaderFor(name);
|
|
1612 |
}
|
|
1613 |
});
|
|
1614 |
} catch (PrivilegedActionException pe) {
|
|
1615 |
throw (InstanceNotFoundException) extractException(pe);
|
|
1616 |
}
|
|
1617 |
}
|
|
1618 |
|
|
1619 |
private Object doPrivilegedOperation(final int operation,
|
|
1620 |
final Object[] params,
|
|
1621 |
final Subject delegationSubject)
|
|
1622 |
throws PrivilegedActionException, IOException {
|
|
1623 |
|
|
1624 |
serverCommunicatorAdmin.reqIncoming();
|
|
1625 |
try {
|
|
1626 |
|
|
1627 |
final AccessControlContext reqACC;
|
|
1628 |
if (delegationSubject == null)
|
|
1629 |
reqACC = acc;
|
|
1630 |
else {
|
|
1631 |
if (subject == null) {
|
|
1632 |
final String msg =
|
|
1633 |
"Subject delegation cannot be enabled unless " +
|
|
1634 |
"an authenticated subject is put in place";
|
|
1635 |
throw new SecurityException(msg);
|
|
1636 |
}
|
|
1637 |
reqACC = subjectDelegator.delegatedContext(
|
|
1638 |
acc, delegationSubject, removeCallerContext);
|
|
1639 |
}
|
|
1640 |
|
|
1641 |
PrivilegedOperation op =
|
|
1642 |
new PrivilegedOperation(operation, params);
|
|
1643 |
if (reqACC == null) {
|
|
1644 |
try {
|
|
1645 |
return op.run();
|
|
1646 |
} catch (Exception e) {
|
|
1647 |
if (e instanceof RuntimeException)
|
|
1648 |
throw (RuntimeException) e;
|
|
1649 |
throw new PrivilegedActionException(e);
|
|
1650 |
}
|
|
1651 |
} else {
|
|
1652 |
return AccessController.doPrivileged(op, reqACC);
|
|
1653 |
}
|
|
1654 |
} catch (Error e) {
|
|
1655 |
throw new JMXServerErrorException(e.toString(),e);
|
|
1656 |
} finally {
|
|
1657 |
serverCommunicatorAdmin.rspOutgoing();
|
|
1658 |
}
|
|
1659 |
}
|
|
1660 |
|
|
1661 |
private Object doOperation(int operation, Object[] params)
|
|
1662 |
throws Exception {
|
|
1663 |
|
|
1664 |
switch (operation) {
|
|
1665 |
|
|
1666 |
case CREATE_MBEAN:
|
|
1667 |
return mbeanServer.createMBean((String)params[0],
|
|
1668 |
(ObjectName)params[1]);
|
|
1669 |
|
|
1670 |
case CREATE_MBEAN_LOADER:
|
|
1671 |
return mbeanServer.createMBean((String)params[0],
|
|
1672 |
(ObjectName)params[1],
|
|
1673 |
(ObjectName)params[2]);
|
|
1674 |
|
|
1675 |
case CREATE_MBEAN_PARAMS:
|
|
1676 |
return mbeanServer.createMBean((String)params[0],
|
|
1677 |
(ObjectName)params[1],
|
|
1678 |
(Object[])params[2],
|
|
1679 |
(String[])params[3]);
|
|
1680 |
|
|
1681 |
case CREATE_MBEAN_LOADER_PARAMS:
|
|
1682 |
return mbeanServer.createMBean((String)params[0],
|
|
1683 |
(ObjectName)params[1],
|
|
1684 |
(ObjectName)params[2],
|
|
1685 |
(Object[])params[3],
|
|
1686 |
(String[])params[4]);
|
|
1687 |
|
|
1688 |
case GET_ATTRIBUTE:
|
|
1689 |
return mbeanServer.getAttribute((ObjectName)params[0],
|
|
1690 |
(String)params[1]);
|
|
1691 |
|
|
1692 |
case GET_ATTRIBUTES:
|
|
1693 |
return mbeanServer.getAttributes((ObjectName)params[0],
|
|
1694 |
(String[])params[1]);
|
|
1695 |
|
|
1696 |
case GET_DEFAULT_DOMAIN:
|
|
1697 |
return mbeanServer.getDefaultDomain();
|
|
1698 |
|
|
1699 |
case GET_DOMAINS:
|
|
1700 |
return mbeanServer.getDomains();
|
|
1701 |
|
|
1702 |
case GET_MBEAN_COUNT:
|
|
1703 |
return mbeanServer.getMBeanCount();
|
|
1704 |
|
|
1705 |
case GET_MBEAN_INFO:
|
|
1706 |
return mbeanServer.getMBeanInfo((ObjectName)params[0]);
|
|
1707 |
|
|
1708 |
case GET_OBJECT_INSTANCE:
|
|
1709 |
return mbeanServer.getObjectInstance((ObjectName)params[0]);
|
|
1710 |
|
|
1711 |
case INVOKE:
|
|
1712 |
return mbeanServer.invoke((ObjectName)params[0],
|
|
1713 |
(String)params[1],
|
|
1714 |
(Object[])params[2],
|
|
1715 |
(String[])params[3]);
|
|
1716 |
|
|
1717 |
case IS_INSTANCE_OF:
|
|
1718 |
return mbeanServer.isInstanceOf((ObjectName)params[0],
|
|
1719 |
(String)params[1])
|
|
1720 |
? Boolean.TRUE : Boolean.FALSE;
|
|
1721 |
|
|
1722 |
case IS_REGISTERED:
|
|
1723 |
return mbeanServer.isRegistered((ObjectName)params[0])
|
|
1724 |
? Boolean.TRUE : Boolean.FALSE;
|
|
1725 |
|
|
1726 |
case QUERY_MBEANS:
|
|
1727 |
return mbeanServer.queryMBeans((ObjectName)params[0],
|
|
1728 |
(QueryExp)params[1]);
|
|
1729 |
|
|
1730 |
case QUERY_NAMES:
|
|
1731 |
return mbeanServer.queryNames((ObjectName)params[0],
|
|
1732 |
(QueryExp)params[1]);
|
|
1733 |
|
|
1734 |
case SET_ATTRIBUTE:
|
|
1735 |
mbeanServer.setAttribute((ObjectName)params[0],
|
|
1736 |
(Attribute)params[1]);
|
|
1737 |
return null;
|
|
1738 |
|
|
1739 |
case SET_ATTRIBUTES:
|
|
1740 |
return mbeanServer.setAttributes((ObjectName)params[0],
|
|
1741 |
(AttributeList)params[1]);
|
|
1742 |
|
|
1743 |
case UNREGISTER_MBEAN:
|
|
1744 |
mbeanServer.unregisterMBean((ObjectName)params[0]);
|
|
1745 |
return null;
|
|
1746 |
|
|
1747 |
case ADD_NOTIFICATION_LISTENERS:
|
1004
|
1748 |
return doAddListener((ObjectName)params[0],
|
|
1749 |
(NotificationFilter)params[1]);
|
2
|
1750 |
|
|
1751 |
case ADD_NOTIFICATION_LISTENER_OBJECTNAME:
|
|
1752 |
mbeanServer.addNotificationListener((ObjectName)params[0],
|
|
1753 |
(ObjectName)params[1],
|
|
1754 |
(NotificationFilter)params[2],
|
|
1755 |
params[3]);
|
|
1756 |
return null;
|
|
1757 |
|
|
1758 |
case REMOVE_NOTIFICATION_LISTENER:
|
1004
|
1759 |
doRemoveListener((ObjectName)params[0],(Integer[])params[1]);
|
2
|
1760 |
return null;
|
|
1761 |
|
|
1762 |
case REMOVE_NOTIFICATION_LISTENER_OBJECTNAME:
|
|
1763 |
mbeanServer.removeNotificationListener((ObjectName)params[0],
|
|
1764 |
(ObjectName)params[1]);
|
|
1765 |
return null;
|
|
1766 |
|
|
1767 |
case REMOVE_NOTIFICATION_LISTENER_OBJECTNAME_FILTER_HANDBACK:
|
|
1768 |
mbeanServer.removeNotificationListener(
|
|
1769 |
(ObjectName)params[0],
|
|
1770 |
(ObjectName)params[1],
|
|
1771 |
(NotificationFilter)params[2],
|
|
1772 |
params[3]);
|
|
1773 |
return null;
|
|
1774 |
|
|
1775 |
default:
|
|
1776 |
throw new IllegalArgumentException("Invalid operation");
|
|
1777 |
}
|
|
1778 |
}
|
|
1779 |
|
|
1780 |
private static <T> T unwrap(final MarshalledObject mo,
|
|
1781 |
final ClassLoader cl,
|
|
1782 |
final Class<T> wrappedClass)
|
|
1783 |
throws IOException {
|
|
1784 |
if (mo == null) {
|
|
1785 |
return null;
|
|
1786 |
}
|
|
1787 |
try {
|
|
1788 |
return AccessController.doPrivileged(
|
|
1789 |
new PrivilegedExceptionAction<T>() {
|
|
1790 |
public T run()
|
|
1791 |
throws IOException {
|
|
1792 |
final ClassLoader old =
|
|
1793 |
Thread.currentThread().getContextClassLoader();
|
|
1794 |
Thread.currentThread().setContextClassLoader(cl);
|
|
1795 |
try {
|
|
1796 |
return wrappedClass.cast(mo.get());
|
|
1797 |
} catch (ClassNotFoundException cnfe) {
|
|
1798 |
throw new UnmarshalException(cnfe.toString(), cnfe);
|
|
1799 |
} finally {
|
|
1800 |
Thread.currentThread().setContextClassLoader(old);
|
|
1801 |
}
|
|
1802 |
}
|
|
1803 |
});
|
|
1804 |
} catch (PrivilegedActionException pe) {
|
|
1805 |
Exception e = extractException(pe);
|
|
1806 |
if (e instanceof IOException) {
|
|
1807 |
throw (IOException) e;
|
|
1808 |
}
|
|
1809 |
if (e instanceof ClassNotFoundException) {
|
|
1810 |
throw new UnmarshalException(e.toString(), e);
|
|
1811 |
}
|
|
1812 |
logger.warning("unwrap", "Failed to unmarshall object: " + e);
|
|
1813 |
logger.debug("unwrap", e);
|
|
1814 |
}
|
|
1815 |
return null;
|
|
1816 |
}
|
|
1817 |
|
|
1818 |
private static <T> T unwrap(final MarshalledObject mo,
|
|
1819 |
final ClassLoader cl1,
|
|
1820 |
final ClassLoader cl2,
|
|
1821 |
final Class<T> wrappedClass)
|
|
1822 |
throws IOException {
|
|
1823 |
if (mo == null) {
|
|
1824 |
return null;
|
|
1825 |
}
|
|
1826 |
try {
|
|
1827 |
return AccessController.doPrivileged(
|
|
1828 |
new PrivilegedExceptionAction<T>() {
|
|
1829 |
public T run()
|
|
1830 |
throws IOException {
|
|
1831 |
return unwrap(mo, new OrderClassLoaders(cl1, cl2),
|
|
1832 |
wrappedClass);
|
|
1833 |
}
|
|
1834 |
});
|
|
1835 |
} catch (PrivilegedActionException pe) {
|
|
1836 |
Exception e = extractException(pe);
|
|
1837 |
if (e instanceof IOException) {
|
|
1838 |
throw (IOException) e;
|
|
1839 |
}
|
|
1840 |
if (e instanceof ClassNotFoundException) {
|
|
1841 |
throw new UnmarshalException(e.toString(), e);
|
|
1842 |
}
|
|
1843 |
logger.warning("unwrap", "Failed to unmarshall object: " + e);
|
|
1844 |
logger.debug("unwrap", e);
|
|
1845 |
}
|
|
1846 |
return null;
|
|
1847 |
}
|
|
1848 |
|
|
1849 |
/**
|
|
1850 |
* Construct a new IOException with a nested exception.
|
|
1851 |
* The nested exception is set only if JDK >= 1.4
|
|
1852 |
*/
|
|
1853 |
private static IOException newIOException(String message,
|
|
1854 |
Throwable cause) {
|
|
1855 |
final IOException x = new IOException(message);
|
|
1856 |
return EnvHelp.initCause(x,cause);
|
|
1857 |
}
|
|
1858 |
|
|
1859 |
/**
|
|
1860 |
* Iterate until we extract the real exception
|
|
1861 |
* from a stack of PrivilegedActionExceptions.
|
|
1862 |
*/
|
|
1863 |
private static Exception extractException(Exception e) {
|
|
1864 |
while (e instanceof PrivilegedActionException) {
|
|
1865 |
e = ((PrivilegedActionException)e).getException();
|
|
1866 |
}
|
|
1867 |
return e;
|
|
1868 |
}
|
|
1869 |
|
|
1870 |
private static final Object[] NO_OBJECTS = new Object[0];
|
|
1871 |
private static final String[] NO_STRINGS = new String[0];
|
|
1872 |
|
|
1873 |
/*
|
|
1874 |
* The JMX spec doesn't explicitly say that a null Object[] or
|
|
1875 |
* String[] in e.g. MBeanServer.invoke is equivalent to an empty
|
|
1876 |
* array, but the RI behaves that way. In the interests of
|
|
1877 |
* maximal interoperability, we make it so even when we're
|
|
1878 |
* connected to some other JMX implementation that might not do
|
|
1879 |
* that. This should be clarified in the next version of JMX.
|
|
1880 |
*/
|
|
1881 |
private static Object[] nullIsEmpty(Object[] array) {
|
|
1882 |
return (array == null) ? NO_OBJECTS : array;
|
|
1883 |
}
|
|
1884 |
|
|
1885 |
private static String[] nullIsEmpty(String[] array) {
|
|
1886 |
return (array == null) ? NO_STRINGS : array;
|
|
1887 |
}
|
|
1888 |
|
|
1889 |
/*
|
|
1890 |
* Similarly, the JMX spec says for some but not all methods in
|
|
1891 |
* MBeanServer that take an ObjectName target, that if it's null
|
|
1892 |
* you get this exception. We specify it for all of them, and
|
|
1893 |
* make it so for the ones where it's not specified in JMX even if
|
|
1894 |
* the JMX implementation doesn't do so.
|
|
1895 |
*/
|
|
1896 |
private static void checkNonNull(String what, Object x) {
|
|
1897 |
if (x == null) {
|
|
1898 |
RuntimeException wrapped =
|
|
1899 |
new IllegalArgumentException(what + " must not be null");
|
|
1900 |
throw new RuntimeOperationsException(wrapped);
|
|
1901 |
}
|
|
1902 |
}
|
|
1903 |
|
|
1904 |
//------------------------------------------------------------------------
|
|
1905 |
// private variables
|
|
1906 |
//------------------------------------------------------------------------
|
|
1907 |
|
|
1908 |
private final Subject subject;
|
|
1909 |
|
|
1910 |
private final SubjectDelegator subjectDelegator;
|
|
1911 |
|
|
1912 |
private final boolean removeCallerContext;
|
|
1913 |
|
|
1914 |
private final AccessControlContext acc;
|
|
1915 |
|
|
1916 |
private final RMIServerImpl rmiServer;
|
|
1917 |
|
|
1918 |
private final MBeanServer mbeanServer;
|
|
1919 |
|
|
1920 |
private final ClassLoader defaultClassLoader;
|
|
1921 |
|
|
1922 |
private final ClassLoaderWithRepository classLoaderWithRepository;
|
|
1923 |
|
|
1924 |
private boolean terminated = false;
|
|
1925 |
|
|
1926 |
private final String connectionId;
|
|
1927 |
|
|
1928 |
private final ServerCommunicatorAdmin serverCommunicatorAdmin;
|
|
1929 |
|
|
1930 |
// Method IDs for doOperation
|
|
1931 |
//---------------------------
|
|
1932 |
|
|
1933 |
private final static int
|
|
1934 |
ADD_NOTIFICATION_LISTENERS = 1;
|
|
1935 |
private final static int
|
|
1936 |
ADD_NOTIFICATION_LISTENER_OBJECTNAME = 2;
|
|
1937 |
private final static int
|
|
1938 |
CREATE_MBEAN = 3;
|
|
1939 |
private final static int
|
|
1940 |
CREATE_MBEAN_PARAMS = 4;
|
|
1941 |
private final static int
|
|
1942 |
CREATE_MBEAN_LOADER = 5;
|
|
1943 |
private final static int
|
|
1944 |
CREATE_MBEAN_LOADER_PARAMS = 6;
|
|
1945 |
private final static int
|
|
1946 |
GET_ATTRIBUTE = 7;
|
|
1947 |
private final static int
|
|
1948 |
GET_ATTRIBUTES = 8;
|
|
1949 |
private final static int
|
|
1950 |
GET_DEFAULT_DOMAIN = 9;
|
|
1951 |
private final static int
|
|
1952 |
GET_DOMAINS = 10;
|
|
1953 |
private final static int
|
|
1954 |
GET_MBEAN_COUNT = 11;
|
|
1955 |
private final static int
|
|
1956 |
GET_MBEAN_INFO = 12;
|
|
1957 |
private final static int
|
|
1958 |
GET_OBJECT_INSTANCE = 13;
|
|
1959 |
private final static int
|
|
1960 |
INVOKE = 14;
|
|
1961 |
private final static int
|
|
1962 |
IS_INSTANCE_OF = 15;
|
|
1963 |
private final static int
|
|
1964 |
IS_REGISTERED = 16;
|
|
1965 |
private final static int
|
|
1966 |
QUERY_MBEANS = 17;
|
|
1967 |
private final static int
|
|
1968 |
QUERY_NAMES = 18;
|
|
1969 |
private final static int
|
|
1970 |
REMOVE_NOTIFICATION_LISTENER = 19;
|
|
1971 |
private final static int
|
1004
|
1972 |
REMOVE_NOTIFICATION_LISTENER_OBJECTNAME = 20;
|
2
|
1973 |
private final static int
|
1004
|
1974 |
REMOVE_NOTIFICATION_LISTENER_OBJECTNAME_FILTER_HANDBACK = 21;
|
2
|
1975 |
private final static int
|
1004
|
1976 |
SET_ATTRIBUTE = 22;
|
2
|
1977 |
private final static int
|
1004
|
1978 |
SET_ATTRIBUTES = 23;
|
2
|
1979 |
private final static int
|
1004
|
1980 |
UNREGISTER_MBEAN = 24;
|
2
|
1981 |
|
|
1982 |
// SERVER NOTIFICATION
|
|
1983 |
//--------------------
|
|
1984 |
|
1004
|
1985 |
private SubscriptionManager subscriptionManager;
|
|
1986 |
private Map<String, ?> env;
|
2
|
1987 |
|
|
1988 |
// TRACES & DEBUG
|
|
1989 |
//---------------
|
|
1990 |
|
|
1991 |
private static String objects(final Object[] objs) {
|
|
1992 |
if (objs == null)
|
|
1993 |
return "null";
|
|
1994 |
else
|
|
1995 |
return Arrays.asList(objs).toString();
|
|
1996 |
}
|
|
1997 |
|
|
1998 |
private static String strings(final String[] strs) {
|
|
1999 |
return objects(strs);
|
|
2000 |
}
|
|
2001 |
|
|
2002 |
private static final ClassLogger logger =
|
|
2003 |
new ClassLogger("javax.management.remote.rmi", "RMIConnectionImpl");
|
|
2004 |
}
|