1 23 24 26 27 package com.sun.enterprise.management.support; 28 29 import java.util.List ; 30 import java.util.ArrayList ; 31 import java.util.Map ; 32 import java.util.HashMap ; 33 import java.util.Collections ; 34 import java.util.Iterator ; 35 import java.io.IOException ; 36 37 import java.lang.reflect.Proxy ; 38 39 import javax.management.ObjectName ; 40 import javax.management.MBeanServer ; 41 import javax.management.Notification ; 42 import javax.management.MBeanServerNotification ; 43 import javax.management.InstanceNotFoundException ; 44 import javax.management.MBeanRegistrationException ; 45 import javax.management.InstanceAlreadyExistsException ; 46 import javax.management.NotCompliantMBeanException ; 47 48 import javax.management.relation.MBeanServerNotificationFilter ; 49 50 51 import com.sun.appserv.management.base.XTypes; 52 import com.sun.appserv.management.base.Util; 53 54 import com.sun.appserv.management.util.jmx.stringifier.NotificationStringifier; 55 import com.sun.appserv.management.util.jmx.JMXUtil; 56 import com.sun.appserv.management.util.jmx.MBeanProxyHandler; 57 import com.sun.appserv.management.util.jmx.MBeanServerConnectionSource; 58 import com.sun.appserv.management.util.jmx.stringifier.StringifierRegistryIniter; 59 60 import com.sun.appserv.management.util.misc.ExceptionUtil; 61 62 import com.sun.appserv.management.util.stringifier.StringifierRegistryIniterImpl; 63 import com.sun.appserv.management.util.stringifier.StringifierRegistryImpl; 64 65 import com.sun.appserv.management.DomainRoot; 66 import com.sun.appserv.management.client.ProxyFactory; 67 68 import com.sun.enterprise.management.support.TypeInfos; 69 70 73 abstract class LoaderBase extends MBeanImplBase 74 implements LoaderMBean, LoaderRegHandler 75 { 76 protected boolean mStarted; 77 protected ObjectNames mObjectNames; 78 79 public 80 LoaderBase() 81 { 82 debug( "LoaderBase" ); 83 84 final boolean offline = false; 85 BootUtil.init( false ); 86 87 mServer = null; 88 89 new StringifierRegistryIniterImpl( StringifierRegistryImpl.DEFAULT ); 90 new StringifierRegistryIniter( StringifierRegistryImpl.DEFAULT ); 91 92 mStarted = false; 93 mObjectNames = null; 94 } 95 96 public String 97 getAMXJMXDomainName() 98 { 99 return( BootUtil.getInstance().getAMXJMXDomainName() ); 100 } 101 102 103 public String 104 getAdministrativeDomainName() 105 { 106 return( BootUtil.getInstance().getAppserverDomainName() ); 107 } 108 109 110 public void 111 handleNotification( 112 final Notification notifIn, 113 final Object handback) 114 { 115 116 } 117 118 public void 119 handleMBeanRegistered( final ObjectName oldObjectName ) 120 throws InstanceNotFoundException 121 { 122 } 123 124 public void 125 handleMBeanUnregistered( final ObjectName oldObjectName ) 126 throws InstanceNotFoundException , MBeanRegistrationException 127 { 128 } 129 130 protected static long 131 now() 132 { 133 return( System.currentTimeMillis() ); 134 } 135 136 public ObjectName 137 loadSystemInfo( final MBeanServer server ) 138 throws NotCompliantMBeanException , MBeanRegistrationException , 139 InstanceAlreadyExistsException 140 { 141 debug( "loadSystemInfo" ); 142 143 final BootUtil bootUtil = BootUtil.getInstance(); 144 145 final SystemInfoImpl systemInfo = new SystemInfoImpl( server, bootUtil ); 146 147 final ObjectName tempName = mObjectNames.getSingletonObjectName( systemInfo.J2EE_TYPE ); 148 149 final ObjectName objectName = mServer.registerMBean( systemInfo, tempName ).getObjectName(); 150 151 debug( "loaded SystemInfo" ); 152 return( objectName ); 153 } 154 155 protected void 156 preRegisterHook() 157 { 158 } 159 160 public final ObjectName 161 preRegister( 162 final MBeanServer server, 163 final ObjectName objectNameIn) 164 throws Exception 165 { 166 debug( "preRegister" ); 167 final ObjectName superObjectName = super.preRegister( server, objectNameIn ); 168 169 mObjectNames = ObjectNames.getInstance( getAMXJMXDomainName() ); 170 171 final String domain = BootUtil.getInstance().getAMXSupportJMXDomain(); 172 mSelfObjectName = Util.newObjectName( domain, LOADER_NAME_PROPS ); 173 174 preRegisterHook(); 175 176 try 177 { 178 loadSystemInfo( server ); 179 180 final MBeanServerNotificationFilter filter = 181 new MBeanServerNotificationFilter (); 182 183 filter.enableAllObjectNames(); 184 185 JMXUtil.listenToMBeanServerDelegate( mServer, this, filter, null ); 186 187 } 188 catch( Exception e ) 189 { 190 throw new RuntimeException ( e ); 191 } 192 193 debug( "preRegister done: " + mSelfObjectName ); 194 return( mSelfObjectName ); 195 } 196 197 public void 198 postRegister( Boolean registrationDone ) 199 { 200 super.postRegister( registrationDone ); 201 202 if ( registrationDone.booleanValue() ) 203 { 204 initLOADER( getMBeanServer(), getObjectName() ); 205 } 206 207 start(); 208 } 209 210 protected boolean 211 mySleep( final long millis ) 212 { 213 boolean interrupted = false; 214 215 try 216 { 217 Thread.sleep( millis ); 218 } 219 catch( InterruptedException e ) 220 { 221 Thread.interrupted(); 222 interrupted = true; 223 } 224 225 return interrupted; 226 } 227 228 protected void 229 startHook() 230 { 231 } 233 234 235 private final class CheckStartedThread extends Thread 236 { 237 public void CheckStartedThread() {} 238 239 public void 240 run() 241 { 242 final long AMX_READY_SLEEP_DURATION = 100; 243 244 while ( ! isStarted() ) 245 { 246 debug( "Waiting " + AMX_READY_SLEEP_DURATION + "ms for AMX to start"); 247 sleepMillis( AMX_READY_SLEEP_DURATION ); 248 } 249 250 BootUtil.getInstance().setAMXReady( true ); 251 } 252 } 253 254 255 public boolean 256 isStarted( ) 257 { 258 return( mStarted ); 259 } 260 261 protected abstract Object createDomainRoot(); 262 263 public abstract boolean isDAS(); 264 265 private final void 266 loadDomainRoot() 267 { 268 debug( "loadDomainRoot ENTER" ); 269 final Object domainRoot = createDomainRoot(); 270 if ( domainRoot != null ) 271 { 272 ObjectName objectName = mObjectNames.getDomainRootObjectName( ); 273 274 debug( "Registering DomainRoot, impl class = " + domainRoot.getClass().getName() ); 275 try 276 { 277 objectName = mServer.registerMBean( domainRoot, objectName ).getObjectName(); 278 debug( "Registered DomainRoot: " + objectName ); 279 } 280 catch( final Exception e ) 281 { 282 final Throwable rootCause = ExceptionUtil.getRootCause(e); 283 debug( "Exception loading DomainRoot: " + 284 rootCause + ", msg=" + rootCause.getMessage() ); 285 throw new RuntimeException ( rootCause ); 286 } 287 } 288 else 289 { 290 debug( "loadDomainRoot: NULL" ); 291 } 292 293 debug( "loadDomainRoot DONE" ); 294 } 295 296 public final DomainRoot 297 getDomainRoot() 298 { 299 final ProxyFactory factory = 300 ProxyFactory.getInstance( getMBeanServer() ); 301 302 return( factory.getDomainRoot() ); 303 } 304 305 private static LoaderMBean LOADER = null; 306 307 private static void 308 initLOADER( final MBeanServer server, final ObjectName loaderObjectName ) 309 { 310 assert( LOADER == null ); 311 312 try 313 { 314 final MBeanServerConnectionSource conn = new MBeanServerConnectionSource( server ); 315 final MBeanProxyHandler handler = new MBeanProxyHandler( conn, loaderObjectName ); 316 317 LOADER = (LoaderMBean) 318 Proxy.newProxyInstance( LoaderMBean.class.getClassLoader(), new Class [] { LoaderMBean.class }, handler); 319 } 320 catch( IOException e ) 321 { 322 assert( false ) : "can't happen"; 323 throw new RuntimeException ( e ); 324 } 325 } 326 327 328 public static LoaderMBean 329 getLoader( final MBeanServer server ) 330 { 331 return( LOADER ); 332 } 333 334 335 protected void 336 start() 337 { 338 synchronized( this ) 339 { 340 if ( mStarted ) 341 { 342 throw new IllegalArgumentException ( "Can't start Loader twice" ); 343 } 344 mStarted = true; 345 } 346 347 new AMXDebugSupport( mServer ); 348 loadDomainRoot(); 349 350 startHook(); 351 352 (new CheckStartedThread()).start(); 353 } 354 355 356 public ObjectName 357 sync( final ObjectName name) 358 { 359 throw new UnsupportedOperationException ( "sync" ); 360 } 361 362 363 368 public void 369 adminServiceReady() 370 { 371 } 373 374 public ObjectName 375 resyncAMXMBean( final ObjectName amx ) 376 throws InstanceNotFoundException , MBeanRegistrationException 377 { 378 return amx; 380 } 381 } 382 383 384 385 386 387 388 389 390 | Popular Tags |