Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/CustomMBeanServer.java
40948 views
1
/*
2
* Copyright (c) 2003, 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.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
package nsk.monitoring.share;
25
26
import java.util.*;
27
import java.io.*;
28
import java.lang.reflect.*;
29
import java.lang.management.*;
30
import javax.management.*;
31
import javax.management.loading.*;
32
import nsk.share.*;
33
34
/**
35
* The <code>CustomMBeanServer</code> implemenets the
36
* {@link javax.management.MBeanServer MBeanServer} interface to provide
37
* minimal funcionality for JSR-174 testing.
38
* <p>Insignificant methods that are not used just throw {@link TestBug TestBug}
39
* with "not implemented" message. If this exception is caught during test
40
* execution, the corresponding method must be implemented.
41
*/
42
43
public class CustomMBeanServer implements MBeanServer {
44
45
// Name of the system property, which specifies class name of MBean server
46
final static String SERVER_BUILDER_PROPERTY
47
= "javax.management.builder.initial";
48
49
// Class name of MBeanServer builder that creates CustomMBeanServer
50
final static String CUSTOM_SERVER_BUILDER
51
= CustomMBeanServerBuilder.class.getCanonicalName();
52
53
// Default MBeanServer builder
54
final static String DEFAULT_SERVER_BUILDER = "";
55
56
// Internal trace level
57
private final static int TRACE_ALL = 10;
58
59
// Prefix to print while logging
60
private final static String LOG_PREFIX = "CustomMBeanServer> ";
61
62
private final static String BROADCASTER_ITNF_NAME =
63
"javax.management.NotificationBroadcaster";
64
65
private final static String DYNAMICMBEAN_ITNF_NAME =
66
"javax.management.DynamicMBean";
67
68
// Private variables
69
private String defaultDomain;
70
private CustomMBeanRegistration register = new CustomMBeanRegistration();
71
private Log.Logger log;
72
private Hashtable<ObjectName, ObjectKeeper> registeredMBeans = new Hashtable<ObjectName, ObjectKeeper>();
73
// StandardMBean view of registered MBeans
74
private Map<ObjectName, DynamicMBean> registeredMBeansStd = new HashMap<ObjectName, DynamicMBean>();
75
76
// Inner class to connect ObjectInstance and Object
77
class ObjectKeeper {
78
ObjectInstance instance;
79
Object object;
80
81
ObjectKeeper(ObjectInstance instance, Object object) {
82
this.instance = instance;
83
this.object = object;
84
}
85
}
86
87
/**
88
* Creates a new <code>CustomMBeanServer</code> object.
89
*
90
* @param defaultDomain default domain of the new MBeanServer
91
*/
92
public CustomMBeanServer(String defaultDomain) {
93
this.defaultDomain = defaultDomain;
94
}
95
96
/**
97
* Instantiates and registers an MBean in the MBean server.
98
*
99
* @see javax.management.MBeanServer#createMBean(String, ObjectName)
100
*/
101
public ObjectInstance createMBean(String className, ObjectName name)
102
throws ReflectionException,
103
InstanceAlreadyExistsException,
104
MBeanRegistrationException,
105
MBeanException,
106
NotCompliantMBeanException {
107
throw new TestBug("not implemented");
108
}
109
110
/**
111
* Instantiates and registers an MBean in the MBean server.
112
*
113
* @see javax.management.MBeanServer#createMBean(String, ObjectName,
114
* Object[], String[])
115
*/
116
public ObjectInstance createMBean(String className, ObjectName name,
117
Object[] params, String[] signature)
118
throws ReflectionException,
119
InstanceAlreadyExistsException,
120
MBeanRegistrationException,
121
MBeanException,
122
NotCompliantMBeanException {
123
throw new TestBug("not implemented");
124
}
125
126
/**
127
* Instantiates and registers an MBean in the MBean server.
128
*
129
* @see javax.management.MBeanServer#createMBean(String, ObjectName,
130
* ObjectName)
131
*/
132
public ObjectInstance createMBean(String className, ObjectName name,
133
ObjectName loaderName)
134
throws ReflectionException,
135
InstanceAlreadyExistsException,
136
MBeanRegistrationException,
137
MBeanException,
138
NotCompliantMBeanException,
139
InstanceNotFoundException {
140
throw new TestBug("not implemented");
141
}
142
143
/**
144
* Instantiates and registers an MBean in the MBean server.
145
*
146
* @see javax.management.MBeanServer#createMBean(String, ObjectName,
147
* ObjectName, Object[], String[])
148
*/
149
public ObjectInstance createMBean(String className, ObjectName name,
150
ObjectName loaderName, Object[] params,
151
String[] signature)
152
throws ReflectionException,
153
InstanceAlreadyExistsException,
154
MBeanRegistrationException,
155
MBeanException,
156
NotCompliantMBeanException,
157
InstanceNotFoundException {
158
throw new TestBug("not implemented");
159
}
160
161
/**
162
* Registers a pre-existing object as an MBean with the MBean server
163
*
164
* @see javax.management.MBeanServer#registerMBean(Object, ObjectName)
165
*/
166
public ObjectInstance registerMBean(Object object, ObjectName name)
167
throws InstanceAlreadyExistsException,
168
MBeanRegistrationException,
169
NotCompliantMBeanException {
170
ObjectName newName = null;
171
172
try {
173
newName = register.preRegister(this, name);
174
} catch (Exception e) {
175
register.postRegister(Boolean.valueOf(false));
176
throw new MBeanRegistrationException(e);
177
}
178
179
// The log object may not be initialized by that time, so try
180
// to check it
181
if (log != null)
182
log.trace(TRACE_ALL, "[registerMBean] " + newName);
183
184
if (isRegistered(newName)) {
185
register.postRegister(Boolean.valueOf(false));
186
throw new InstanceAlreadyExistsException("already registered");
187
}
188
189
ObjectInstance instance = null;
190
try {
191
instance = new ObjectInstance(newName, object.getClass().getName());
192
} catch (IllegalArgumentException e) {
193
throw new RuntimeOperationsException(e);
194
}
195
registeredMBeans.put(newName, new ObjectKeeper(instance, object));
196
register.postRegister(Boolean.valueOf(true));
197
return instance;
198
}
199
200
/**
201
* Unregisters an MBean from the MBean server.
202
*
203
* @see javax.management.MBeanServer#unregisterMBean(ObjectName)
204
*/
205
public void unregisterMBean(ObjectName name)
206
throws InstanceNotFoundException,
207
MBeanRegistrationException {
208
throw new TestBug("not implemented");
209
}
210
211
/**
212
* Gets the <code>ObjectInstance</code> for a given MBean registered with
213
* the MBean server.
214
*
215
* @see javax.management.MBeanServer#getObjectInstance(ObjectName)
216
*/
217
public ObjectInstance getObjectInstance(ObjectName name)
218
throws InstanceNotFoundException {
219
throw new TestBug("not implemented");
220
}
221
222
/**
223
* Gets MBeans controlled by the MBean server.
224
*
225
* @see javax.management.MBeanServer#queryMBeans(ObjectName, QueryExp)
226
*/
227
public Set<ObjectInstance> queryMBeans(ObjectName name, QueryExp query) {
228
if ( (name != null) || (query != null) )
229
throw new TestBug("not implemented");
230
231
HashSet<ObjectInstance> result = new HashSet<ObjectInstance>();
232
Enumeration enumeration = registeredMBeans.elements();
233
while (enumeration.hasMoreElements()) {
234
ObjectKeeper keeper = (ObjectKeeper) enumeration.nextElement();
235
result.add(keeper.instance);
236
}
237
return result;
238
}
239
240
/**
241
* Gets the names of MBeans controlled by the MBean server.
242
*
243
* @see javax.management.MBeanServer#queryNames(ObjectName, QueryExp)
244
*/
245
public Set<ObjectName> queryNames(ObjectName name, QueryExp query) {
246
if (query != null)
247
throw new TestBug("not implemented");
248
249
HashSet<ObjectName> result = new HashSet<ObjectName>();
250
Enumeration enumeration = registeredMBeans.elements();
251
while (enumeration.hasMoreElements()) {
252
ObjectKeeper keeper = (ObjectKeeper) enumeration.nextElement();
253
ObjectName obj = keeper.instance.getObjectName();
254
if ((name == null) || (name.apply(obj))) {
255
result.add(obj);
256
}
257
}
258
return result;
259
}
260
261
/**
262
* Checks whether an MBean, identified by its object name, is
263
* already registered with the MBean server.
264
*
265
* @see javax.management.MBeanServer#isRegistered(ObjectName)
266
*/
267
public boolean isRegistered(ObjectName name) {
268
return registeredMBeans.containsKey(name);
269
}
270
271
/**
272
* Returns the number of MBeans registered in the MBean server.
273
*
274
* @see javax.management.MBeanServer#getMBeanCount()
275
*/
276
public Integer getMBeanCount() {
277
throw new TestBug("not implemented");
278
}
279
280
/**
281
* Gets the value of a specific attribute of a named MBean.
282
*
283
* @see javax.management.MBeanServer#getAttribute(ObjectName, String)
284
*/
285
public Object getAttribute(ObjectName name, String attribute)
286
throws MBeanException,
287
AttributeNotFoundException,
288
InstanceNotFoundException,
289
ReflectionException {
290
291
if (log != null)
292
log.trace(TRACE_ALL, "[getAttribute] " + name + "> " + attribute);
293
294
DynamicMBean mbean = getObject(name);
295
Object result = mbean.getAttribute(attribute);
296
if (result instanceof List) {
297
List list = (List) result;
298
Object[] arr = new Object[list.size()];
299
int i = 0;
300
for (Object o : list)
301
arr[i++] = o;
302
return arr;
303
}
304
return result;
305
}
306
307
/**
308
* Gets the values of several attributes of a named MBean.
309
*
310
* @see javax.management.MBeanServer#getAttributes(ObjectName, String[])
311
*/
312
public AttributeList getAttributes(ObjectName name, String[] attributes)
313
throws InstanceNotFoundException,
314
ReflectionException {
315
throw new TestBug("not implemented");
316
}
317
318
/**
319
* Sets the value of a specific attribute of a named MBean.
320
*
321
* @see javax.management.MBeanServer#setAttribute(ObjectName, Attribute)
322
*/
323
public void setAttribute(ObjectName name, Attribute attribute)
324
throws InstanceNotFoundException,
325
AttributeNotFoundException,
326
InvalidAttributeValueException,
327
MBeanException,
328
ReflectionException {
329
330
if (log != null)
331
log.trace(TRACE_ALL, "[setAttribute] " + name + "> " + attribute);
332
333
DynamicMBean mbean = getObject(name);
334
mbean.setAttribute(attribute);
335
}
336
337
/**
338
* Sets the values of several attributes of a named MBean.
339
*
340
* @see javax.management.MBeanServer#setAttributes(ObjectName,
341
* AttributeList)
342
*/
343
public AttributeList setAttributes(ObjectName name,
344
AttributeList attributes)
345
throws InstanceNotFoundException,
346
ReflectionException {
347
throw new TestBug("not implemented");
348
}
349
350
/**
351
* Invokes an operation on an MBean.
352
*
353
* @see javax.management.MBeanServer#invoke(ObjectName, String,
354
* Object[], String[])
355
*/
356
public Object invoke(ObjectName name, String operationName,
357
Object[] params, String[] signature)
358
throws InstanceNotFoundException,
359
MBeanException,
360
ReflectionException {
361
362
if (log != null)
363
log.trace(TRACE_ALL, "[invoke] " + name + "> "
364
+ operationName);
365
return invokeObjectMethod(name, operationName, params, signature);
366
}
367
368
/**
369
* Returns the default domain used for naming the MBean.
370
*
371
* @see javax.management.MBeanServer#getDefaultDomain()
372
*/
373
public String getDefaultDomain() {
374
throw new TestBug("not implemented");
375
}
376
377
/**
378
* Returns the list of domains in which any MBean is currently
379
* registered.
380
*
381
* @see javax.management.MBeanServer#getDomains()
382
*/
383
public String[] getDomains() {
384
throw new TestBug("not implemented");
385
}
386
387
/**
388
* Adds a listener to a registered MBean.
389
*
390
* @see javax.management.MBeanServer#addNotificationListener(ObjectName,
391
* NotificationListener, NotificationFilter, Object)
392
*/
393
public void addNotificationListener(ObjectName name,
394
NotificationListener listener,
395
NotificationFilter filter,
396
Object handback) throws InstanceNotFoundException {
397
getNotificationBroadcaster(name).addNotificationListener(listener, filter, handback);
398
}
399
400
/**
401
* Adds a listener to a registered MBean.
402
*
403
* @see javax.management.MBeanServer#addNotificationListener(ObjectName,
404
* ObjectName, NotificationFilter, Object)
405
*/
406
public void addNotificationListener(ObjectName name, ObjectName listener,
407
NotificationFilter filter,
408
Object handback)
409
throws InstanceNotFoundException {
410
throw new TestBug("not implemented");
411
}
412
413
/**
414
* Removes a listener from a registered MBean.
415
*
416
* @see javax.management.MBeanServer#removeNotificationListener(ObjectName,
417
* ObjectName)
418
*/
419
public void removeNotificationListener(ObjectName name, ObjectName listener)
420
throws InstanceNotFoundException, ListenerNotFoundException {
421
throw new TestBug("not implemented");
422
}
423
424
/**
425
* Removes a listener from a registered MBean.
426
*
427
* @see javax.management.MBeanServer#removeNotificationListener(ObjectName,
428
* ObjectName, NotificationFilter, Object)
429
*/
430
public void removeNotificationListener(ObjectName name,
431
ObjectName listener,
432
NotificationFilter filter,
433
Object handback)
434
throws InstanceNotFoundException,
435
ListenerNotFoundException {
436
throw new TestBug("not implemented");
437
}
438
439
/**
440
* Removes a listener from a registered MBean.
441
*
442
* @see javax.management.MBeanServer#removeNotificationListener(ObjectName,
443
* NotificationListener)
444
*/
445
public void removeNotificationListener(ObjectName name,
446
NotificationListener listener)
447
throws InstanceNotFoundException,
448
ListenerNotFoundException {
449
throw new TestBug("not implemented");
450
}
451
452
/**
453
* Removes a listener from a registered MBean.
454
*
455
* @see javax.management.MBeanServer#removeNotificationListener(ObjectName,
456
* NotificationListener, NotificationFilter, Object)
457
*/
458
public void removeNotificationListener(ObjectName name,
459
NotificationListener listener,
460
NotificationFilter filter,
461
Object handback)
462
throws InstanceNotFoundException,
463
ListenerNotFoundException {
464
}
465
466
/**
467
* This method discovers the attributes and operations that an
468
* MBean exposes for management.
469
*
470
* @see javax.management.MBeanServer#getMBeanInfo(ObjectName)
471
*/
472
public MBeanInfo getMBeanInfo(ObjectName name)
473
throws InstanceNotFoundException,
474
IntrospectionException,
475
ReflectionException {
476
throw new TestBug("not implemented");
477
}
478
479
/**
480
* Returns true if the MBean specified is an instance of the
481
* specified class, false otherwise.
482
*
483
* @see javax.management.MBeanServer#isInstanceOf(ObjectName, String)
484
*/
485
public boolean isInstanceOf(ObjectName name, String className)
486
throws InstanceNotFoundException {
487
// DynamicMBean mbean = getObject(name);
488
// MBeanInfo info = mbean.getMBeanInfo();
489
// return info.getClassName().compareTo(className) == 0;
490
491
DynamicMBean mbean = getObject(name);
492
MBeanInfo info = mbean.getMBeanInfo();
493
String infoClassName = info.getClassName();
494
495
if (log != null) {
496
log.trace(TRACE_ALL, "[isInstanceOf] name=" + name);
497
log.trace(TRACE_ALL, "[isInstanceOf] className=" + className);
498
}
499
500
if (infoClassName.equals(className)) {
501
if (log != null)
502
log.trace(TRACE_ALL, "[isInstanceOf] infoClassName is equal className. return true");
503
return true;
504
}
505
506
try {
507
ClassLoader cl = mbean.getClass().getClassLoader();
508
Class<?> classNameClass = loadClass(className,cl);
509
if (classNameClass == null) {
510
if (log != null)
511
log.trace(TRACE_ALL, "[isInstanceOf] classNameClass is null. return false");
512
return false;
513
}
514
515
if (classNameClass.isInstance(mbean)) {
516
if (log != null)
517
log.trace(TRACE_ALL, "[isInstanceOf] mbean is instance of classNameClass. return true");
518
return true;
519
}
520
521
Class<?> instanceClass = loadClass(infoClassName,cl);
522
if (instanceClass == null) {
523
if (log != null)
524
log.trace(TRACE_ALL, "[isInstanceOf] instanceClass is null. return false");
525
return false;
526
}
527
528
boolean isAssignable = classNameClass.isAssignableFrom(instanceClass);
529
if (log != null)
530
log.trace(TRACE_ALL, "[isInstanceOf] classNameClass is assignable="+isAssignable);
531
return isAssignable;
532
} catch (ReflectionException e) {
533
if (log != null) {
534
log.trace(TRACE_ALL, "[isInstanceOf] "+e.getMessage());
535
e.printStackTrace(log.getOutStream());
536
}
537
return false;
538
} catch (Exception e) {
539
/* Could be SecurityException or ClassNotFoundException */
540
if (log != null) {
541
log.trace(TRACE_ALL, "[isInstanceOf] "+e.getMessage());
542
e.printStackTrace(log.getOutStream());
543
}
544
return false;
545
}
546
547
}
548
549
/**
550
* Load a class with the specified loader, or with this object
551
* class loader if the specified loader is null.
552
**/
553
static Class loadClass(String className, ClassLoader loader)
554
throws ReflectionException {
555
556
Class theClass = null;
557
if (className == null) {
558
throw new RuntimeOperationsException(new
559
IllegalArgumentException("The class name cannot be null"),
560
"Exception occured during object instantiation");
561
}
562
try {
563
if (loader == null)
564
loader = CustomMBeanServer.class.getClassLoader();
565
if (loader != null) {
566
theClass = Class.forName(className, false, loader);
567
} else {
568
theClass = Class.forName(className);
569
}
570
} catch (ClassNotFoundException e) {
571
throw new ReflectionException(e,
572
"The MBean class could not be loaded by the context classloader");
573
}
574
return theClass;
575
}
576
577
578
/**
579
* Instantiates an object using the list of all class loaders
580
* registered in the MBean server's.
581
*
582
* @see javax.management.MBeanServer#instantiate(String)
583
*/
584
public Object instantiate(String className)
585
throws ReflectionException,
586
MBeanException {
587
throw new TestBug("not implemented");
588
}
589
590
/**
591
* Instantiates an object using the list of all class loaders
592
* registered in the MBean server's.
593
*
594
* @see javax.management.MBeanServer#instantiate(String, ObjectName)
595
*/
596
public Object instantiate(String className, ObjectName loaderName)
597
throws ReflectionException,
598
MBeanException,
599
InstanceNotFoundException {
600
throw new TestBug("not implemented");
601
}
602
603
/**
604
* Instantiates an object using the list of all class loaders
605
* registered in the MBean server's.
606
*
607
* @see javax.management.MBeanServer#instantiate(String, Object[],
608
* String[])
609
*/
610
public Object instantiate(String className, Object[] params,
611
String[] signature)
612
throws ReflectionException,
613
MBeanException {
614
throw new TestBug("not implemented");
615
}
616
617
/**
618
* Instantiates an object using the list of all class loaders
619
* registered in the MBean server's.
620
*
621
* @see javax.management.MBeanServer#instantiate(String, ObjectName,
622
* Object[], String[])
623
*/
624
public Object instantiate(String className, ObjectName loaderName,
625
Object[] params, String[] signature)
626
throws ReflectionException,
627
MBeanException,
628
InstanceNotFoundException {
629
throw new TestBug("not implemented");
630
}
631
632
/**
633
* De-serializes a byte array in the context of the class loader
634
* of an MBean.
635
*
636
* @see javax.management.MBeanServer#deserialize(ObjectName, byte[])
637
*/
638
public ObjectInputStream deserialize(ObjectName name, byte[] data)
639
throws InstanceNotFoundException,
640
OperationsException {
641
throw new TestBug("not implemented");
642
}
643
644
/**
645
* De-serializes a byte array in the context of the class loader
646
* of an MBean.
647
*
648
* @see javax.management.MBeanServer#deserialize(String, byte[])
649
*/
650
public ObjectInputStream deserialize(String className, byte[] data)
651
throws OperationsException,
652
ReflectionException {
653
throw new TestBug("not implemented");
654
}
655
656
/**
657
* De-serializes a byte array in the context of the class loader
658
* of an MBean.
659
*
660
* @see javax.management.MBeanServer#deserialize(String, ObjectName, byte[])
661
*/
662
public ObjectInputStream deserialize(String className,
663
ObjectName loaderName,
664
byte[] data)
665
throws InstanceNotFoundException,
666
OperationsException,
667
ReflectionException {
668
throw new TestBug("not implemented");
669
}
670
671
/**
672
* Return the {@link java.lang.ClassLoader} that was used for
673
* loading the class of the named MBean.
674
*
675
* @see javax.management.MBeanServer#getClassLoaderFor(ObjectName)
676
*/
677
public ClassLoader getClassLoaderFor(ObjectName mbeanName)
678
throws InstanceNotFoundException {
679
throw new TestBug("not implemented");
680
}
681
682
/**
683
* Return the named {@link java.lang.ClassLoader}.
684
*
685
* @see javax.management.MBeanServer#getClassLoader(ObjectName)
686
*/
687
public ClassLoader getClassLoader(ObjectName loaderName)
688
throws InstanceNotFoundException {
689
throw new TestBug("not implemented");
690
}
691
692
/**
693
* Return the named {@link java.lang.ClassLoader}.
694
*
695
* @see javax.management.MBeanServer#getClassLoader(ObjectName)
696
*/
697
public ClassLoaderRepository getClassLoaderRepository() {
698
throw new TestBug("not implemented");
699
}
700
701
/**
702
* Initializes {@link Log <code>Log</code>} object.
703
*
704
* @param log a new <code>Log</code> object.
705
*/
706
public void setLog(Log log) {
707
this.log = new Log.Logger(log, LOG_PREFIX + "> ");
708
}
709
710
// **********************************************************************
711
//
712
// Private methods
713
//
714
// **********************************************************************
715
716
/**
717
* Gets the object reference for a given MBean registered with the MBean
718
* server.
719
*
720
* @param name The object name of the MBean.
721
*
722
* @return The MBean object, specified by <code>name</code>.
723
*
724
* @throws InstanceNotFoundException The MBean specified is not registered
725
* in the MBean server.
726
*/
727
private DynamicMBean getObject(ObjectName name) throws InstanceNotFoundException {
728
DynamicMBean mbean = registeredMBeansStd.get(name);
729
if (mbean == null) {
730
ObjectKeeper objKeeper = registeredMBeans.get(name);
731
if (objKeeper == null)
732
throw new InstanceNotFoundException();
733
Object object = objKeeper.object;
734
if (object instanceof DynamicMBean)
735
mbean = (DynamicMBean) object;
736
else
737
mbean = new StandardMBean(object, getMBeanInterface(object), true);
738
registeredMBeansStd.put(name, mbean);
739
}
740
return mbean;
741
/*
742
ObjectKeeper objKeeper = (ObjectKeeper) registeredMBeans.get(name);
743
744
if (objKeeper == null)
745
throw new InstanceNotFoundException();
746
747
Class superOfMBeans = null;
748
try {
749
superOfMBeans = Class.forName(DYNAMICMBEAN_ITNF_NAME);
750
} catch (ClassNotFoundException e) {
751
throw new InstanceNotFoundException();
752
}
753
754
if (superOfMBeans.isAssignableFrom(objKeeper.object.getClass())) {
755
return (DynamicMBean )objKeeper.object;
756
}
757
758
return null;
759
*/
760
}
761
762
/**
763
* Obtain NotificationBroadcaster for given MBean registered with the MBean
764
* server.
765
*
766
* @param name The object name of the MBean.
767
*
768
* @return The MBean object, specified by <code>name</code>.
769
*
770
* @throws InstanceNotFoundException if MBean specified is not registered
771
* in the MBean server.
772
*/
773
private NotificationBroadcaster getNotificationBroadcaster(ObjectName name) throws InstanceNotFoundException {
774
ObjectKeeper objKeeper = (ObjectKeeper) registeredMBeans.get(name);
775
if (objKeeper == null)
776
throw new InstanceNotFoundException();
777
Object mbean = objKeeper.object;
778
if (mbean instanceof NotificationBroadcaster)
779
return (NotificationBroadcaster) mbean;
780
throw new InstanceNotFoundException();
781
}
782
783
/**
784
* Invoke the method
785
*/
786
private Object invokeObjectMethod(ObjectName name, String methodName,
787
Object[] params, String[] signature) throws InstanceNotFoundException,
788
MBeanException,
789
ReflectionException {
790
791
if (log != null)
792
log.trace(TRACE_ALL, "[invokeObjectMethod] " + name + "> "
793
+ methodName);
794
795
DynamicMBean mbean = getObject(name);
796
return mbean.invoke(methodName, params, signature);
797
}
798
799
private Class getInterface(Class cl, String prefix) {
800
Class[] interfaces = cl.getInterfaces();
801
if (interfaces == null || interfaces.length == 0)
802
return null;
803
for (Class c : interfaces) {
804
if (c.getName().startsWith(prefix))
805
return c;
806
c = getInterface(c, prefix);
807
if (c != null)
808
return c;
809
}
810
return null;
811
}
812
813
/**
814
* Discover MBean interface of the bean.
815
*
816
* Note: this is very specialized for java.lang.management
817
* and java.util.logging tests.
818
* It is generally not correct for any MBean.
819
*
820
* @param object the bean
821
* @return interface class
822
*/
823
private Class getMBeanInterface(Object object) throws InstanceNotFoundException {
824
String className = object.getClass().getName();
825
Class<?> iface = null;
826
if (className.startsWith("java.lang.management"))
827
iface = getInterface(object.getClass(), "java.lang.management");
828
else if (className.startsWith("java.util.logging"))
829
iface = getInterface(object.getClass(), "java.util.logging");
830
else if (className.startsWith("sun.management"))
831
iface = getInterface(object.getClass(), "java.lang.management");
832
if (iface != null)
833
return iface;
834
Class<?>[] interfaces = object.getClass().getInterfaces();
835
System.out.println(object);
836
System.out.println(object.getClass());
837
System.out.println(interfaces.length);
838
for (Class<?> c : interfaces) {
839
System.out.println(c.getName());
840
}
841
throw new TestBug("No suitable implemented interface found for: " + object + " class: " + object.getClass());
842
}
843
}
844
845