Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.management/share/classes/com/sun/jmx/mbeanserver/JmxMBeanServer.java
41161 views
1
/*
2
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle 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 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.
24
*/
25
26
package com.sun.jmx.mbeanserver;
27
28
import com.sun.jmx.interceptor.DefaultMBeanServerInterceptor;
29
import com.sun.jmx.interceptor.MBeanServerInterceptor;
30
import static com.sun.jmx.defaults.JmxProperties.MBEANSERVER_LOGGER;
31
32
import java.io.ObjectInputStream;
33
import java.security.AccessController;
34
import java.security.Permission;
35
import java.security.PrivilegedAction;
36
import java.security.PrivilegedExceptionAction;
37
import java.util.List;
38
import java.util.Set;
39
import java.lang.System.Logger.Level;
40
41
import javax.management.Attribute;
42
import javax.management.AttributeList;
43
import javax.management.AttributeNotFoundException;
44
import javax.management.InstanceAlreadyExistsException;
45
import javax.management.InstanceNotFoundException;
46
import javax.management.IntrospectionException;
47
import javax.management.InvalidAttributeValueException;
48
import javax.management.ListenerNotFoundException;
49
import javax.management.MBeanException;
50
import javax.management.MBeanInfo;
51
import javax.management.MBeanPermission;
52
import javax.management.MBeanRegistrationException;
53
import javax.management.MBeanServer;
54
import javax.management.MBeanServerDelegate;
55
import javax.management.MBeanServerPermission;
56
import javax.management.NotCompliantMBeanException;
57
import javax.management.NotificationFilter;
58
import javax.management.NotificationListener;
59
import javax.management.ObjectInstance;
60
import javax.management.ObjectName;
61
import javax.management.OperationsException;
62
import javax.management.QueryExp;
63
import javax.management.ReflectionException;
64
import javax.management.RuntimeOperationsException;
65
import javax.management.loading.ClassLoaderRepository;
66
67
/**
68
* This is the base class for MBean manipulation on the agent side. It
69
* contains the methods necessary for the creation, registration, and
70
* deletion of MBeans as well as the access methods for registered MBeans.
71
* This is the core component of the JMX infrastructure.
72
* <P>
73
* Every MBean which is added to the MBean server becomes manageable:
74
* its attributes and operations become remotely accessible through
75
* the connectors/adaptors connected to that MBean server.
76
* A Java object cannot be registered in the MBean server unless it is a
77
* JMX compliant MBean.
78
* <P>
79
* When an MBean is registered or unregistered in the MBean server an
80
* {@link javax.management.MBeanServerNotification MBeanServerNotification}
81
* Notification is emitted. To register an object as listener to
82
* MBeanServerNotifications you should call the MBean server method
83
* {@link #addNotificationListener addNotificationListener} with
84
* the <CODE>ObjectName</CODE> of the
85
* {@link javax.management.MBeanServerDelegate MBeanServerDelegate}.
86
* This <CODE>ObjectName</CODE> is:
87
* <BR>
88
* <CODE>JMImplementation:type=MBeanServerDelegate</CODE>.
89
*
90
* @since 1.5
91
*/
92
public final class JmxMBeanServer
93
implements SunJmxMBeanServer {
94
95
/** Control the default locking policy of the repository.
96
* By default, we will be using a fair locking policy.
97
**/
98
public static final boolean DEFAULT_FAIR_LOCK_POLICY = true;
99
100
private final MBeanInstantiator instantiator;
101
private final SecureClassLoaderRepository secureClr;
102
103
/** true if interceptors are enabled **/
104
private final boolean interceptorsEnabled;
105
106
private final MBeanServer outerShell;
107
108
private volatile MBeanServer mbsInterceptor = null;
109
110
/** The MBeanServerDelegate object representing the MBean Server */
111
private final MBeanServerDelegate mBeanServerDelegateObject;
112
113
/**
114
* <b>Package:</b> Creates an MBeanServer with the
115
* specified default domain name, outer interface, and delegate.
116
* <p>The default domain name is used as the domain part in the ObjectName
117
* of MBeans if no domain is specified by the user.
118
* <ul><b>Note:</b>Using this constructor directly is strongly
119
* discouraged. You should use
120
* {@link javax.management.MBeanServerFactory#createMBeanServer(java.lang.String)}
121
* or
122
* {@link javax.management.MBeanServerFactory#newMBeanServer(java.lang.String)}
123
* instead.
124
* <p>
125
* By default, interceptors are disabled. Use
126
* {@link #JmxMBeanServer(java.lang.String,javax.management.MBeanServer,javax.management.MBeanServerDelegate,boolean)} to enable them.
127
* </ul>
128
* @param domain The default domain name used by this MBeanServer.
129
* @param outer A pointer to the MBeanServer object that must be
130
* passed to the MBeans when invoking their
131
* {@link javax.management.MBeanRegistration} interface.
132
* @param delegate A pointer to the MBeanServerDelegate associated
133
* with the new MBeanServer. The new MBeanServer must register
134
* this MBean in its MBean repository.
135
* @exception IllegalArgumentException if the instantiator is null.
136
*/
137
JmxMBeanServer(String domain, MBeanServer outer,
138
MBeanServerDelegate delegate) {
139
this(domain,outer,delegate,null,false);
140
}
141
142
/**
143
* <b>Package:</b> Creates an MBeanServer with the
144
* specified default domain name, outer interface, and delegate.
145
* <p>The default domain name is used as the domain part in the ObjectName
146
* of MBeans if no domain is specified by the user.
147
* <ul><b>Note:</b>Using this constructor directly is strongly
148
* discouraged. You should use
149
* {@link javax.management.MBeanServerFactory#createMBeanServer(java.lang.String)}
150
* or
151
* {@link javax.management.MBeanServerFactory#newMBeanServer(java.lang.String)}
152
* instead.
153
* </ul>
154
* @param domain The default domain name used by this MBeanServer.
155
* @param outer A pointer to the MBeanServer object that must be
156
* passed to the MBeans when invoking their
157
* {@link javax.management.MBeanRegistration} interface.
158
* @param delegate A pointer to the MBeanServerDelegate associated
159
* with the new MBeanServer. The new MBeanServer must register
160
* this MBean in its MBean repository.
161
* @param interceptors If <code>true</code>,
162
* {@link MBeanServerInterceptor} will be enabled (default is
163
* <code>false</code>)
164
* Note: this parameter is not taken into account by this
165
* implementation - the default value <code>false</code> is
166
* always used.
167
* @exception IllegalArgumentException if the instantiator is null.
168
*/
169
JmxMBeanServer(String domain, MBeanServer outer,
170
MBeanServerDelegate delegate, boolean interceptors) {
171
this(domain,outer,delegate,null,false);
172
}
173
174
/**
175
* <b>Package:</b> Creates an MBeanServer.
176
* @param domain The default domain name used by this MBeanServer.
177
* @param outer A pointer to the MBeanServer object that must be
178
* passed to the MBeans when invoking their
179
* {@link javax.management.MBeanRegistration} interface.
180
* @param delegate A pointer to the MBeanServerDelegate associated
181
* with the new MBeanServer. The new MBeanServer must register
182
* this MBean in its MBean repository.
183
* @param instantiator The MBeanInstantiator that will be used to
184
* instantiate MBeans and take care of class loading issues.
185
* @param metadata The MetaData object that will be used by the
186
* MBean server in order to invoke the MBean interface of
187
* the registered MBeans.
188
* @param interceptors If <code>true</code>,
189
* {@link MBeanServerInterceptor} will be enabled (default is
190
* <code>false</code>).
191
*/
192
JmxMBeanServer(String domain, MBeanServer outer,
193
MBeanServerDelegate delegate,
194
MBeanInstantiator instantiator,
195
boolean interceptors) {
196
this(domain,outer,delegate,instantiator,interceptors,true);
197
}
198
199
/**
200
* <b>Package:</b> Creates an MBeanServer.
201
* @param domain The default domain name used by this MBeanServer.
202
* @param outer A pointer to the MBeanServer object that must be
203
* passed to the MBeans when invoking their
204
* {@link javax.management.MBeanRegistration} interface.
205
* @param delegate A pointer to the MBeanServerDelegate associated
206
* with the new MBeanServer. The new MBeanServer must register
207
* this MBean in its MBean repository.
208
* @param instantiator The MBeanInstantiator that will be used to
209
* instantiate MBeans and take care of class loading issues.
210
* @param metadata The MetaData object that will be used by the
211
* MBean server in order to invoke the MBean interface of
212
* the registered MBeans.
213
* @param interceptors If <code>true</code>,
214
* {@link MBeanServerInterceptor} will be enabled (default is
215
* <code>false</code>).
216
* @param fairLock If {@code true}, the MBean repository will use a {@link
217
* java.util.concurrent.locks.ReentrantReadWriteLock#ReentrantReadWriteLock(boolean)
218
* fair locking} policy.
219
*/
220
@SuppressWarnings("removal")
221
JmxMBeanServer(String domain, MBeanServer outer,
222
MBeanServerDelegate delegate,
223
MBeanInstantiator instantiator,
224
boolean interceptors,
225
boolean fairLock) {
226
227
if (instantiator == null) {
228
final ModifiableClassLoaderRepository
229
clr = new ClassLoaderRepositorySupport();
230
instantiator = new MBeanInstantiator(clr);
231
}
232
233
final MBeanInstantiator fInstantiator = instantiator;
234
this.secureClr = new
235
SecureClassLoaderRepository(AccessController.doPrivileged(new PrivilegedAction<ClassLoaderRepository>() {
236
@Override
237
public ClassLoaderRepository run() {
238
return fInstantiator.getClassLoaderRepository();
239
}
240
})
241
);
242
if (delegate == null)
243
delegate = new MBeanServerDelegateImpl();
244
if (outer == null)
245
outer = this;
246
247
this.instantiator = instantiator;
248
this.mBeanServerDelegateObject = delegate;
249
this.outerShell = outer;
250
251
final Repository repository = new Repository(domain);
252
this.mbsInterceptor =
253
new DefaultMBeanServerInterceptor(outer, delegate, instantiator,
254
repository);
255
this.interceptorsEnabled = interceptors;
256
initialize();
257
}
258
259
/**
260
* Tell whether {@link MBeanServerInterceptor}s are enabled on this
261
* object.
262
* @return <code>true</code> if {@link MBeanServerInterceptor}s are
263
* enabled.
264
* @see #newMBeanServer(java.lang.String,javax.management.MBeanServer,javax.management.MBeanServerDelegate,boolean)
265
**/
266
public boolean interceptorsEnabled() {
267
return interceptorsEnabled;
268
}
269
270
/**
271
* Return the MBeanInstantiator associated to this MBeanServer.
272
* @exception UnsupportedOperationException if
273
* {@link MBeanServerInterceptor}s
274
* are not enabled on this object.
275
* @see #interceptorsEnabled
276
**/
277
public MBeanInstantiator getMBeanInstantiator() {
278
if (interceptorsEnabled) return instantiator;
279
else throw new UnsupportedOperationException(
280
"MBeanServerInterceptors are disabled.");
281
}
282
283
/**
284
* Instantiates and registers an MBean in the MBean server.
285
* The MBean server will use its
286
* {@link javax.management.loading.ClassLoaderRepository Default Loader Repository}
287
* to load the class of the MBean.
288
* An object name is associated to the MBean.
289
* If the object name given is null, the MBean can automatically
290
* provide its own name by implementing the
291
* {@link javax.management.MBeanRegistration MBeanRegistration} interface.
292
* The call returns an <CODE>ObjectInstance</CODE> object representing
293
* the newly created MBean.
294
*
295
* @param className The class name of the MBean to be instantiated.
296
* @param name The object name of the MBean. May be null.
297
*
298
* @return An <CODE>ObjectInstance</CODE>, containing the
299
* <CODE>ObjectName</CODE> and the Java class name of the newly
300
* instantiated MBean.
301
*
302
* @exception ReflectionException Wraps an
303
* <CODE>{@link java.lang.ClassNotFoundException}</CODE> or an
304
* <CODE>{@link java.lang.Exception}</CODE> that occurred
305
* when trying to invoke the MBean's constructor.
306
* @exception InstanceAlreadyExistsException The MBean is already
307
* under the control of the MBean server.
308
* @exception MBeanRegistrationException The <CODE>preRegister()</CODE>
309
* (<CODE>MBeanRegistration</CODE> interface) method of the MBean
310
* has thrown an exception. The MBean will not be registered.
311
* @exception MBeanException The constructor of the MBean has thrown
312
* an exception.
313
* @exception NotCompliantMBeanException This class is not a JMX
314
* compliant MBean.
315
* @exception RuntimeOperationsException Wraps an
316
* <CODE>{@link java.lang.IllegalArgumentException}</CODE>:
317
* The className passed in parameter is null, the
318
* <CODE>ObjectName</CODE> passed in parameter contains a pattern
319
* or no <CODE>ObjectName</CODE> is specified for the MBean.
320
*
321
*/
322
public ObjectInstance createMBean(String className, ObjectName name)
323
throws ReflectionException, InstanceAlreadyExistsException,
324
MBeanRegistrationException, MBeanException,
325
NotCompliantMBeanException {
326
327
return mbsInterceptor.createMBean(className,
328
cloneObjectName(name),
329
(Object[]) null,
330
(String[]) null);
331
}
332
333
/**
334
* Instantiates and registers an MBean in the MBean server.
335
* The class loader to be used is identified by its object name.
336
* An object name is associated to the MBean.
337
* If the object name of the loader is null, the ClassLoader that
338
* loaded the MBean server will be used.
339
* If the MBean's object name given is null, the MBean can
340
* automatically provide its own name by implementing the
341
* {@link javax.management.MBeanRegistration MBeanRegistration} interface.
342
* The call returns an <CODE>ObjectInstance</CODE> object representing
343
* the newly created MBean.
344
*
345
* @param className The class name of the MBean to be instantiated.
346
* @param name The object name of the MBean. May be null.
347
* @param loaderName The object name of the class loader to be used.
348
*
349
* @return An <CODE>ObjectInstance</CODE>, containing the
350
* <CODE>ObjectName</CODE> and the Java class name
351
* of the newly instantiated MBean.
352
*
353
* @exception ReflectionException Wraps an
354
* <CODE>{@link java.lang.ClassNotFoundException}</CODE> or an
355
* <CODE>{@link java.lang.Exception}</CODE> that occurred when trying
356
* to invoke the MBean's constructor.
357
* @exception InstanceAlreadyExistsException The MBean is already
358
* under the control of the MBean server.
359
* @exception MBeanRegistrationException The <CODE>preRegister()</CODE>
360
* (<CODE>MBeanRegistration</CODE> interface) method of the MBean
361
* has thrown an exception. The MBean will not be registered.
362
* @exception MBeanException The constructor of the MBean has thrown
363
* an exception
364
* @exception NotCompliantMBeanException This class is not a JMX
365
* compliant MBean.
366
* @exception InstanceNotFoundException The specified class loader
367
* is not registered in the MBean server.
368
* @exception RuntimeOperationsException Wraps an
369
* <CODE>{@link java.lang.IllegalArgumentException}</CODE>: The
370
* className passed in parameter is null, the <CODE>ObjectName</CODE>
371
* passed in parameter contains a pattern or no
372
* <CODE>ObjectName</CODE> is specified for the MBean.
373
*/
374
public ObjectInstance createMBean(String className, ObjectName name,
375
ObjectName loaderName)
376
throws ReflectionException, InstanceAlreadyExistsException,
377
MBeanRegistrationException, MBeanException,
378
NotCompliantMBeanException, InstanceNotFoundException {
379
380
return mbsInterceptor.createMBean(className,
381
cloneObjectName(name),
382
loaderName,
383
(Object[]) null,
384
(String[]) null);
385
}
386
387
/**
388
* Instantiates and registers an MBean in the MBean server.
389
* The MBean server will use its
390
* {@link javax.management.loading.ClassLoaderRepository Default Loader Repository}
391
* to load the class of the MBean.
392
* An object name is associated to the MBean.
393
* If the object name given is null, the MBean can automatically
394
* provide its own name by implementing the
395
* {@link javax.management.MBeanRegistration MBeanRegistration} interface.
396
* The call returns an <CODE>ObjectInstance</CODE> object representing
397
* the newly created MBean.
398
*
399
* @param className The class name of the MBean to be instantiated.
400
* @param name The object name of the MBean. May be null.
401
* @param params An array containing the parameters of the constructor
402
* to be invoked.
403
* @param signature An array containing the signature of the
404
* constructor to be invoked.
405
*
406
* @return An <CODE>ObjectInstance</CODE>, containing the
407
* <CODE>ObjectName</CODE> and the Java class name
408
* of the newly instantiated MBean.
409
*
410
* @exception ReflectionException Wraps a
411
* <CODE>{@link java.lang.ClassNotFoundException}</CODE> or an
412
* <CODE>{@link java.lang.Exception}</CODE> that occurred
413
* when trying to invoke the MBean's constructor.
414
* @exception InstanceAlreadyExistsException The MBean is already
415
* under the control of the MBean server.
416
* @exception MBeanRegistrationException The <CODE>preRegister()</CODE>
417
* (<CODE>MBeanRegistration</CODE> interface) method of the MBean
418
* has thrown an exception. The MBean will not be registered.
419
* @exception MBeanException The constructor of the MBean has
420
* thrown an exception.
421
* @exception RuntimeOperationsException Wraps an
422
* <CODE>{@link java.lang.IllegalArgumentException}</CODE>: The
423
* className passed in parameter is null, the <CODE>ObjectName</CODE>
424
* passed in parameter contains a pattern or no
425
* <CODE>ObjectName</CODE> is specified for the MBean.
426
*
427
*/
428
public ObjectInstance createMBean(String className, ObjectName name,
429
Object params[], String signature[])
430
throws ReflectionException, InstanceAlreadyExistsException,
431
MBeanRegistrationException, MBeanException,
432
NotCompliantMBeanException {
433
434
return mbsInterceptor.createMBean(className, cloneObjectName(name),
435
params, signature);
436
}
437
438
/**
439
* Instantiates and registers an MBean in the MBean server.
440
* The class loader to be used is identified by its object name.
441
* An object name is associated to the MBean. If the object name
442
* of the loader is not specified, the ClassLoader that loaded the
443
* MBean server will be used.
444
* If the MBean object name given is null, the MBean can automatically
445
* provide its own name by implementing the
446
* {@link javax.management.MBeanRegistration MBeanRegistration} interface.
447
* The call returns an <CODE>ObjectInstance</CODE> object representing
448
* the newly created MBean.
449
*
450
* @param className The class name of the MBean to be instantiated.
451
* @param name The object name of the MBean. May be null.
452
* @param params An array containing the parameters of the constructor
453
* to be invoked.
454
* @param signature An array containing the signature of the
455
* constructor to be invoked.
456
* @param loaderName The object name of the class loader to be used.
457
*
458
* @return An <CODE>ObjectInstance</CODE>, containing the
459
* <CODE>ObjectName</CODE> and the Java class name of the newly
460
* instantiated MBean.
461
*
462
* @exception ReflectionException Wraps a
463
* <CODE>{@link java.lang.ClassNotFoundException}</CODE> or an
464
* <CODE>{@link java.lang.Exception}</CODE>
465
* that occurred when trying to invoke the MBean's constructor.
466
* @exception InstanceAlreadyExistsException The MBean is already
467
* under the control of the MBean server.
468
* @exception MBeanRegistrationException The <CODE>preRegister()</CODE>
469
* (<CODE>MBeanRegistration</CODE> interface) method of the MBean
470
* has thrown an exception. The MBean will not be registered.
471
* @exception MBeanException The constructor of the MBean has
472
* thrown an exception
473
* @exception InstanceNotFoundException The specified class loader is
474
* not registered in the MBean server.
475
* @exception RuntimeOperationsException Wraps an
476
* <CODE>{@link java.lang.IllegalArgumentException}</CODE>: The
477
* className passed in parameter is null, the <CODE>ObjectName</CODE>
478
* passed in parameter contains a pattern or no
479
* <CODE>ObjectName</CODE> is specified for the MBean.
480
*
481
*/
482
public ObjectInstance createMBean(String className, ObjectName name,
483
ObjectName loaderName, Object params[],
484
String signature[])
485
throws ReflectionException, InstanceAlreadyExistsException,
486
MBeanRegistrationException, MBeanException,
487
NotCompliantMBeanException, InstanceNotFoundException {
488
489
return mbsInterceptor.createMBean(className, cloneObjectName(name),
490
loaderName, params, signature);
491
}
492
493
/**
494
* Registers a pre-existing object as an MBean with the MBean server.
495
* If the object name given is null, the MBean may automatically
496
* provide its own name by implementing the
497
* {@link javax.management.MBeanRegistration MBeanRegistration} interface.
498
* The call returns an <CODE>ObjectInstance</CODE> object representing
499
* the registered MBean.
500
*
501
* @param object The MBean to be registered as an MBean.
502
* @param name The object name of the MBean. May be null.
503
*
504
* @return The <CODE>ObjectInstance</CODE> for the MBean that has been
505
* registered.
506
*
507
* @exception InstanceAlreadyExistsException The MBean is already
508
* under the control of the MBean server.
509
* @exception MBeanRegistrationException The <CODE>preRegister()</CODE>
510
* (<CODE>MBeanRegistration</CODE> interface) method of the MBean
511
* has thrown an exception. The MBean will not be registered.
512
* @exception NotCompliantMBeanException This object is not a JMX
513
* compliant MBean
514
* @exception RuntimeOperationsException Wraps an
515
* <CODE>{@link java.lang.IllegalArgumentException}</CODE>: The
516
* object passed in parameter is null or no object name is specified.
517
*
518
*/
519
public ObjectInstance registerMBean(Object object, ObjectName name)
520
throws InstanceAlreadyExistsException, MBeanRegistrationException,
521
NotCompliantMBeanException {
522
523
return mbsInterceptor.registerMBean(object, cloneObjectName(name));
524
}
525
526
/**
527
* De-registers an MBean from the MBean server. The MBean is identified by
528
* its object name. Once the method has been invoked, the MBean may
529
* no longer be accessed by its object name.
530
*
531
* @param name The object name of the MBean to be de-registered.
532
*
533
* @exception InstanceNotFoundException The MBean specified is not
534
* registered in the MBean server.
535
* @exception MBeanRegistrationException The <code>preDeregister()</code>
536
* (<CODE>MBeanRegistration</CODE> interface) method of the MBean
537
* has thrown an exception.
538
* @exception RuntimeOperationsException Wraps an
539
* <CODE>{@link java.lang.IllegalArgumentException}</CODE>: The
540
* object name in parameter is null or the MBean you are when
541
* trying to de-register is the
542
* {@link javax.management.MBeanServerDelegate MBeanServerDelegate}
543
* MBean.
544
**/
545
public void unregisterMBean(ObjectName name)
546
throws InstanceNotFoundException, MBeanRegistrationException {
547
mbsInterceptor.unregisterMBean(cloneObjectName(name));
548
}
549
550
/**
551
* Gets the <CODE>ObjectInstance</CODE> for a given MBean registered
552
* with the MBean server.
553
*
554
* @param name The object name of the MBean.
555
*
556
* @return The <CODE>ObjectInstance</CODE> associated to the MBean
557
* specified by <VAR>name</VAR>.
558
*
559
* @exception InstanceNotFoundException The MBean specified is not
560
* registered in the MBean server.
561
*/
562
public ObjectInstance getObjectInstance(ObjectName name)
563
throws InstanceNotFoundException {
564
565
return mbsInterceptor.getObjectInstance(cloneObjectName(name));
566
}
567
568
/**
569
* Gets MBeans controlled by the MBean server. This method allows any
570
* of the following to be obtained: All MBeans, a set of MBeans specified
571
* by pattern matching on the <CODE>ObjectName</CODE> and/or a Query
572
* expression, a specific MBean. When the object name is null or no
573
* domain and key properties are specified, all objects are to be
574
* selected (and filtered if a query is specified). It returns the
575
* set of <CODE>ObjectInstance</CODE> objects (containing the
576
* <CODE>ObjectName</CODE> and the Java Class name) for
577
* the selected MBeans.
578
*
579
* @param name The object name pattern identifying the MBeans to
580
* be retrieved. If null or no domain and key properties
581
* are specified, all the MBeans registered will be retrieved.
582
* @param query The query expression to be applied for selecting
583
* MBeans. If null no query expression will be applied for
584
* selecting MBeans.
585
*
586
* @return A set containing the <CODE>ObjectInstance</CODE> objects
587
* for the selected MBeans.
588
* If no MBean satisfies the query an empty list is returned.
589
*
590
*/
591
public Set<ObjectInstance> queryMBeans(ObjectName name, QueryExp query) {
592
593
return mbsInterceptor.queryMBeans(cloneObjectName(name), query);
594
}
595
596
/**
597
* Gets the names of MBeans controlled by the MBean server. This method
598
* enables any of the following to be obtained: The names of all MBeans,
599
* the names of a set of MBeans specified by pattern matching on the
600
* <CODE>ObjectName</CODE> and/or a Query expression, a specific
601
* MBean name (equivalent to testing whether an MBean is registered).
602
* When the object name is null or no domain and key properties are
603
* specified, all objects are selected (and filtered if a query is
604
* specified). It returns the set of ObjectNames for the MBeans
605
* selected.
606
*
607
* @param name The object name pattern identifying the MBeans to be
608
* retrieved. If null or no domain and key properties are
609
* specified, all the MBeans registered will be retrieved.
610
* @param query The query expression to be applied for selecting
611
* MBeans. If null no query expression will be applied for
612
* selecting MBeans.
613
*
614
* @return A set containing the ObjectNames for the MBeans selected.
615
* If no MBean satisfies the query, an empty list is returned.
616
*
617
*/
618
public Set<ObjectName> queryNames(ObjectName name, QueryExp query) {
619
620
return mbsInterceptor.queryNames(cloneObjectName(name), query);
621
}
622
623
/**
624
* Checks whether an MBean, identified by its object name, is already
625
* registered with the MBean server.
626
*
627
* @param name The object name of the MBean to be checked.
628
*
629
* @return True if the MBean is already registered in the MBean server,
630
* false otherwise.
631
*
632
* @exception RuntimeOperationsException Wraps an
633
* <CODE>{@link java.lang.IllegalArgumentException}</CODE>: The object
634
* name in parameter is null.
635
*
636
*/
637
public boolean isRegistered(ObjectName name) {
638
639
return mbsInterceptor.isRegistered(name);
640
}
641
642
/**
643
* Returns the number of MBeans registered in the MBean server.
644
*/
645
public Integer getMBeanCount() {
646
647
return mbsInterceptor.getMBeanCount();
648
}
649
650
/**
651
* Gets the value of a specific attribute of a named MBean. The MBean
652
* is identified by its object name.
653
*
654
* @param name The object name of the MBean from which the attribute
655
* is to be retrieved.
656
* @param attribute A String specifying the name of the attribute to be
657
* retrieved.
658
*
659
* @return The value of the retrieved attribute.
660
*
661
* @exception AttributeNotFoundException The attribute specified
662
* is not accessible in the MBean.
663
* @exception MBeanException Wraps an exception thrown by the
664
* MBean's getter.
665
* @exception InstanceNotFoundException The MBean specified is not
666
* registered in the MBean server.
667
* @exception ReflectionException Wraps an
668
* <CODE>{@link java.lang.Exception}</CODE> thrown when trying to
669
* invoke the setter.
670
* @exception RuntimeOperationsException Wraps an
671
* <CODE>{@link java.lang.IllegalArgumentException}</CODE>:
672
* The object name in parameter is null or the attribute in
673
* parameter is null.
674
*/
675
public Object getAttribute(ObjectName name, String attribute)
676
throws MBeanException, AttributeNotFoundException,
677
InstanceNotFoundException, ReflectionException {
678
679
return mbsInterceptor.getAttribute(cloneObjectName(name), attribute);
680
}
681
682
683
/**
684
* Enables the values of several attributes of a named MBean. The MBean
685
* is identified by its object name.
686
*
687
* @param name The object name of the MBean from which the attributes are
688
* retrieved.
689
* @param attributes A list of the attributes to be retrieved.
690
*
691
* @return The list of the retrieved attributes.
692
*
693
* @exception InstanceNotFoundException The MBean specified is not
694
* registered in the MBean server.
695
* @exception ReflectionException An exception occurred when trying
696
* to invoke the getAttributes method of a Dynamic MBean.
697
* @exception RuntimeOperationsException Wrap an
698
* <CODE>{@link java.lang.IllegalArgumentException}</CODE>: The
699
* object name in parameter is null or attributes in parameter
700
* is null.
701
*
702
*/
703
public AttributeList getAttributes(ObjectName name, String[] attributes)
704
throws InstanceNotFoundException, ReflectionException {
705
706
return mbsInterceptor.getAttributes(cloneObjectName(name), attributes);
707
708
}
709
710
/**
711
* Sets the value of a specific attribute of a named MBean. The MBean
712
* is identified by its object name.
713
*
714
* @param name The name of the MBean within which the attribute is
715
* to be set.
716
* @param attribute The identification of the attribute to be set
717
* and the value it is to be set to.
718
*
719
* @exception InstanceNotFoundException The MBean specified is
720
* not registered in the MBean server.
721
* @exception AttributeNotFoundException The attribute specified is
722
* not accessible in the MBean.
723
* @exception InvalidAttributeValueException The value specified for
724
* the attribute is not valid.
725
* @exception MBeanException Wraps an exception thrown by the
726
* MBean's setter.
727
* @exception ReflectionException Wraps an
728
* <CODE>{@link java.lang.Exception}</CODE> thrown when trying
729
* to invoke the setter.
730
* @exception RuntimeOperationsException Wraps an
731
* <CODE>{@link java.lang.IllegalArgumentException}</CODE>: The
732
* object name in parameter is null or the attribute in parameter
733
* is null.
734
*/
735
public void setAttribute(ObjectName name, Attribute attribute)
736
throws InstanceNotFoundException, AttributeNotFoundException,
737
InvalidAttributeValueException, MBeanException,
738
ReflectionException {
739
740
mbsInterceptor.setAttribute(cloneObjectName(name),
741
cloneAttribute(attribute));
742
}
743
744
/**
745
* Sets the values of several attributes of a named MBean. The MBean is
746
* identified by its object name.
747
*
748
* @param name The object name of the MBean within which the
749
* attributes are to be set.
750
* @param attributes A list of attributes: The identification of the
751
* attributes to be set and the values they are to be set to.
752
*
753
* @return The list of attributes that were set, with their new values.
754
*
755
* @exception InstanceNotFoundException The MBean specified is not
756
* registered in the MBean server.
757
* @exception ReflectionException An exception occurred when trying
758
* to invoke the getAttributes method of a Dynamic MBean.
759
* @exception RuntimeOperationsException Wraps an
760
* <CODE>{@link java.lang.IllegalArgumentException}</CODE>:
761
* The object name in parameter is null or attributes in
762
* parameter is null.
763
*
764
*/
765
public AttributeList setAttributes(ObjectName name,
766
AttributeList attributes)
767
throws InstanceNotFoundException, ReflectionException {
768
769
return mbsInterceptor.setAttributes(cloneObjectName(name),
770
cloneAttributeList(attributes));
771
}
772
773
/**
774
* Invokes an operation on an MBean.
775
*
776
* @param name The object name of the MBean on which the method is to be
777
* invoked.
778
* @param operationName The name of the operation to be invoked.
779
* @param params An array containing the parameters to be set when
780
* the operation is invoked
781
* @param signature An array containing the signature of the operation.
782
* The class objects will be loaded using the same class loader as
783
* the one used for loading the MBean on which the operation was
784
* invoked.
785
*
786
* @return The object returned by the operation, which represents the
787
* result ofinvoking the operation on the MBean specified.
788
*
789
* @exception InstanceNotFoundException The MBean specified is not
790
* registered in the MBean server.
791
* @exception MBeanException Wraps an exception thrown by the MBean's
792
* invoked method.
793
* @exception ReflectionException Wraps an
794
* <CODE>{@link java.lang.Exception}</CODE> thrown while trying
795
* to invoke the method.
796
*
797
*/
798
public Object invoke(ObjectName name, String operationName,
799
Object params[], String signature[])
800
throws InstanceNotFoundException, MBeanException,
801
ReflectionException {
802
return mbsInterceptor.invoke(cloneObjectName(name), operationName,
803
params, signature);
804
}
805
806
/**
807
* Returns the default domain used for naming the MBean.
808
* The default domain name is used as the domain part in the ObjectName
809
* of MBeans if no domain is specified by the user.
810
*/
811
public String getDefaultDomain() {
812
return mbsInterceptor.getDefaultDomain();
813
}
814
815
// From MBeanServer
816
public String[] getDomains() {
817
return mbsInterceptor.getDomains();
818
}
819
820
/**
821
* Adds a listener to a registered MBean.
822
*
823
* @param name The name of the MBean on which the listener should be added.
824
* @param listener The listener object which will handle the
825
* notifications emitted by the registered MBean.
826
* @param filter The filter object. If filter is null, no filtering
827
* will be performed before handling notifications.
828
* @param handback The context to be sent to the listener when a
829
* notification is emitted.
830
*
831
* @exception InstanceNotFoundException The MBean name provided does
832
* not match any of the registered MBeans.
833
*/
834
public void addNotificationListener(ObjectName name,
835
NotificationListener listener,
836
NotificationFilter filter,
837
Object handback)
838
throws InstanceNotFoundException {
839
840
mbsInterceptor.addNotificationListener(cloneObjectName(name), listener,
841
filter, handback);
842
}
843
844
/**
845
* Adds a listener to a registered MBean.
846
*
847
* @param name The name of the MBean on which the listener should be added.
848
* @param listener The object name of the listener which will handle the
849
* notifications emitted by the registered MBean.
850
* @param filter The filter object. If filter is null, no filtering will
851
* be performed before handling notifications.
852
* @param handback The context to be sent to the listener when a
853
* notification is emitted.
854
*
855
* @exception InstanceNotFoundException The MBean name of the
856
* notification listener or of the notification broadcaster
857
* does not match any of the registered MBeans.
858
*/
859
public void addNotificationListener(ObjectName name, ObjectName listener,
860
NotificationFilter filter, Object handback)
861
throws InstanceNotFoundException {
862
863
mbsInterceptor.addNotificationListener(cloneObjectName(name), listener,
864
filter, handback);
865
}
866
867
public void removeNotificationListener(ObjectName name,
868
NotificationListener listener)
869
throws InstanceNotFoundException, ListenerNotFoundException {
870
871
mbsInterceptor.removeNotificationListener(cloneObjectName(name),
872
listener);
873
}
874
875
public void removeNotificationListener(ObjectName name,
876
NotificationListener listener,
877
NotificationFilter filter,
878
Object handback)
879
throws InstanceNotFoundException, ListenerNotFoundException {
880
881
mbsInterceptor.removeNotificationListener(cloneObjectName(name),
882
listener, filter, handback);
883
}
884
885
public void removeNotificationListener(ObjectName name,
886
ObjectName listener)
887
throws InstanceNotFoundException, ListenerNotFoundException {
888
889
mbsInterceptor.removeNotificationListener(cloneObjectName(name),
890
listener);
891
}
892
893
public void removeNotificationListener(ObjectName name,
894
ObjectName listener,
895
NotificationFilter filter,
896
Object handback)
897
throws InstanceNotFoundException, ListenerNotFoundException {
898
899
mbsInterceptor.removeNotificationListener(cloneObjectName(name),
900
listener, filter, handback);
901
}
902
903
/**
904
* This method discovers the attributes and operations that an MBean exposes
905
* for management.
906
*
907
* @param name The name of the MBean to analyze
908
*
909
* @return An instance of <CODE>MBeanInfo</CODE> allowing the retrieval of
910
* all attributes and operations of this MBean.
911
*
912
* @exception IntrospectionException An exception occurs during
913
* introspection.
914
* @exception InstanceNotFoundException The MBean specified is not found.
915
* @exception ReflectionException An exception occurred when trying to
916
* invoke the getMBeanInfo of a Dynamic MBean.
917
*/
918
public MBeanInfo getMBeanInfo(ObjectName name) throws
919
InstanceNotFoundException, IntrospectionException, ReflectionException {
920
921
return mbsInterceptor.getMBeanInfo(cloneObjectName(name));
922
}
923
924
/**
925
* Instantiates an object using the list of all class loaders registered
926
* in the MBean server (using its
927
* {@link javax.management.loading.ClassLoaderRepository Default Loader Repository}).
928
* The object's class should have a public constructor.
929
* It returns a reference to the newly created object.
930
* The newly created object is not registered in the MBean server.
931
*
932
* @param className The class name of the object to be instantiated.
933
*
934
* @return The newly instantiated object.
935
*
936
* @exception ReflectionException Wraps the
937
* <CODE>{@link java.lang.ClassNotFoundException}</CODE> or the
938
* <CODE>{@link java.lang.Exception}</CODE> that
939
* occurred when trying to invoke the object's constructor.
940
* @exception MBeanException The constructor of the object has thrown
941
* an exception.
942
* @exception RuntimeOperationsException Wraps an
943
* <CODE>{@link java.lang.IllegalArgumentException}</CODE>:
944
* The className passed in parameter is null.
945
*
946
*/
947
public Object instantiate(String className)
948
throws ReflectionException, MBeanException {
949
950
/* Permission check */
951
checkMBeanPermission(className, null, null, "instantiate");
952
953
return instantiator.instantiate(className);
954
}
955
956
/**
957
* Instantiates an object using the class Loader specified by its
958
* <CODE>ObjectName</CODE>.
959
* If the loader name is null, the ClassLoader that loaded the
960
* MBean Server will be used.
961
* The object's class should have a public constructor.
962
* It returns a reference to the newly created object.
963
* The newly created object is not registered in the MBean server.
964
*
965
* @param className The class name of the MBean to be instantiated.
966
* @param loaderName The object name of the class loader to be used.
967
*
968
* @return The newly instantiated object.
969
*
970
* @exception ReflectionException Wraps the
971
* <CODE>{@link java.lang.ClassNotFoundException}</CODE> or the
972
* <CODE>{@link java.lang.Exception}</CODE> that
973
* occurred when trying to invoke the object's constructor.
974
* @exception MBeanException The constructor of the object has thrown
975
* an exception.
976
* @exception InstanceNotFoundException The specified class loader
977
* is not registered in the MBaenServer.
978
* @exception RuntimeOperationsException Wraps an
979
* <CODE>{@link java.lang.IllegalArgumentException}</CODE>: The
980
* className passed in parameter is null.
981
*
982
*/
983
public Object instantiate(String className, ObjectName loaderName)
984
throws ReflectionException, MBeanException,
985
InstanceNotFoundException {
986
987
/* Permission check */
988
checkMBeanPermission(className, null, null, "instantiate");
989
990
ClassLoader myLoader = outerShell.getClass().getClassLoader();
991
return instantiator.instantiate(className, loaderName, myLoader);
992
}
993
994
/**
995
* Instantiates an object using the list of all class loaders registered
996
* in the MBean server (using its
997
* {@link javax.management.loading.ClassLoaderRepository Default Loader Repository}).
998
* The object's class should have a public constructor.
999
* The call returns a reference to the newly created object.
1000
* The newly created object is not registered in the MBean server.
1001
*
1002
* @param className The class name of the object to be instantiated.
1003
* @param params An array containing the parameters of the constructor
1004
* to be invoked.
1005
* @param signature An array containing the signature of the
1006
* constructor to be invoked.
1007
*
1008
* @return The newly instantiated object.
1009
*
1010
* @exception ReflectionException Wraps the
1011
* <CODE>{@link java.lang.ClassNotFoundException}</CODE> or the
1012
* <CODE>{@link java.lang.Exception}</CODE> that
1013
* occurred when trying to invoke the object's constructor.
1014
* @exception MBeanException The constructor of the object has thrown
1015
* an exception.
1016
* @exception RuntimeOperationsException Wraps an
1017
* <CODE>{@link java.lang.IllegalArgumentException}</CODE>:
1018
* The className passed in parameter is null.
1019
*
1020
*/
1021
public Object instantiate(String className, Object params[],
1022
String signature[])
1023
throws ReflectionException, MBeanException {
1024
1025
/* Permission check */
1026
checkMBeanPermission(className, null, null, "instantiate");
1027
1028
ClassLoader myLoader = outerShell.getClass().getClassLoader();
1029
return instantiator.instantiate(className, params, signature,
1030
myLoader);
1031
}
1032
1033
/**
1034
* Instantiates an object. The class loader to be used is identified
1035
* by its object name. If the object name of the loader is null,
1036
* the ClassLoader that loaded the MBean server will be used.
1037
* The object's class should have a public constructor.
1038
* The call returns a reference to the newly created object.
1039
* The newly created object is not registered in the MBean server.
1040
*
1041
* @param className The class name of the object to be instantiated.
1042
* @param params An array containing the parameters of the constructor
1043
* to be invoked.
1044
* @param signature An array containing the signature of the constructor
1045
* to be invoked.
1046
* @param loaderName The object name of the class loader to be used.
1047
*
1048
* @return The newly instantiated object.
1049
*
1050
* @exception ReflectionException Wraps the
1051
* <CODE>{@link java.lang.ClassNotFoundException}</CODE> or the
1052
* <CODE>{@link java.lang.Exception}</CODE> that
1053
* occurred when trying to invoke the object's constructor.
1054
* @exception MBeanException The constructor of the object has thrown
1055
* an exception.
1056
* @exception InstanceNotFoundException The specified class loader
1057
* is not registered in the MBean server.
1058
* @exception RuntimeOperationsException Wraps an
1059
* <CODE>{@link java.lang.IllegalArgumentException}</CODE>:
1060
* The className passed in parameter is null.
1061
*
1062
*/
1063
public Object instantiate(String className, ObjectName loaderName,
1064
Object params[], String signature[])
1065
throws ReflectionException, MBeanException,
1066
InstanceNotFoundException {
1067
1068
/* Permission check */
1069
checkMBeanPermission(className, null, null, "instantiate");
1070
1071
ClassLoader myLoader = outerShell.getClass().getClassLoader();
1072
return instantiator.instantiate(className,loaderName,params,signature,
1073
myLoader);
1074
}
1075
1076
/**
1077
* Returns true if the MBean specified is an instance of the specified
1078
* class, false otherwise.
1079
*
1080
* @param name The <CODE>ObjectName</CODE> of the MBean.
1081
* @param className The name of the class.
1082
*
1083
* @return true if the MBean specified is an instance of the specified
1084
* class, false otherwise.
1085
*
1086
* @exception InstanceNotFoundException The MBean specified is not
1087
* registered in the MBean server.
1088
*/
1089
public boolean isInstanceOf(ObjectName name, String className)
1090
throws InstanceNotFoundException {
1091
1092
return mbsInterceptor.isInstanceOf(cloneObjectName(name), className);
1093
}
1094
1095
/**
1096
* De-serializes a byte array in the context of the class loader
1097
* of an MBean.
1098
*
1099
* @param name The name of the MBean whose class loader should
1100
* be used for the de-serialization.
1101
* @param data The byte array to be de-sererialized.
1102
*
1103
* @return The de-serialized object stream.
1104
*
1105
* @exception InstanceNotFoundException The MBean specified is not
1106
* found.
1107
* @exception OperationsException Any of the usual Input/Output
1108
* related exceptions.
1109
*
1110
*/
1111
@Deprecated
1112
public ObjectInputStream deserialize(ObjectName name, byte[] data)
1113
throws InstanceNotFoundException, OperationsException {
1114
1115
/* Permission check */
1116
// This call requires MBeanPermission 'getClassLoaderFor'
1117
final ClassLoader loader = getClassLoaderFor(name);
1118
1119
return instantiator.deserialize(loader, data);
1120
}
1121
1122
/**
1123
* De-serializes a byte array in the context of a given MBean class loader.
1124
* The class loader is the one that loaded the class with name "className".
1125
*
1126
* @param className The name of the class whose class loader should be
1127
* used for the de-serialization.
1128
* @param data The byte array to be de-sererialized.
1129
*
1130
* @return The de-serialized object stream.
1131
*
1132
* @exception OperationsException Any of the usual Input/Output
1133
* related exceptions.
1134
* @exception ReflectionException The specified class could not be
1135
* loaded by the default loader repository
1136
*
1137
*/
1138
@Deprecated
1139
public ObjectInputStream deserialize(String className, byte[] data)
1140
throws OperationsException, ReflectionException {
1141
1142
if (className == null) {
1143
throw new RuntimeOperationsException(
1144
new IllegalArgumentException(),
1145
"Null className passed in parameter");
1146
}
1147
1148
/* Permission check */
1149
// This call requires MBeanPermission 'getClassLoaderRepository'
1150
final ClassLoaderRepository clr = getClassLoaderRepository();
1151
1152
Class<?> theClass;
1153
try {
1154
if (clr == null) throw new ClassNotFoundException(className);
1155
theClass = clr.loadClass(className);
1156
} catch (ClassNotFoundException e) {
1157
throw new ReflectionException(e,
1158
"The given class could not be " +
1159
"loaded by the default loader " +
1160
"repository");
1161
}
1162
1163
return instantiator.deserialize(theClass.getClassLoader(), data);
1164
}
1165
1166
/**
1167
* De-serializes a byte array in the context of a given MBean class loader.
1168
* The class loader is the one that loaded the class with name "className".
1169
* The name of the class loader to be used for loading the specified
1170
* class is specified.
1171
* If null, the MBean Server's class loader will be used.
1172
*
1173
* @param className The name of the class whose class loader should be
1174
* used for the de-serialization.
1175
* @param data The byte array to be de-sererialized.
1176
* @param loaderName The name of the class loader to be used for
1177
* loading the specified class.
1178
* If null, the MBean Server's class loader will be used.
1179
*
1180
* @return The de-serialized object stream.
1181
*
1182
* @exception InstanceNotFoundException The specified class loader
1183
* MBean is not found.
1184
* @exception OperationsException Any of the usual Input/Output
1185
* related exceptions.
1186
* @exception ReflectionException The specified class could not
1187
* be loaded by the specified class loader.
1188
*
1189
*/
1190
@Deprecated
1191
public ObjectInputStream deserialize(String className,
1192
ObjectName loaderName,
1193
byte[] data) throws
1194
InstanceNotFoundException, OperationsException, ReflectionException {
1195
1196
// Clone ObjectName
1197
//
1198
loaderName = cloneObjectName(loaderName);
1199
1200
/* Permission check */
1201
// Make this call just to force the 'getClassLoader'
1202
// permission check
1203
try {
1204
getClassLoader(loaderName);
1205
} catch (SecurityException e) {
1206
throw e;
1207
} catch (Exception e) {
1208
}
1209
1210
ClassLoader myLoader = outerShell.getClass().getClassLoader();
1211
return instantiator.deserialize(className, loaderName, data, myLoader);
1212
}
1213
1214
/**
1215
* Initializes this MBeanServer, registering the MBeanServerDelegate.
1216
* <p>This method must be called once, before using the MBeanServer.
1217
**/
1218
@SuppressWarnings("removal")
1219
private void initialize() {
1220
if (instantiator == null) throw new
1221
IllegalStateException("instantiator must not be null.");
1222
1223
// Registers the MBeanServer identification MBean
1224
try {
1225
AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
1226
public Object run() throws Exception {
1227
mbsInterceptor.registerMBean(
1228
mBeanServerDelegateObject,
1229
MBeanServerDelegate.DELEGATE_NAME);
1230
return null;
1231
}
1232
});
1233
} catch (SecurityException e) {
1234
if (MBEANSERVER_LOGGER.isLoggable(Level.DEBUG)) {
1235
MBEANSERVER_LOGGER.log(Level.DEBUG,
1236
"Unexpected security exception occurred", e);
1237
}
1238
throw e;
1239
} catch (Exception e) {
1240
if (MBEANSERVER_LOGGER.isLoggable(Level.DEBUG)) {
1241
MBEANSERVER_LOGGER.log(Level.DEBUG,
1242
"Unexpected exception occurred", e);
1243
}
1244
throw new
1245
IllegalStateException("Can't register delegate.",e);
1246
}
1247
1248
1249
/* Add my class loader to the repository
1250
This can be null if my class loader is the bootstrap
1251
class loader. The ClassLoaderRepository knows how
1252
to handle that case. */
1253
ClassLoader myLoader = outerShell.getClass().getClassLoader();
1254
final ModifiableClassLoaderRepository loaders = AccessController.doPrivileged(new PrivilegedAction<ModifiableClassLoaderRepository>() {
1255
1256
@Override
1257
public ModifiableClassLoaderRepository run() {
1258
return instantiator.getClassLoaderRepository();
1259
}
1260
});
1261
1262
if (loaders != null) {
1263
loaders.addClassLoader(myLoader);
1264
1265
/* Add the system class loader, so that if the MBean server is
1266
loaded by the bootstrap class loader we can still load
1267
MBeans from the classpath using
1268
createMBean(className, objectName).
1269
1270
If this class (JmxMBeanServer) was not loaded by the
1271
system class loader or a parent of it, then the caller
1272
must have RuntimePermission("getClassLoader") for the
1273
getSystemClassLoader() call to succeed. If the caller
1274
does not have that permission, any call to
1275
Class.getClassLoader() will fail. Since there are lots
1276
of those in JMX, we better throw the exception now.
1277
1278
This permission question is irrelevant when JMX is part
1279
of J2SE (as of 1.5). */
1280
ClassLoader systemLoader = ClassLoader.getSystemClassLoader();
1281
if (systemLoader != myLoader)
1282
loaders.addClassLoader(systemLoader);
1283
}
1284
}
1285
1286
/**
1287
* Return the MBeanServerInterceptor.
1288
* @exception UnsupportedOperationException if
1289
* {@link MBeanServerInterceptor}s
1290
* are not enabled on this object.
1291
* @see #interceptorsEnabled
1292
**/
1293
public synchronized MBeanServer getMBeanServerInterceptor() {
1294
if (interceptorsEnabled) return mbsInterceptor;
1295
else throw new UnsupportedOperationException(
1296
"MBeanServerInterceptors are disabled.");
1297
}
1298
1299
/**
1300
* Set the MBeanServerInterceptor.
1301
* @exception UnsupportedOperationException if
1302
* {@link MBeanServerInterceptor}s
1303
* are not enabled on this object.
1304
* @see #interceptorsEnabled
1305
**/
1306
public synchronized void
1307
setMBeanServerInterceptor(MBeanServer interceptor) {
1308
if (!interceptorsEnabled) throw new UnsupportedOperationException(
1309
"MBeanServerInterceptors are disabled.");
1310
if (interceptor == null) throw new
1311
IllegalArgumentException("MBeanServerInterceptor is null");
1312
mbsInterceptor = interceptor;
1313
}
1314
1315
/**
1316
* <p>Return the {@link java.lang.ClassLoader} that was used for
1317
* loading the class of the named MBean.
1318
* @param mbeanName The ObjectName of the MBean.
1319
* @return The ClassLoader used for that MBean.
1320
* @exception InstanceNotFoundException if the named MBean is not found.
1321
*/
1322
public ClassLoader getClassLoaderFor(ObjectName mbeanName)
1323
throws InstanceNotFoundException {
1324
return mbsInterceptor.getClassLoaderFor(cloneObjectName(mbeanName));
1325
}
1326
1327
/**
1328
* <p>Return the named {@link java.lang.ClassLoader}.
1329
* @param loaderName The ObjectName of the ClassLoader.
1330
* @return The named ClassLoader.
1331
* @exception InstanceNotFoundException if the named ClassLoader
1332
* is not found.
1333
*/
1334
public ClassLoader getClassLoader(ObjectName loaderName)
1335
throws InstanceNotFoundException {
1336
return mbsInterceptor.getClassLoader(cloneObjectName(loaderName));
1337
}
1338
1339
/**
1340
* <p>Return the ClassLoaderRepository for that MBeanServer.
1341
* @return The ClassLoaderRepository for that MBeanServer.
1342
**/
1343
public ClassLoaderRepository getClassLoaderRepository() {
1344
/* Permission check */
1345
checkMBeanPermission(null, null, null, "getClassLoaderRepository");
1346
return secureClr;
1347
}
1348
1349
public MBeanServerDelegate getMBeanServerDelegate() {
1350
if (!interceptorsEnabled) throw new UnsupportedOperationException(
1351
"MBeanServerInterceptors are disabled.");
1352
return mBeanServerDelegateObject;
1353
}
1354
1355
// These methods are called by the JMX MBeanServerBuilder.
1356
1357
/**
1358
* This method creates a new MBeanServerDelegate for a new MBeanServer.
1359
* When creating a new MBeanServer the
1360
* {@link javax.management.MBeanServerBuilder} first calls this method
1361
* in order to create a new MBeanServerDelegate.
1362
* <br>Then it calls
1363
* <code>newMBeanServer(defaultDomain,outer,delegate,interceptors)</code>
1364
* passing the <var>delegate</var> that should be used by the MBeanServer
1365
* implementation.
1366
* <p>Note that the passed <var>delegate</var> might not be directly the
1367
* MBeanServerDelegate that was returned by this method. It could
1368
* be, for instance, a new object wrapping the previously
1369
* returned object.
1370
*
1371
* @return A new {@link javax.management.MBeanServerDelegate}.
1372
**/
1373
public static MBeanServerDelegate newMBeanServerDelegate() {
1374
return new MBeanServerDelegateImpl();
1375
}
1376
1377
/**
1378
* This method creates a new MBeanServer implementation object.
1379
* When creating a new MBeanServer the
1380
* {@link javax.management.MBeanServerBuilder} first calls
1381
* <code>newMBeanServerDelegate()</code> in order to obtain a new
1382
* {@link javax.management.MBeanServerDelegate} for the new
1383
* MBeanServer. Then it calls
1384
* <code>newMBeanServer(defaultDomain,outer,delegate)</code>
1385
* passing the <var>delegate</var> that should be used by the
1386
* MBeanServer implementation.
1387
* <p>Note that the passed <var>delegate</var> might not be directly the
1388
* MBeanServerDelegate that was returned by this implementation. It could
1389
* be, for instance, a new object wrapping the previously
1390
* returned delegate.
1391
* <p>The <var>outer</var> parameter is a pointer to the MBeanServer that
1392
* should be passed to the {@link javax.management.MBeanRegistration}
1393
* interface when registering MBeans inside the MBeanServer.
1394
* If <var>outer</var> is <code>null</code>, then the MBeanServer
1395
* implementation is free to use its own <code>this</code> pointer when
1396
* invoking the {@link javax.management.MBeanRegistration} interface.
1397
* <p>This makes it possible for a MBeanServer implementation to wrap
1398
* another MBeanServer implementation, in order to implement, e.g,
1399
* security checks, or to prevent access to the actual MBeanServer
1400
* implementation by returning a pointer to a wrapping object.
1401
*
1402
* @param defaultDomain Default domain of the new MBeanServer.
1403
* @param outer A pointer to the MBeanServer object that must be
1404
* passed to the MBeans when invoking their
1405
* {@link javax.management.MBeanRegistration} interface.
1406
* @param delegate A pointer to the MBeanServerDelegate associated
1407
* with the new MBeanServer. The new MBeanServer must register
1408
* this MBean in its MBean repository.
1409
* @param interceptors If <code>true</code>,
1410
* {@link MBeanServerInterceptor}s will be enabled (default is
1411
* <code>false</code>).
1412
* Note: this parameter is not taken into account by this
1413
* implementation - the default value <code>false</code> is
1414
* always used.
1415
* @return A new private implementation of an MBeanServer.
1416
* @see #interceptorsEnabled
1417
* @see javax.management.MBeanServerBuilder
1418
* @see com.sun.jmx.mbeanserver.JmxMBeanServerBuilder
1419
**/
1420
public static MBeanServer newMBeanServer(String defaultDomain,
1421
MBeanServer outer,
1422
MBeanServerDelegate delegate,
1423
boolean interceptors) {
1424
// Determine whether to use fair locking for the repository.
1425
// Default is true.
1426
final boolean fairLock = DEFAULT_FAIR_LOCK_POLICY;
1427
1428
checkNewMBeanServerPermission();
1429
1430
// This constructor happens to disregard the value of the interceptors
1431
// flag - that is, it always uses the default value - false.
1432
// This is admitedly a bug, but we chose not to fix it for now
1433
// since we would rather not have anybody depending on the Sun private
1434
// interceptor APIs - which is most probably going to be removed and
1435
// replaced by a public (javax) feature in the future.
1436
//
1437
return new JmxMBeanServer(defaultDomain,outer,delegate,null,
1438
interceptors,fairLock);
1439
}
1440
1441
// JMX OBJECT CLONING
1442
//-------------------
1443
1444
/**
1445
* Clone object name.
1446
*/
1447
private ObjectName cloneObjectName(ObjectName name) {
1448
if (name != null) {
1449
return ObjectName.getInstance(name);
1450
}
1451
return name;
1452
}
1453
1454
/**
1455
* Clone attribute.
1456
*/
1457
private Attribute cloneAttribute(Attribute attribute) {
1458
if (attribute != null) {
1459
if (!attribute.getClass().equals(Attribute.class)) {
1460
return new Attribute(attribute.getName(), attribute.getValue());
1461
}
1462
}
1463
return attribute;
1464
}
1465
1466
/**
1467
* Clone attribute list.
1468
*/
1469
private AttributeList cloneAttributeList(AttributeList list) {
1470
if (list != null) {
1471
List<Attribute> alist = list.asList();
1472
if (!list.getClass().equals(AttributeList.class)) {
1473
// Create new attribute list
1474
//
1475
AttributeList newList = new AttributeList(alist.size());
1476
1477
// Iterate through list and replace non JMX attributes
1478
//
1479
for (Attribute attribute : alist)
1480
newList.add(cloneAttribute(attribute));
1481
return newList;
1482
} else {
1483
// Iterate through list and replace non JMX attributes
1484
//
1485
for (int i = 0; i < alist.size(); i++) {
1486
Attribute attribute = alist.get(i);
1487
if (!attribute.getClass().equals(Attribute.class)) {
1488
list.set(i, cloneAttribute(attribute));
1489
}
1490
}
1491
return list;
1492
}
1493
}
1494
return list;
1495
}
1496
1497
// SECURITY CHECKS
1498
//----------------
1499
1500
private static void checkMBeanPermission(String classname,
1501
String member,
1502
ObjectName objectName,
1503
String actions)
1504
throws SecurityException {
1505
@SuppressWarnings("removal")
1506
SecurityManager sm = System.getSecurityManager();
1507
if (sm != null) {
1508
Permission perm = new MBeanPermission(classname,
1509
member,
1510
objectName,
1511
actions);
1512
sm.checkPermission(perm);
1513
}
1514
}
1515
1516
private static void checkNewMBeanServerPermission() {
1517
@SuppressWarnings("removal")
1518
SecurityManager sm = System.getSecurityManager();
1519
if (sm != null) {
1520
Permission perm = new MBeanServerPermission("newMBeanServer");
1521
sm.checkPermission(perm);
1522
}
1523
}
1524
}
1525
1526