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