1 23 package com.sun.enterprise.management.support; 24 25 import java.util.Set ; 26 import java.util.Collections ; 27 28 import javax.management.ObjectName ; 29 import javax.management.MBeanServer ; 30 import javax.management.MBeanRegistrationException ; 31 import javax.management.InstanceAlreadyExistsException ; 32 import javax.management.InstanceNotFoundException ; 33 34 35 import com.sun.enterprise.management.support.oldconfig.OldProps; 36 import com.sun.appserv.management.base.Util; 37 import com.sun.appserv.management.base.XTypes; 38 import com.sun.appserv.management.base.AMX; 39 import com.sun.appserv.management.util.jmx.JMXUtil; 40 import com.sun.appserv.management.util.misc.GSetUtil; 41 import com.sun.appserv.management.util.misc.StringUtil; 42 import com.sun.appserv.management.util.stringifier.ArrayStringifier; 43 import com.sun.appserv.management.j2ee.J2EETypes; 44 import com.sun.enterprise.config.serverbeans.ApplicationHelper; 45 import com.sun.enterprise.config.serverbeans.WebModule; 46 import com.sun.enterprise.config.ConfigBean; 47 import com.sun.enterprise.admin.server.core.AdminService; 48 import com.sun.enterprise.config.ConfigContext; 49 50 51 54 final class LoaderOfOldMonitor extends LoaderOfOld 55 { 56 LoaderOfOldMonitor( final Loader loader ) 57 { 58 super( loader ); 59 } 60 61 public Set <ObjectName > 62 findAllOldCandidates() 63 { 64 final ObjectName pattern = JMXUtil.newObjectName( "com.sun.appserv:category=monitor,*" ); 65 final Set <ObjectName > all = JMXUtil.queryNames( getMBeanServer(), pattern, null ); 66 67 return( all ); 68 } 69 70 71 private final class MyOldTypes 72 implements OldTypeToJ2EETypeMapper 73 { 74 private final OldMonitorTypes mOldTypes; 75 76 public 77 MyOldTypes() 78 { 79 mOldTypes = OldMonitorTypes.getInstance(); 80 } 81 82 public String 83 j2eeTypeToOldType( final String j2eeType ) 84 { 85 String result = null; 86 87 if ( j2eeType.endsWith( "BeanMonitor" ) ) 88 { 89 result = "ejb"; 90 } 91 else 92 { 93 result = mOldTypes.j2eeTypeToOldType( j2eeType ); 94 } 95 96 return( result ); 97 } 98 99 100 public String 101 oldTypeToJ2EEType( final String oldType, final ObjectName oldObjectName ) 102 { 103 String j2eeType = null; 104 105 final String EJB = "ejb"; 106 107 111 if ( oldType.equals( EJB ) ) 112 { 113 116 if ( oldObjectName.getKeyProperty( "type" ).equals( EJB ) ) 117 { 118 String [] statisticNames = null; 120 try 121 { 122 statisticNames = (String [])getMBeanServer().invoke( oldObjectName, "getStatisticNames", null, null); 123 } 124 catch ( Exception e ) 125 { 126 throw new RuntimeException ( "Can't invoke getStatisticNames() on " + oldObjectName, e ); 127 } 128 129 final Set <String > names = GSetUtil.newSet( statisticNames ); 131 assert( names.contains( "CreateCount" ) ) : 132 "MBean " + oldObjectName + " does not contain 'RemoveCount' as a Statistic name: all = " + 133 ArrayStringifier.stringify( statisticNames, ", " ); 134 assert( names.contains( "RemoveCount" ) ); 135 if ( names.contains( "MethodReadyCount" ) ) 136 { 137 if ( names.contains( "PassiveCount" ) ) 138 { 139 j2eeType = XTypes.STATEFUL_SESSION_BEAN_MONITOR; 140 } 141 else 142 { 143 j2eeType = XTypes.STATELESS_SESSION_BEAN_MONITOR; 144 } 145 } 146 else if ( names.contains( "MessageCount" ) ) 147 { 148 j2eeType = XTypes.MESSAGE_DRIVEN_BEAN_MONITOR; 149 } 150 else if ( names.contains( "ReadyCount" ) && names.contains( "PooledCount" ) ) 151 { 152 j2eeType = XTypes.ENTITY_BEAN_MONITOR; 153 } 154 else 155 { 156 throw new RuntimeException ( "Unknown type of ejb monitor: " + oldObjectName ); 157 } 158 } 159 else 160 { 161 167 final String parentName = oldObjectName.getKeyProperty( EJB ); 168 final String parentModuleName = oldObjectName.getKeyProperty( "ejb-module" ); 169 final String serverName = oldObjectName.getKeyProperty( "server" ); 170 final String applicationName = oldObjectName.getKeyProperty( "application" ); 171 172 final String parentTypeProp = Util.makeProp( "type", EJB ); 173 final String parentNameProp = Util.makeProp( "name", parentName ); 174 final String parentModuleNameProp = Util.makeProp( "ejb-module", parentModuleName ); 175 final String parentProps = Util.concatenateProps( parentTypeProp, parentNameProp, parentModuleNameProp ); 176 final String serverProp = Util.makeProp( "server", serverName ); 177 178 String props = Util.concatenateProps( serverProp, parentProps, "category=monitor" ); 179 180 if ( applicationName != null ) 181 { 182 final String applicationProp = Util.makeProp( "application", applicationName ); 183 props = Util.concatenateProps( props, applicationProp ); 184 } 185 186 187 final ObjectName pattern = JMXUtil.newObjectNamePattern( "com.sun.appserv", props ); 188 189 final Set <ObjectName > candidates = 190 JMXUtil.queryNames( getMBeanServer(), pattern, null ); 191 192 if ( candidates.size() == 0 ) 193 { 194 getLogger().fine( "Can't find MBean for pattern " + 195 StringUtil.quote( pattern ) + 196 " corresponding to " + StringUtil.quote( oldObjectName ) ); 197 throw new RuntimeException ( new DeferRegistrationException( pattern ) ); 198 } 199 200 final ObjectName beanObjectName = GSetUtil.getSingleton( candidates ); 201 j2eeType = oldTypeToJ2EEType( EJB, beanObjectName ); 202 } 203 } 204 else 205 { 206 j2eeType = mOldTypes.oldTypeToJ2EEType( oldType, oldObjectName ); 207 } 208 return( j2eeType ); 209 } 210 211 public String 212 oldObjectNameToJ2EEType( final ObjectName oldObjectName ) 213 { 214 final String oldType = oldObjectName.getKeyProperty( "type" ); 215 216 return( oldTypeToJ2EEType( oldType, oldObjectName ) ); 217 } 218 } 219 220 private static void 221 mySleep( final long millis ) 222 { 223 try 224 { 225 Thread.sleep( millis ); 226 } 227 catch( InterruptedException e ) 228 { 229 } 230 } 231 232 private final String 233 formApplicationAndServerProps( final ObjectName oldObjectName ) 234 { 235 final String serverName = oldObjectName.getKeyProperty( "server" ); 236 final String serverProp = Util.makeProp( XTypes.SERVER_ROOT_MONITOR, serverName ); 237 238 String props = serverProp; 239 240 String applicationName = oldObjectName.getKeyProperty( "application" ); 241 if ( applicationName == null ) 242 { 243 applicationName = AMX.NULL_NAME; 244 } 245 final String applicationProp = Util.makeProp( XTypes.APPLICATION_MONITOR, applicationName ); 246 247 props = Util.concatenateProps( props, applicationProp ); 248 249 return( props ); 250 } 251 252 287 288 protected ObjectName 289 oldToNewObjectName( final ObjectName oldObjectName ) 290 { 291 final String oldType = oldObjectName.getKeyProperty( "type" ); 292 final String domainName = mLoader.getAMXJMXDomainName(); 293 294 ObjectName newObjectName = null; 295 296 if ( oldType.equals( "servlet" ) ) 316 { 317 final String webModuleVirtualServerMonitorName = oldObjectName.getKeyProperty( "webmodule-virtual-server" ); 320 321 final String requiredProps = 322 Util.makeRequiredProps( XTypes.SERVLET_MONITOR, oldObjectName.getKeyProperty( "name" ) ); 323 324 final String containerProp = 325 Util.makeProp( XTypes.WEB_MODULE_VIRTUAL_SERVER_MONITOR, webModuleVirtualServerMonitorName ); 326 final String containmentProps = formApplicationAndServerProps( oldObjectName ); 327 328 final String props = Util.concatenateProps( requiredProps, containerProp, containmentProps); 329 330 newObjectName = JMXUtil.newObjectName( domainName, props ); 331 } 332 else 333 if ( oldType.equals( "webservice-endpoint" )) 334 { 335 String ejbModName = 338 oldObjectName.getKeyProperty("standalone-ejb-module"); 339 if ( ejbModName == null) 340 { 341 ejbModName = oldObjectName.getKeyProperty("ejb-module"); 343 } 344 if ( ejbModName != null) 345 { 346 final String requiredProps = 347 Util.makeRequiredProps( XTypes.WEBSERVICE_ENDPOINT_MONITOR, oldObjectName.getKeyProperty( "name" ) ); 348 349 final String modProp = Util.makeProp( XTypes.EJB_MODULE_MONITOR, ejbModName ); 350 final String containmentProps = formApplicationAndServerProps( oldObjectName ); 351 352 final String props = 353 Util.concatenateProps( requiredProps, modProp, containmentProps); 354 355 newObjectName = JMXUtil.newObjectName( domainName, props ); 356 } 357 else 358 { 359 381 final String requiredProps = 382 Util.makeRequiredProps( XTypes.WEBSERVICE_ENDPOINT_MONITOR, oldObjectName.getKeyProperty( "name" ) ); 383 384 final String webModuleVirtualServerMonitorName = 385 oldObjectName.getKeyProperty( "webmodule-virtual-server" ); 386 final String modProp = 387 Util.makeProp( XTypes.WEB_MODULE_VIRTUAL_SERVER_MONITOR, webModuleVirtualServerMonitorName ); 388 final String containmentProps = formApplicationAndServerProps( oldObjectName ); 389 390 final String props = 391 Util.concatenateProps( requiredProps, modProp, containmentProps); 392 393 newObjectName = JMXUtil.newObjectName( domainName, props ); 394 } 395 396 } 397 else 398 { 399 final OldTypeToJ2EETypeMapper mapper = new MyOldTypes(); 400 final OldProps oldProps = new OldProps( oldObjectName, mapper); 401 402 String props = oldProps.getNewProps(); 403 newObjectName = JMXUtil.newObjectName( domainName, props ); 404 405 410 final String j2eeType = newObjectName.getKeyProperty( AMX.J2EE_TYPE_KEY ); 411 final String [] fullType = TypeInfos.getInstance().getJ2EETypeChain( newObjectName ); 412 for( int i = 0; i < fullType.length - 1; ++i ) 413 { 414 if ( fullType[ i ].equals( XTypes.APPLICATION_MONITOR ) && 415 newObjectName.getKeyProperty( XTypes.APPLICATION_MONITOR ) == null ) 416 { 417 final String prop = Util.makeProp( XTypes.APPLICATION_MONITOR, AMX.NULL_NAME ); 418 newObjectName = JMXUtil.newObjectName( newObjectName, prop ); 419 break; 420 } 421 } 422 } 423 return( newObjectName ); 424 } 425 426 427 private String 429 getContextRoot( final String webModuleName ) { 430 431 ConfigBean cb = null; 432 ConfigContext cCtx = AdminService.getAdminService(). 433 getAdminContext().getAdminConfigContext(); 434 435 try { 436 cb = ApplicationHelper.findApplication(cCtx, webModuleName); 437 } catch(Exception e) { 438 return null; 440 } 441 if (cb instanceof WebModule) { 442 String ctxRoot = ((WebModule) cb).getContextRoot(); 443 if ((ctxRoot != null) && (ctxRoot.length() > 0)) { 444 if (ctxRoot.charAt(0) == '/'){ 445 ctxRoot = ctxRoot.substring(1,ctxRoot.length()) ; 446 } 447 } 448 return ctxRoot; 449 } else { 450 return null; 451 } 452 } 453 454 private boolean 455 isOldMonitorObjectName( final ObjectName objectName ) 456 { 457 boolean isOldMonitor = false; 458 459 if ( objectName.getDomain().equals( "com.sun.appserv" ) && 460 "monitor".equals( objectName.getKeyProperty( "category" ) ) ) 461 { 462 final String type = objectName.getKeyProperty( "type" ); 463 464 isOldMonitor = ! getIgnoreTypes().contains( type ); 465 } 466 467 return( isOldMonitor ); 468 } 469 470 473 private static final Set <String > IGNORE_TYPES = GSetUtil.newUnmodifiableStringSet( 474 "connection-factories", 475 "connector-modules", 476 "connector-service", 477 "connection-factory", 478 "connection-pools", 479 "resources", 480 "thread-pools", 481 "applications", 482 "orb", 483 "connection-managers", 484 "bean-methods", 485 486 "web-module", 488 "standalone-web-module", 489 490 "operating-system", 492 "threadinfo", 493 "memory", 494 "thread-system", 495 "garbage-collectors", 496 "garbage-collector", 497 "runtime", 498 "compilation-system", 499 "class-loading-system", 500 501 "request", 503 "pwc-thread-pool", 504 505 "jndi", 507 "jms-service", 508 "jndi", 509 510 "GMSClientMBean", 511 512 "DomainDiagnostics", 514 "JVMInformation", 515 "JVMInformationCollector", 516 "work-management" 517 ); 518 519 522 private static final Set <String > NEEDS_SUPPORT = GSetUtil.newUnmodifiableStringSet( 523 ); 529 530 531 protected Set <String > 532 getNeedsSupport() 533 { 534 return( NEEDS_SUPPORT ); 535 } 536 537 protected Set <String > 538 getIgnoreTypes() 539 { 540 return( IGNORE_TYPES ); 541 } 542 543 544 public boolean 545 isOldMBean( final ObjectName oldObjectName ) 546 { 547 return isOldMonitorObjectName( oldObjectName ); 548 } 549 550 } 551 552 553 554 555 556 557 558 559 | Popular Tags |