1 23 24 28 29 package com.sun.enterprise.management.support; 30 31 import java.util.logging.Logger ; 32 import java.util.Set ; 33 import java.util.Map ; 34 import java.util.HashMap ; 35 import java.util.HashSet ; 36 import java.util.Iterator ; 37 import java.util.Collections ; 38 39 import javax.management.ObjectName ; 40 import javax.management.MBeanRegistrationException ; 41 import javax.management.InstanceAlreadyExistsException ; 42 43 44 import com.sun.enterprise.management.support.oldconfig.OldProps; 45 46 import com.sun.appserv.management.DomainRoot; 47 import com.sun.appserv.management.base.Util; 48 import com.sun.appserv.management.base.XTypes; 49 import com.sun.appserv.management.base.AMX; 50 import com.sun.appserv.management.base.SystemInfo; 51 52 import com.sun.appserv.management.config.ServerConfig; 53 import com.sun.appserv.management.config.DomainConfig; 54 55 import com.sun.appserv.management.util.jmx.JMXUtil; 56 import com.sun.appserv.management.util.misc.GSetUtil; 57 import com.sun.appserv.management.util.misc.ClassUtil; 58 import com.sun.appserv.management.util.misc.StringUtil; 59 60 import com.sun.appserv.management.j2ee.J2EETypes; 61 62 63 66 final class LoaderOfOld77 extends LoaderOfOld 67 { 68 private final String mAMXJMXDomain; 69 72 private final boolean mIsDAS; 73 74 LoaderOfOld77( final Loader loader ) 75 { 76 super( loader ); 77 78 mAMXJMXDomain = loader.getAMXJMXDomainName(); 79 80 final SystemInfo systemInfo = loader.getDomainRoot().getSystemInfo(); 81 mIsDAS = systemInfo.supportsFeature( SystemInfo.RUNNING_IN_DAS_FEATURE ); 82 } 83 84 public Set <ObjectName > 85 findAllOldCandidates() 86 { 87 final ObjectName pattern = JMXUtil.newObjectName( "com.sun.appserv", JMXUtil.WILD_ALL ); 88 final Set <ObjectName > all = JMXUtil.queryNames( getMBeanServer(), pattern, null ); 89 90 final Set <ObjectName > results = new HashSet <ObjectName >(); 91 for( final ObjectName objectName : all ) 92 { 93 if ( shouldSync( objectName ) ) 94 { 95 results.add( objectName ); 96 } 97 } 98 99 return( results ); 100 } 101 102 103 104 105 private boolean 106 isOld77ObjectName( final ObjectName objectName ) 107 { 108 final String j2eeType = objectName.getKeyProperty( "j2eeType" ); 109 110 boolean ret = ( j2eeType != null && 111 ! objectName.getDomain().equals( mAMXJMXDomain ) ); 112 113 return ret; 114 } 115 116 118 public static final Set SYNC_TYPES = GSetUtil.newUnmodifiableStringSet( 119 J2EETypes.J2EE_DOMAIN, 120 J2EETypes.J2EE_SERVER, 121 J2EETypes.J2EE_APPLICATION, 122 J2EETypes.APP_CLIENT_MODULE, 123 J2EETypes.EJB_MODULE, 124 J2EETypes.WEB_MODULE, 125 J2EETypes.RESOURCE_ADAPTER_MODULE, 126 J2EETypes.RESOURCE_ADAPTER, 127 J2EETypes.ENTITY_BEAN, 128 J2EETypes.STATEFUL_SESSION_BEAN, 129 J2EETypes.STATELESS_SESSION_BEAN, 130 J2EETypes.MESSAGE_DRIVEN_BEAN, 131 J2EETypes.SERVLET, 132 J2EETypes.JAVA_MAIL_RESOURCE, 133 J2EETypes.JCA_RESOURCE, 134 J2EETypes.JCA_CONNECTION_FACTORY, 135 J2EETypes.JCA_MANAGED_CONNECTION_FACTORY, 136 J2EETypes.JDBC_RESOURCE, 137 J2EETypes.JDBC_DATA_SOURCE, 138 J2EETypes.JDBC_DRIVER, 139 J2EETypes.JMS_RESOURCE, 140 J2EETypes.JNDI_RESOURCE, 141 J2EETypes.JTA_RESOURCE, 142 J2EETypes.RMI_IIOP_RESOURCE, 143 J2EETypes.URL_RESOURCE, 144 J2EETypes.JVM, 145 J2EETypes.WEB_SERVICE_ENDPOINT ); 146 147 148 149 protected Set 150 getNeedsSupport() 151 { 152 return( Collections.EMPTY_SET ); 153 } 154 155 protected Set 156 getIgnoreTypes() 157 { 158 return( Collections.EMPTY_SET ); 159 } 160 161 private boolean 162 isValidCompositeWebModuleName( final String compositeName ) 163 { 164 boolean valid = false; 165 166 try 167 { 168 final String webModuleName = WebModuleSupport.extractWebModuleName( compositeName ); 169 170 valid = true; 172 } 173 catch( Exception e ) 174 { 175 } 176 return valid; 177 } 178 179 private boolean 180 hasValidWebModuleName( final ObjectName objectName ) 181 { 182 boolean isValid = true; 183 184 final String j2eeType = Util.getJ2EEType( objectName ); 185 186 if ( j2eeType.equals( J2EETypes.SERVLET ) ) 190 { 191 final String compositeName = objectName.getKeyProperty( J2EETypes.WEB_MODULE ); 192 isValid = isValidCompositeWebModuleName( compositeName ); 193 } 194 else if (j2eeType.equals( J2EETypes.WEB_SERVICE_ENDPOINT)) 195 { 196 final String ejbModName = objectName.getKeyProperty( J2EETypes.EJB_MODULE); 198 if (ejbModName != null) 199 { 200 isValid = true; 201 } 202 else 203 { 204 final String compositeName = objectName.getKeyProperty( J2EETypes.WEB_MODULE ); 205 isValid = isValidCompositeWebModuleName( compositeName ); 206 } 207 } 208 else if ( j2eeType.equals( J2EETypes.WEB_MODULE ) ) 209 { 210 final String compositeName = objectName.getKeyProperty( AMX.NAME_KEY ); 211 isValid = isValidCompositeWebModuleName( compositeName ); 212 } 213 214 return( isValid ); 215 } 216 217 public boolean 218 isOldMBean( final ObjectName objectName ) 219 { 220 boolean shouldSync = isOld77ObjectName( objectName ); 221 222 if ( shouldSync ) 223 { 224 final String j2eeType = Util.getJ2EEType( objectName ); 225 shouldSync = SYNC_TYPES.contains( j2eeType ); 226 227 if ( shouldSync && ! hasValidWebModuleName( objectName ) ) 228 { 229 shouldSync = false; 231 232 getLogger().warning( 233 "Not registering AMX MBean against old MBean " + StringUtil.quote( objectName ) + 234 " due to malformed composite WebModule name." ); 235 } 236 } 237 238 return( shouldSync ); 239 } 240 241 245 private final static String [] CONTAINMENT_KEYS_77 = new String [] 246 { 247 AMX.NAME_KEY, 248 AMX.J2EE_TYPE_KEY, 249 J2EETypes.J2EE_DOMAIN, 250 J2EETypes.J2EE_SERVER, 251 J2EETypes.J2EE_APPLICATION, 252 J2EETypes.EJB_MODULE, 253 J2EETypes.WEB_MODULE, 254 J2EETypes.RESOURCE_ADAPTER_MODULE, 255 J2EETypes.JDBC_RESOURCE, 256 J2EETypes.JCA_RESOURCE, 257 J2EETypes.WEB_SERVICE_ENDPOINT, 258 }; 259 260 private Map <String ,String > 261 getOld77Props( final ObjectName oldObjectName ) 262 { 263 final Map <String ,String > m = new HashMap <String ,String >(); 264 265 for( int i = 0; i < CONTAINMENT_KEYS_77.length; ++i ) 266 { 267 final String key = CONTAINMENT_KEYS_77[ i ]; 268 269 final String value = oldObjectName.getKeyProperty( key ); 270 if ( value != null ) 271 { 272 m.put( key, value ); 273 } 274 } 275 276 return( m ); 277 } 278 279 284 protected ObjectName 285 oldToNewObjectName( final ObjectName oldObjectName ) 286 { 287 final String j2eeType = Util.getJ2EEType( oldObjectName ); 288 final String j2eeDomainName = getAMXJMXDomainName(); 289 290 final Map <String ,String > propsMap = getOld77Props( oldObjectName ); 291 if ( j2eeType.equals( J2EETypes.J2EE_DOMAIN ) ) 292 { 293 propsMap.put( AMX.NAME_KEY, j2eeDomainName ); 295 } 296 else if ( j2eeType.equals( J2EETypes.J2EE_SERVER ) ) 297 { 298 } 299 else 300 { 301 } 303 304 305 final String props = JMXUtil.mapToProps( propsMap ); 306 307 final ObjectName newName = Util.newObjectName( j2eeDomainName, props ); 308 309 return( newName ); 310 } 311 312 313 314 private final boolean 315 serverRunningInDAS( final String serverName ) 316 { 317 boolean runningInDAS = false; 318 319 if ( mIsDAS ) 320 { 321 runningInDAS = true; 323 } 324 325 return( runningInDAS ); 326 } 327 328 protected Class 329 getImplClass( 330 final ObjectName newObjectName, 331 final ObjectName oldObjectName ) 332 { 333 Class implClass = super.getImplClass( newObjectName, oldObjectName ); 334 335 final boolean isJ2EEServer = 336 Util.getJ2EEType( newObjectName ).equals( J2EETypes.J2EE_SERVER ); 337 if ( isJ2EEServer ) 338 { 339 final String serverName = Util.getName( newObjectName ); 342 final boolean isAdminServer = serverRunningInDAS( serverName ); 343 if ( isAdminServer ) 344 { 345 346 try 347 { 348 implClass = 349 ClassUtil.getClassFromName( "com.sun.enterprise.management.j2ee.DASJ2EEServerImpl"); 350 } 351 catch (ClassNotFoundException cnfe) 352 { 353 try 354 { 355 implClass = ClassUtil.getClassFromName( 356 "com.sun.enterprise.management.j2ee.J2EEServerImpl" ); 357 } 358 catch( ClassNotFoundException e ) 359 { 360 throw new RuntimeException ( e ); 361 } 362 } 363 } 364 getLogger().fine( 365 "LoaderOfOld77.getImplClass: Using J2EEServer impl of class: " + 366 implClass.getName() + 367 " for server " + serverName ); 368 369 } 370 371 return( implClass ); 372 } 373 374 } 375 | Popular Tags |