1 23 package com.sun.enterprise.admin.server.core.jmx; 24 25 import java.lang.reflect.Method ; 27 import java.util.Set ; 28 import java.util.HashSet ; 29 import java.io.ObjectOutputStream ; 30 import java.io.ObjectInputStream ; 31 32 import javax.management.MBeanServer ; 34 import javax.management.QueryExp ; 35 import javax.management.ObjectInstance ; 36 import javax.management.ObjectName ; 37 import javax.management.Attribute ; 38 import javax.management.AttributeList ; 39 import javax.management.InstanceAlreadyExistsException ; 40 import javax.management.InvalidAttributeValueException ; 41 import javax.management.InstanceNotFoundException ; 42 import javax.management.AttributeNotFoundException ; 43 import javax.management.ReflectionException ; 44 import javax.management.MBeanException ; 45 import javax.management.IntrospectionException ; 46 import javax.management.ListenerNotFoundException ; 47 import javax.management.MBeanInfo ; 48 import javax.management.MBeanRegistrationException ; 49 import javax.management.NotificationListener ; 50 import javax.management.NotificationFilter ; 51 import javax.management.NotCompliantMBeanException ; 52 import javax.management.OperationsException ; 53 import javax.management.MBeanRegistrationException ; 54 import javax.management.NotCompliantMBeanException ; 55 56 import com.sun.enterprise.admin.common.ObjectNames; 58 59 import com.sun.enterprise.util.i18n.StringManager; 61 62 public class MBeanServerImpl implements MBeanServer 63 { 64 protected IRepository mMBeanRepository = null; 65 66 private static boolean kDynamicMBeansOnly = true; 67 private static String kGetMBeanInfoMethodName = "getMBeanInfo"; 68 69 private static String kAllMBeansPattern = "*"; 70 71 private static StringManager localStrings = 73 StringManager.getManager( MBeanServerImpl.class ); 74 75 83 84 protected MBeanServerImpl(String defaultDomainName) throws InitException 85 { 86 mMBeanRepository = new DomainRepository(); 87 } 88 89 97 98 protected MBeanServerImpl() throws InitException 99 { 100 this(ServiceName.DOMAIN); 101 } 102 103 public ObjectInstance registerMBean(Object object, ObjectName objectName) 104 throws InstanceAlreadyExistsException , MBeanRegistrationException , 105 NotCompliantMBeanException 106 { 107 if (object == null || objectName == null) 108 { 109 throw new IllegalArgumentException (); 110 } 111 if (mMBeanRepository.contains(objectName)) 112 { 113 throw new InstanceAlreadyExistsException (objectName.toString()); 114 } 115 mMBeanRepository.add(objectName, object); 116 117 return ( new ObjectInstance (objectName, object.getClass().getName()) ); 118 } 119 120 public Object invoke(ObjectName objectName, String operationName, 121 Object [] params, String [] signature) 122 throws ReflectionException , InstanceNotFoundException , MBeanException 123 { 124 Object implObject = mMBeanRepository.find(objectName); 125 if (implObject == null ) 126 { 127 throw new InstanceNotFoundException (objectName.toString()); 128 } 129 Class implClass = implObject.getClass(); 130 Introspector reflector = new Introspector(implClass); 131 Object value = null; 132 try 133 { 134 Method method = reflector.getMethod(operationName, signature); 135 value = reflector.invokeMethodOn(method, implObject, params); 136 } 137 catch (java.lang.ClassNotFoundException cnfe) 138 { 139 throw new javax.management.ReflectionException (cnfe); 140 } 141 catch (java.lang.NoSuchMethodException nsme) 142 { 143 throw new javax.management.ReflectionException (nsme); 144 } 145 catch (java.lang.SecurityException se) 146 { 147 throw new javax.management.ReflectionException (se); 148 } 149 catch (java.lang.reflect.InvocationTargetException ite) 150 { 151 Throwable t = ite.getTargetException(); 152 if (t instanceof MBeanException ) 153 { 154 throw (MBeanException )t; 155 } 156 else 157 if (t instanceof Exception ) 158 { 159 throw new MBeanException ((Exception ) t); 160 } 161 else { 163 String msg = localStrings.getString( "admin.server.core.jmx.error_from_mbean", t.getMessage() ); 164 RuntimeException re = new RuntimeException ( msg ); 165 throw new MBeanException (re); 166 } 168 } 169 catch (java.lang.IllegalAccessException iae) 170 { 171 throw new javax.management.ReflectionException (iae); 172 } 173 catch (Exception e) 174 { 175 throw new MBeanException (e); 176 } 177 return value; 178 } 179 180 public Object getAttribute(ObjectName objectName, String attributeName) 181 throws InstanceNotFoundException , AttributeNotFoundException , 182 MBeanException , ReflectionException 183 { 184 Object implObject = mMBeanRepository.find(objectName); 185 if (implObject == null ) 186 { 187 throw new InstanceNotFoundException (objectName.toString()); 188 } 189 Class implClass = implObject.getClass(); 190 Object value = null; 191 try 192 { 193 MBeanIntrospector introspector = new MBeanIntrospector(implClass); 194 if (introspector.isDynamicMBean()) 195 { 196 Method method = introspector.getMethod("getAttribute", 197 new String [] {"java.lang.String"}); 198 value = introspector.invokeMethodOn(method, implObject, 199 new Object [] {attributeName}); 200 } 201 } 202 catch (javax.management.NotCompliantMBeanException e) 203 { 204 208 value = null; 209 } 210 catch (java.lang.ClassNotFoundException cnfe) 211 { 212 throw new javax.management.ReflectionException (cnfe); 213 } 214 catch (java.lang.NoSuchMethodException nsme) 215 { 216 throw new javax.management.ReflectionException (nsme); 217 } 218 catch (java.lang.SecurityException se) 219 { 220 throw new javax.management.ReflectionException (se); 221 } 222 catch (java.lang.reflect.InvocationTargetException ite) 223 { 224 Throwable t = ite.getTargetException(); 225 if (t instanceof javax.management.AttributeNotFoundException ) 226 { 227 throw (javax.management.AttributeNotFoundException ) t; 228 } 229 else if (t instanceof Exception ) 230 { 231 throw new MBeanException ((Exception ) t); 232 } 233 else { 235 } 237 } 238 catch (java.lang.IllegalAccessException iae) 239 { 240 throw new javax.management.ReflectionException (iae); 241 } 242 catch (Exception e) 243 { 244 throw new MBeanException (e); 245 } 246 return value; 247 } 248 249 public void setAttribute(ObjectName objectName, Attribute attribute) throws 250 InstanceNotFoundException , AttributeNotFoundException , 251 MBeanException , ReflectionException , InvalidAttributeValueException 252 { 253 Object implObject = mMBeanRepository.find(objectName); 254 if (implObject == null ) 255 { 256 throw new InstanceNotFoundException (objectName.toString()); 257 } 258 Class implClass = implObject.getClass(); 259 Object value = null; 260 try 261 { 262 MBeanIntrospector introspector = new MBeanIntrospector(implClass); 263 if (introspector.isDynamicMBean()) 264 { 265 Method method = introspector.getMethod("setAttribute", 266 new String [] {"javax.management.Attribute"}); 267 value = introspector.invokeMethodOn(method, implObject, 268 new Object [] {attribute}); 269 } 270 } 271 catch (NotCompliantMBeanException e) 272 { 273 277 value = null; 278 } 279 catch (java.lang.ClassNotFoundException cnfe) 280 { 281 throw new javax.management.ReflectionException (cnfe); 282 } 283 catch (java.lang.NoSuchMethodException nsme) 284 { 285 throw new javax.management.ReflectionException (nsme); 286 } 287 catch (java.lang.SecurityException se) 288 { 289 throw new javax.management.ReflectionException (se); 290 } 291 catch (java.lang.reflect.InvocationTargetException ite) 292 { 293 Throwable t = ite.getTargetException(); 294 if (t instanceof javax.management.AttributeNotFoundException ) 295 { 296 throw (javax.management.AttributeNotFoundException ) t; 297 } 298 if (t instanceof javax.management.InvalidAttributeValueException ) 299 { 300 throw (javax.management.InvalidAttributeValueException ) t; 301 } 302 else if (t instanceof Exception ) 303 { 304 throw new MBeanException ((Exception ) t); 305 } 306 else { 308 } 310 } 311 catch (IllegalAccessException iae) 312 { 313 throw new ReflectionException (iae); 314 } 315 catch (Exception e) 316 { 317 throw new MBeanException (e); 318 } 319 } 320 321 public void unregisterMBean(ObjectName objectName) 322 throws InstanceNotFoundException , MBeanRegistrationException 323 { 324 if (! mMBeanRepository.contains(objectName)) 325 { 326 throw new InstanceNotFoundException (objectName.toString()); 327 } 328 mMBeanRepository.remove(objectName); 329 } 330 331 public Integer getMBeanCount() 332 { 333 return ( new Integer (mMBeanRepository.getTotalCount()) ); 334 } 335 336 339 public Set queryMBeans(ObjectName name, QueryExp exp) 340 { 341 Set mbeans = new HashSet (); 342 350 mbeans = mMBeanRepository.query(name); 351 return ( mbeans ); 352 } 353 354 public MBeanInfo getMBeanInfo(ObjectName objName) throws 355 InstanceNotFoundException , IntrospectionException , ReflectionException 356 { 357 MBeanInfo info = null; 358 359 if (! kDynamicMBeansOnly) 360 { 361 String msg = localStrings.getString( "admin.server.core.jmx.assert" ); 362 throw new IntrospectionException ( msg ); 363 } 364 try 365 { 366 String operationName = kGetMBeanInfoMethodName; 367 String [] signature = null; 368 Object [] params = null; 369 info = (MBeanInfo ) this.invoke(objName, operationName, params, signature); 370 } 371 catch(MBeanException e) 372 { 373 throw new IntrospectionException (e.getMessage()); 374 } 375 376 return ( info ); 377 } 378 379 public boolean isRegistered(ObjectName name) 380 { 381 return mMBeanRepository.contains(name); 382 } 383 384 public void addNotificationListener(ObjectName objectName, 385 NotificationListener notificationListener, 386 NotificationFilter notificationFilter, Object obj) 387 throws InstanceNotFoundException 388 { 389 String msg = localStrings.getString( "admin.server.core.jmx.mbeanserver_addnotificationlistener" ); 390 throw new UnsupportedOperationException ( msg ); 391 } 392 393 public void addNotificationListener (ObjectName objectName, 394 ObjectName objectName1, NotificationFilter notificationFilter, 395 Object obj) throws InstanceNotFoundException 396 { 397 String msg = localStrings.getString( "admin.server.core.jmx.mbeanserver_addnotificationlistener" ); 398 throw new UnsupportedOperationException ( msg ); 399 } 400 401 public ObjectInstance createMBean (String str, ObjectName objectName) 402 throws ReflectionException , InstanceAlreadyExistsException , 403 MBeanRegistrationException , MBeanException , 404 NotCompliantMBeanException 405 { 406 String msg = localStrings.getString( "admin.server.core.jmx.mbeanserver_creatembean" ); 407 throw new UnsupportedOperationException ( msg ); 408 } 409 410 public ObjectInstance createMBean (String str, ObjectName objectName, 411 ObjectName objectName2) throws ReflectionException , 412 InstanceAlreadyExistsException , MBeanRegistrationException , javax.management.MBeanException , javax.management.NotCompliantMBeanException , javax.management.InstanceNotFoundException 413 { 414 String msg = localStrings.getString( "admin.server.core.jmx.mbeanserver_creatembean" ); 415 throw new UnsupportedOperationException ( msg ); 416 } 417 418 public ObjectInstance createMBean (String str, ObjectName objectName, 419 Object [] obj, String [] str3) 420 throws ReflectionException , InstanceAlreadyExistsException , 421 MBeanRegistrationException , MBeanException , NotCompliantMBeanException 422 { 423 String msg = localStrings.getString( "admin.server.core.jmx.mbeanserver_creatembean" ); 424 throw new UnsupportedOperationException ( msg ); 425 } 426 427 public ObjectInstance createMBean (String str, ObjectName objectName, 428 ObjectName objectName2, Object [] obj, String [] str4) 429 throws ReflectionException , InstanceAlreadyExistsException , 430 MBeanRegistrationException , MBeanException , 431 NotCompliantMBeanException , InstanceNotFoundException 432 { 433 String msg = localStrings.getString( "admin.server.core.jmx.mbeanserver_creatembean" ); 434 throw new UnsupportedOperationException ( msg ); 435 } 436 437 public ObjectInputStream deserialize (String str, byte[] values) 438 throws OperationsException , ReflectionException 439 { 440 String msg = localStrings.getString( "admin.server.core.jmx.mbeanserver_deserialize" ); 441 throw new UnsupportedOperationException ( msg ); 442 } 443 444 public ObjectInputStream deserialize (ObjectName objectName, byte[] values) 445 throws InstanceNotFoundException , OperationsException 446 { 447 String msg = localStrings.getString( "admin.server.core.jmx.mbeanserver_deserialize" ); 448 throw new UnsupportedOperationException ( msg ); 449 } 450 451 public ObjectInputStream deserialize (String str, ObjectName objectName, 452 byte[] values) throws InstanceNotFoundException , OperationsException , 453 ReflectionException 454 { 455 String msg = localStrings.getString( "admin.server.core.jmx.mbeanserver_deserialize" ); 456 throw new UnsupportedOperationException ( msg ); 457 } 458 459 public AttributeList getAttributes(ObjectName objectName, String [] attrNames) 460 throws InstanceNotFoundException , ReflectionException { 462 Object implObject = mMBeanRepository.find(objectName); 464 if (implObject == null ) 465 { 466 throw new InstanceNotFoundException (objectName.toString()); 467 } 468 Class implClass = implObject.getClass(); 469 AttributeList list = new AttributeList (); 470 try 471 { 472 MBeanIntrospector introspector = new MBeanIntrospector(implClass); 473 if (introspector.isDynamicMBean()) 474 { 475 Method method = introspector.getMethod("getAttributes", 476 new String [] {"[Ljava.lang.String;"}); 477 list = (AttributeList )introspector.invokeMethodOn(method, implObject, 478 new Object [] {attrNames}); 479 } 480 } 481 catch (javax.management.NotCompliantMBeanException e) 482 { 483 487 } 488 catch (java.lang.ClassNotFoundException cnfe) 489 { 490 throw new javax.management.ReflectionException (cnfe); 491 } 492 catch (java.lang.NoSuchMethodException nsme) 493 { 494 throw new javax.management.ReflectionException (nsme); 495 } 496 catch (java.lang.SecurityException se) 497 { 498 throw new javax.management.ReflectionException (se); 499 } 500 catch (java.lang.IllegalAccessException iae) 501 { 502 throw new javax.management.ReflectionException (iae); 503 } 505 catch (java.lang.reflect.InvocationTargetException ite) 506 { 507 Throwable t = ite.getTargetException(); 508 String msg = localStrings.getString( "admin.server.core.jmx.getattributes_error_from_mbean", t.getMessage() ); 509 throw new RuntimeException ( msg ); 510 } 511 return list; 512 513 } 514 515 public String getDefaultDomain () 516 { 517 return ( ServiceName.DOMAIN ); 518 } 519 520 public ObjectInstance getObjectInstance (ObjectName objectName) 521 throws InstanceNotFoundException 522 { 523 String msg = localStrings.getString( "admin.server.core.jmx.mbeanserver_getobjectinstance" ); 524 throw new UnsupportedOperationException ( msg ); 525 } 526 527 public Object instantiate (String str) throws ReflectionException , 528 MBeanException 529 { 530 String msg = localStrings.getString( "admin.server.core.jmx.mbeanserver_instantiate" ); 531 throw new UnsupportedOperationException ( msg ); 532 } 533 534 public Object instantiate (String str, ObjectName objectName) 535 throws ReflectionException , MBeanException , InstanceNotFoundException 536 { 537 String msg = localStrings.getString( "admin.server.core.jmx.mbeanserver_instantiate" ); 538 throw new UnsupportedOperationException ( msg ); 539 } 540 541 public Object instantiate (String str, Object [] obj, String [] str2) 542 throws ReflectionException , MBeanException 543 { 544 String msg = localStrings.getString( "admin.server.core.jmx.mbeanserver_instantiate" ); 545 throw new UnsupportedOperationException ( msg ); 546 } 547 548 public Object instantiate (String str, ObjectName objectName, 549 Object [] obj, String [] str3) 550 throws ReflectionException , MBeanException , InstanceNotFoundException 551 { 552 String msg = localStrings.getString( "admin.server.core.jmx.mbeanserver_instantiate" ); 553 throw new UnsupportedOperationException ( msg ); 554 } 555 556 public boolean isInstanceOf (ObjectName objectName, String str) 557 throws InstanceNotFoundException 558 { 559 String msg = localStrings.getString( "admin.server.core.jmx.mbeanserver_isinstanceof" ); 560 throw new UnsupportedOperationException ( msg ); 561 } 562 563 public Set queryNames (ObjectName objectName, QueryExp queryExp) 564 { 565 String msg = localStrings.getString( "admin.server.core.jmx.mbeanserver_querynames" ); 566 throw new UnsupportedOperationException ( msg ); 567 } 568 569 public void removeNotificationListener (ObjectName objectName, ObjectName objectName1) 570 throws InstanceNotFoundException , ListenerNotFoundException 571 { 572 String msg = localStrings.getString( "admin.server.core.jmx.mbeanserver_removenotificationlistener" ); 573 throw new UnsupportedOperationException ( msg ); 574 } 575 576 public void removeNotificationListener (ObjectName objectName, 577 NotificationListener notificationListener) 578 throws InstanceNotFoundException , ListenerNotFoundException 579 { 580 String msg = localStrings.getString( "admin.server.core.jmx.mbeanserver_removenotificationlistener" ); 581 throw new UnsupportedOperationException ( msg ); 582 } 583 584 public AttributeList setAttributes (ObjectName objectName, AttributeList attributeList) 585 throws InstanceNotFoundException , ReflectionException { 587 Object implObject = mMBeanRepository.find(objectName); 589 if (implObject == null ) 590 { 591 throw new InstanceNotFoundException (objectName.toString()); 592 } 593 Class implClass = implObject.getClass(); 594 AttributeList list = new AttributeList (); 595 try 596 { 597 MBeanIntrospector introspector = new MBeanIntrospector(implClass); 598 if (introspector.isDynamicMBean()) 599 { 600 Method method = introspector.getMethod("setAttributes", 601 new String [] {list.getClass().getName()}); 602 list = (AttributeList )introspector.invokeMethodOn(method, implObject, 603 new Object [] {attributeList}); 604 } 605 } 606 catch (javax.management.NotCompliantMBeanException e) 607 { 608 612 } 613 catch (java.lang.ClassNotFoundException cnfe) 614 { 615 throw new javax.management.ReflectionException (cnfe); 616 } 617 catch (java.lang.NoSuchMethodException nsme) 618 { 619 throw new javax.management.ReflectionException (nsme); 620 } 621 catch (java.lang.SecurityException se) 622 { 623 throw new javax.management.ReflectionException (se); 624 } 625 catch (java.lang.IllegalAccessException iae) 626 { 627 throw new javax.management.ReflectionException (iae); 628 } 630 catch (java.lang.reflect.InvocationTargetException ite) 631 { 632 Throwable t = ite.getTargetException(); 633 String msg = localStrings.getString( "admin.server.core.jmx.setattributes_error_from_mbean", t.getMessage() ); 634 throw new RuntimeException ( msg ); 635 } 636 return list; 637 638 } 639 640 641 public String [] getDomains() { 642 final String msg = "getDomains"; 643 644 throw new UnsupportedOperationException (msg); 645 } 646 647 public void removeNotificationListener(ObjectName name, 648 ObjectName listener, NotificationFilter filter, Object handback) { 649 final String msg = "removeNotificationListener"; 650 651 throw new UnsupportedOperationException (msg); 652 } 653 654 public void removeNotificationListener(ObjectName name, 655 NotificationListener listener, NotificationFilter filter, 656 Object handback) { 657 final String msg = "removeNotificationListener"; 658 659 throw new UnsupportedOperationException (msg); 660 } 661 662 public ClassLoader getClassLoaderFor(ObjectName oName) { 663 final String msg = "getClassLoaderFor"; 664 665 throw new UnsupportedOperationException (msg); 666 } 667 668 public ClassLoader getClassLoader(ObjectName oName) { 669 final String msg = "getClassLoader"; 670 671 throw new UnsupportedOperationException (msg); 672 } 673 674 public javax.management.loading.ClassLoaderRepository getClassLoaderRepository() { 675 final String msg = "getClassLoaderRepository"; 676 677 throw new UnsupportedOperationException (msg); 678 } 679 680 681 } 682 | Popular Tags |