1 23 package com.sun.enterprise.management.j2ee; 24 25 import java.util.Set ; 26 import java.util.HashSet ; 27 import java.util.Map ; 28 import java.util.HashMap ; 29 import java.util.Collections ; 30 import java.util.Iterator ; 31 32 import javax.management.ObjectName ; 33 import javax.management.MBeanInfo ; 34 import javax.management.MBeanAttributeInfo ; 35 import javax.management.j2ee.statistics.Stats ; 36 import javax.management.Attribute ; 37 import javax.management.AttributeNotFoundException ; 38 39 import com.sun.enterprise.management.support.AMXNonConfigImplBase; 40 41 42 import com.sun.appserv.management.util.misc.GSetUtil; 43 import com.sun.appserv.management.util.misc.MapUtil; 44 import com.sun.appserv.management.util.misc.ExceptionUtil; 45 import com.sun.enterprise.management.support.AMXAttributeNameMapper; 46 import com.sun.appserv.management.util.jmx.JMXUtil; 47 import com.sun.appserv.management.util.jmx.AttributeNameManglerImpl; 48 49 import com.sun.appserv.management.base.Util; 50 import com.sun.appserv.management.base.AMX; 51 import com.sun.appserv.management.base.XTypes; 52 import com.sun.appserv.management.base.QueryMgr; 53 import com.sun.appserv.management.base.Extra; 54 55 import com.sun.appserv.management.j2ee.J2EETypes; 56 import com.sun.appserv.management.j2ee.J2EEServer; 57 import com.sun.appserv.management.j2ee.J2EEManagedObject; 58 import com.sun.appserv.management.j2ee.ConfigPeer; 59 60 import com.sun.appserv.management.monitor.MonitoringStats; 61 62 import com.sun.appserv.management.config.ServerConfig; 63 64 import com.sun.enterprise.management.support.Delegate; 65 66 import com.sun.enterprise.management.support.TypeInfos; 67 68 69 71 public abstract class J2EEManagedObjectImplBase extends AMXNonConfigImplBase 72 { 73 protected long mStartTime; 74 75 public 76 J2EEManagedObjectImplBase() 77 { 78 this( null ); 79 } 80 81 public 82 J2EEManagedObjectImplBase( final Delegate delegate ) 83 { 84 super( delegate ); 85 mStartTime = 0; 86 } 87 88 protected 89 J2EEManagedObjectImplBase( String j2eeType, Delegate delegate ) 90 { 91 super( j2eeType, delegate ); 92 mStartTime = 0; 93 } 94 95 99 static private final Set <String > IGNORE_MISSING = 100 GSetUtil.newUnmodifiableStringSet( 101 "EJBModule", "J2EEApplication", "J2EEServer", "j2eeType", 102 "ModuleName", "eventTypes", "hasWebServices", "endpointAddresses" 103 ); 104 105 protected void 106 handleMissingOriginals( final Set <String > missingOriginals ) 107 { 108 missingOriginals.removeAll( IGNORE_MISSING ); 109 110 super.handleMissingOriginals( missingOriginals ); 111 } 112 113 114 public void 115 preRegisterDone() 116 throws Exception 117 { 118 super.preRegisterDone(); 119 mStartTime = System.currentTimeMillis(); 120 } 121 122 protected final void 123 setstartTime(final long startTime ) 124 { 125 mStartTime = startTime; 126 } 127 128 129 public long 130 getstartTime() 131 { 132 return( mStartTime ); 133 } 134 135 136 protected String 137 getServerName() 138 { 139 return( getObjectName().getKeyProperty( "J2EEServer" ) ); 140 } 141 142 protected String 143 getServerXType() 144 { 145 String type = null; 146 147 final String serverName = getServerName(); 148 if ( serverName != null ) 149 { 150 final Map <String ,ServerConfig> m = 151 getDomainRoot().getDomainConfig().getServerConfigMap(); 152 153 final ServerConfig serverConfig = m.get( serverName ); 154 type = serverConfig.getJ2EEType(); 155 } 156 157 return( type ); 158 } 159 160 163 private static final Map <String ,String > ToConfigMap = MapUtil.newMap( new String [] 164 { 165 J2EETypes.J2EE_DOMAIN, XTypes.DOMAIN_CONFIG, 166 J2EETypes.J2EE_CLUSTER, XTypes.CLUSTER_CONFIG, 167 J2EETypes.J2EE_SERVER, XTypes.STANDALONE_SERVER_CONFIG, 168 J2EETypes.JVM, XTypes.JAVA_CONFIG, 169 170 J2EETypes.J2EE_APPLICATION, XTypes.J2EE_APPLICATION_CONFIG, 171 J2EETypes.EJB_MODULE, XTypes.EJB_MODULE_CONFIG, 172 J2EETypes.WEB_MODULE, XTypes.WEB_MODULE_CONFIG, 173 J2EETypes.APP_CLIENT_MODULE, XTypes.APP_CLIENT_MODULE_CONFIG, 174 175 J2EETypes.JAVA_MAIL_RESOURCE, XTypes.MAIL_RESOURCE_CONFIG, 176 J2EETypes.JDBC_RESOURCE, XTypes.JDBC_RESOURCE_CONFIG, 177 J2EETypes.JNDI_RESOURCE, XTypes.JNDI_RESOURCE_CONFIG, 178 J2EETypes.WEB_SERVICE_ENDPOINT, XTypes.WEB_SERVICE_ENDPOINT_CONFIG, 179 } 180 ); 181 182 protected String 183 getConfigPeerJ2EEType() 184 { 185 final String configPeerJ2EEType = (String )ToConfigMap.get( getSelfJ2EEType() ); 186 187 return( configPeerJ2EEType ); 188 } 189 190 193 private static final Map <String ,String > MON_MAP = 194 Collections.unmodifiableMap( MapUtil.newMap( new String [] 195 { 196 J2EETypes.J2EE_SERVER, XTypes.SERVER_ROOT_MONITOR, 197 J2EETypes.J2EE_APPLICATION, XTypes.APPLICATION_MONITOR, 198 199 J2EETypes.WEB_MODULE, XTypes.WEB_MODULE_VIRTUAL_SERVER_MONITOR, 200 J2EETypes.SERVLET, XTypes.SERVLET_MONITOR, 201 202 J2EETypes.EJB_MODULE, XTypes.EJB_MODULE_MONITOR, 203 J2EETypes.STATELESS_SESSION_BEAN, XTypes.STATELESS_SESSION_BEAN_MONITOR, 204 J2EETypes.STATEFUL_SESSION_BEAN, XTypes.STATEFUL_SESSION_BEAN_MONITOR, 205 J2EETypes.ENTITY_BEAN, XTypes.ENTITY_BEAN_MONITOR, 206 J2EETypes.MESSAGE_DRIVEN_BEAN, XTypes.MESSAGE_DRIVEN_BEAN_MONITOR, 207 })); 208 209 protected String 210 getMonitoringPeerJ2EEType() 211 { 212 final String monPeerJ2EEType = (String )MON_MAP.get( getSelfJ2EEType() ); 213 214 return( monPeerJ2EEType ); 215 } 216 217 protected Map <String ,String > 218 getMonitoringPeerProps( 219 final String monitorJ2EEType, 220 final String monitorName ) 221 { 222 final Map <String ,String > props = new HashMap <String ,String >(); 223 224 props.put( AMX.J2EE_TYPE_KEY, monitorJ2EEType ); 225 props.put( AMX.NAME_KEY, monitorName ); 226 227 for( final String j2eeType : MON_MAP.keySet() ) 228 { 229 final String j2eeMonType = (String )MON_MAP.get( j2eeType ); 230 231 final String name = getKeyProperty( j2eeType ); 232 if ( name != null ) 233 { 234 props.put( j2eeMonType, name ); 235 } 236 } 237 238 return( props ); 239 } 240 241 protected Map <String ,String > 242 getMonitoringPeerProps( ) 243 { 244 Map <String ,String > props = null; 245 246 final String j2eeType = getMonitoringPeerJ2EEType(); 247 if ( j2eeType != null ) 248 { 249 props = getMonitoringPeerProps( j2eeType, getMonitoringPeerName() ); 250 } 251 return( props ); 252 } 253 254 protected ObjectName 255 queryProps( final Map <String ,String > propsMap ) 256 { 257 ObjectName objectName = null; 258 259 final String props = MapUtil.toString( propsMap, "," ); 260 261 final Set <ObjectName > candidates = 262 getQueryMgr().queryPropsObjectNameSet( props ); 263 if ( candidates.size() == 1 ) 264 { 265 objectName = GSetUtil.getSingleton( candidates ); 266 } 267 else if ( candidates.size() > 1 ) 268 { 269 throw new RuntimeException ( 270 "Unexpectedly found too many candidates for query pattern " + quote( props ) + 271 " found: " + toString( candidates ) ); 272 } 273 274 return( objectName ); 275 } 276 277 public ObjectName 278 getMonitoringPeerObjectName() 279 { 280 ObjectName objectName = null; 281 282 final Map <String ,String > propsMap = getMonitoringPeerProps(); 283 if ( propsMap != null && propsMap.keySet().size() != 0 ) 284 { 285 debug( "getMonitoringPeerObjectName: my ObjectName = ", getObjectName(), 286 ", queryProps = ", MapUtil.toString( propsMap, ", " ) ); 287 objectName = queryProps( propsMap ); 288 289 if ( objectName == null ) 290 { 291 objectName = queryMonitoringPeerFailed( propsMap ); 292 } 293 } 294 295 return( objectName ); 296 } 297 298 302 protected ObjectName 303 queryMonitoringPeerFailed( final Map <String ,String > propsMap ) 304 { 305 return null; 306 } 307 308 309 313 protected ObjectName 314 queryConfigPeerFailed( final Map <String ,String > propsMap ) 315 { 316 debug( "queryConfigPeerFailed: " + MapUtil.toString( propsMap ) ); 317 return null; 318 } 319 320 321 326 public final String 327 getobjectName() 328 { 329 return( getObjectName().toString() ); 330 } 331 332 333 public boolean 334 isstatisticProvider() 335 { 336 return( getMonitoringPeerObjectName() != null ); 337 } 338 339 public boolean 340 isstatisticsProvider() 341 { 342 return( isstatisticProvider() ); 343 } 344 345 protected Stats 346 getStatsGeneric() 347 { 348 Stats stats = null; 349 350 if ( isstatisticProvider() ) 351 { 352 final ObjectName mon = getMonitoringPeerObjectName(); 353 if ( mon != null ) 354 { 355 final AMX monStats = getProxyFactory().getProxy( mon, AMX.class); 356 try 357 { 358 final Extra extra = Util.getExtra( monStats ); 359 stats = (Stats )extra.getAttribute( "stats" ); 360 361 } 362 catch( Exception e ) 363 { 364 } 366 } 367 } 368 369 return( stats ); 370 } 371 372 public final String 373 getGroup() 374 { 375 return( AMX.GROUP_JSR77 ); 376 } 377 378 379 protected String 380 getConfigPeerName() 381 { 382 return( getSelfName() ); 383 } 384 385 protected String 386 getMonitoringPeerName() 387 { 388 return( getSelfName() ); 389 } 390 391 396 protected Map <String ,String > 397 getConfigPeerProps() 398 { 399 HashMap <String ,String > props = null; 400 final String j2eeType = getConfigPeerJ2EEType(); 401 if ( j2eeType != null ) 402 { 403 props = new HashMap <String ,String >(); 404 405 props.put( AMX.J2EE_TYPE_KEY, j2eeType ); 406 props.put( AMX.NAME_KEY, getConfigPeerName() ); 407 } 408 return( props ); 409 } 410 411 412 418 public ObjectName 419 getConfigPeerObjectName() 420 { 421 ObjectName configPeerObjectName = null; 422 423 if (isConfigProvider() ) 424 { 425 final Map <String ,String > propsMap = getConfigPeerProps( ); 426 if ( propsMap != null ) 427 { 428 configPeerObjectName = queryProps( propsMap ); 429 if ( configPeerObjectName == null ) 430 { 431 configPeerObjectName = queryConfigPeerFailed( propsMap ); 432 } 433 } 434 435 } 436 437 return( configPeerObjectName ); 438 } 439 440 441 public boolean 442 isConfigProvider() 443 { 444 return( ToConfigMap.keySet().contains( getSelfJ2EEType() ) ); 445 } 446 447 public boolean 448 iseventProvider() 449 { 450 return( false ); 451 } 452 453 public boolean 454 isstateManageable() 455 { 456 return( false ); 457 } 458 459 protected final String [] 460 getContaineeObjectNameStrings( final String j2eeType ) 461 { 462 final Set <ObjectName > objectNames = getContaineeObjectNameSet( j2eeType ); 463 464 final String [] names = GSetUtil.toStringArray( objectNames ); 465 466 return( names ); 467 } 468 469 public J2EEServer 470 getJ2EEServer() 471 { 472 return getProxyFactory().getProxy( getServerObjectName(), J2EEServer.class); 473 } 474 475 public ObjectName 476 getServerObjectName() 477 { 478 final ObjectName selfObjectName = getObjectName(); 479 480 ObjectName serverObjectName = null; 481 482 final String serverName = selfObjectName.getKeyProperty( J2EETypes.J2EE_SERVER ); 483 if ( serverName != null ) 484 { 485 final String props = Util.makeRequiredProps( J2EETypes.J2EE_SERVER, serverName ); 486 final Set <AMX> candidates = getQueryMgr().queryPatternSet( selfObjectName.getDomain(), props ); 487 488 serverObjectName = Util.getObjectName( GSetUtil.getSingleton( candidates ) ); 489 } 490 return( serverObjectName ); 491 } 492 493 494 private static final Set <String > DEPLOYED_TYPES = GSetUtil.newUnmodifiableStringSet( 495 J2EETypes.J2EE_APPLICATION, 496 J2EETypes.WEB_MODULE, 497 J2EETypes.EJB_MODULE, 498 J2EETypes.APP_CLIENT_MODULE, 499 J2EETypes.RESOURCE_ADAPTER_MODULE 500 ); 501 502 503 public Set <ObjectName > 504 getDeployedObjectsObjectNameSet() 505 { 506 return( getContaineeObjectNameSet( DEPLOYED_TYPES ) ); 507 } 508 509 public String [] 510 getdeployedObjects() 511 { 512 final String [] names = GSetUtil.toStringArray( getDeployedObjectsObjectNameSet() ); 513 return( names ); 514 } 515 516 519 protected Set <String > 520 getDontMapAttributeNames() 521 { 522 return( Collections.emptySet() ); 524 } 525 526 538 539 } 540 | Popular Tags |