1 23 package com.sun.enterprise.server; 24 25 import java.io.File ; 26 import java.util.ArrayList ; 27 import java.io.IOException ; 28 29 import com.sun.enterprise.Switch; 30 import com.sun.enterprise.server.J2EEServer; 31 import com.sun.enterprise.security.audit.AuditModuleEventListenerImpl; 32 import com.sun.enterprise.security.audit.SecurityServiceEventListenerImpl; 33 import com.sun.enterprise.security.auth.realm.AuthRealmEventListenerImpl; 34 import com.sun.enterprise.security.auth.realm.UserMgmtEventListenerImpl; 35 36 import com.sun.enterprise.config.serverbeans.ServerBeansFactory; 37 import com.sun.enterprise.config.serverbeans.TransactionService; 38 import com.sun.enterprise.config.serverbeans.Applications; 39 import com.sun.enterprise.config.serverbeans.ServerXPathHelper; 40 import com.sun.enterprise.config.ConfigBeansFactory; 41 import com.sun.enterprise.config.ConfigContext; 42 import com.sun.enterprise.config.ConfigException; 43 44 import com.sun.enterprise.instance.InstanceFactory; 45 import com.sun.enterprise.instance.InstanceEnvironment; 46 import com.sun.enterprise.instance.AppsManager; 47 import com.sun.enterprise.instance.EjbModulesManager; 48 import com.sun.enterprise.instance.ConnectorModulesManager; 49 import com.sun.enterprise.loader.ClassLoaderUtils; 50 import com.sun.enterprise.util.logging.Debug; 51 52 import com.sun.enterprise.util.ConnectorClassLoader; 53 import com.sun.enterprise.resource.ResourceInstaller; 54 55 import com.sun.appserv.server.ServerLifecycle; 56 import com.sun.appserv.server.ServerLifecycleException; 57 58 import com.sun.enterprise.server.pluggable.InternalServicesList; 59 60 import com.sun.enterprise.admin.event.AdminEventListenerRegistry; 61 import com.sun.enterprise.admin.event.jms.JmsServiceEvent; 62 import com.sun.enterprise.admin.event.jms.JmsHostEvent; 63 import com.sun.enterprise.admin.alert.AlertConfigurator; 64 66 70 import java.util.logging.Level ; 71 import java.util.logging.Logger ; 72 import com.sun.logging.LogDomains; 73 import com.sun.enterprise.server.logging.ServerLogManager; 74 75 82 public class ApplicationServer { 83 84 85 static Logger _logger = LogDomains.getLogger(LogDomains.CORE_LOGGER); 86 87 public static java.io.PrintStream ostream = System.out; 88 public static java.io.PrintStream estream = System.err; 89 90 private static final String USER_TX = "java:comp/UserTransaction"; 91 private static final String CODEBASE_PROP = "java.rmi.server.codebase"; 92 93 99 static String [][]servicesByName; 100 101 102 103 private static ServerContext context = null; 104 105 106 private ArrayList services = new ArrayList (); 107 108 109 private ClassLoader commonClassLoader; 110 111 112 private ClassLoader connectorClassLoader; 113 114 117 public ApplicationServer() {} 118 119 132 public void onInitialization(ServerContext context) 133 throws ServerLifecycleException 134 { 135 this.context = context; 137 138 143 ServerLogManager.reInitializeServerLoggers(); 144 145 printStartupInfo(); 147 148 ClassLoader parentOfCommonCL = this.getClass().getClassLoader(); 150 if(Boolean.getBoolean(com.sun.enterprise.server.PELaunch.USE_NEW_CLASSLOADER_PROPERTY)) 154 parentOfCommonCL = PELaunch.getSharedChain(); 155 156 InstanceEnvironment env = this.context.getInstanceEnvironment(); 157 158 try { 159 160 String dir = env.getLibClassesPath(); 161 String jarDir = env.getLibPath(); 162 163 commonClassLoader = 168 ClassLoaderUtils.getClassLoader(new File [] {new File (dir)}, 169 new File [] {new File (jarDir)}, 170 parentOfCommonCL 171 ); 172 173 if (commonClassLoader == null) { 175 commonClassLoader = parentOfCommonCL; 176 } 177 } catch (IOException ioe) { 178 _logger.log(Level.WARNING, "server.ioexception", ioe); 179 commonClassLoader = parentOfCommonCL; 180 } catch (Throwable th) { 181 _logger.log(Level.WARNING, "server.exception", th); 182 commonClassLoader = parentOfCommonCL; 183 } 184 185 connectorClassLoader = 189 ConnectorClassLoader.getInstance(commonClassLoader); 190 191 if (this.context instanceof ServerContextImpl) { 193 ServerContextImpl contextImpl = (ServerContextImpl) this.context; 194 195 contextImpl.setCommonClassLoader(commonClassLoader); 197 198 contextImpl.setSharedClassLoader(connectorClassLoader); 200 201 contextImpl.setLifecycleParentClassLoader(connectorClassLoader); 203 } 204 205 final ClassLoader commonCL = commonClassLoader; 207 208 java.security.AccessController.doPrivileged( 210 new java.security.PrivilegedAction () { 211 public Object run() { 212 Thread.currentThread().setContextClassLoader(commonCL); 213 return null; 214 } 215 } 216 ); 217 218 InternalServicesList servicesList = 220 context.getPluggableFeatureFactory().getInternalServicesList(); 221 222 servicesByName = servicesList.getServicesByName(); 223 if (servicesByName == null) { 224 _logger.log(Level.SEVERE, "services.null"); 225 throw new ServerLifecycleException(); 226 } 227 228 230 services = instantiateRuntimeServices(); 232 233 for (int i = 0; i < services.size(); i++) { 235 Object service = services.get(i); 236 if (service instanceof ServerLifecycle) { 237 try { 238 ((ServerLifecycle) service).onInitialization(context); 239 } catch (ServerLifecycleException e) { 240 _logger.log(Level.SEVERE, "service.notinit", 241 new Object [] {service, e.toString()}); 242 throw e; 243 } 244 } 245 } 246 247 AdminEventListenerRegistry.addAuditModuleEventListener( 249 new AuditModuleEventListenerImpl()); 250 AdminEventListenerRegistry.addAuthRealmEventListener( 251 new AuthRealmEventListenerImpl()); 252 AdminEventListenerRegistry.addSecurityServiceEventListener( 253 new SecurityServiceEventListenerImpl()); 254 AdminEventListenerRegistry.addUserMgmtEventListener( 255 new UserMgmtEventListenerImpl()); 256 257 try { 260 J2EEServer.main(context); 261 } catch (Exception e) { 262 throw new ServerLifecycleException(e); 263 } 264 265 final ClassLoader connCL = connectorClassLoader; 267 268 java.security.AccessController.doPrivileged( 270 new java.security.PrivilegedAction () { 271 public Object run() { 272 Thread.currentThread(). 273 setContextClassLoader(connCL); 274 return null; 275 } 276 } 277 ); 278 279 } 280 281 284 protected ArrayList instantiateRuntimeServices() throws ServerLifecycleException{ 285 286 ArrayList serviceList = new ArrayList (); 287 288 for (int i=0; i < servicesByName.length; i++) { 290 try { 291 String [] def = servicesByName[i]; 292 Class c = Class.forName(def[1]); 293 Object o = c.newInstance(); 294 295 serviceList.add(o); 296 } catch (Exception ex) { 297 _logger.log(Level.SEVERE, "server.exception", ex); 298 throw new ServerLifecycleException(ex.getMessage()); 299 } 300 301 } 302 return serviceList; 303 } 304 305 318 public void onStartup() throws ServerLifecycleException 319 { 320 for (int i = 0; i < services.size(); i++) { 322 Object service = services.get(i); 323 324 if (service instanceof ServerLifecycle) { 325 try { 326 ((ServerLifecycle) service).onStartup(context); 327 } catch (ServerLifecycleException e) { 328 _logger.log(Level.SEVERE, "service.notstarted", 329 new Object [] {service, e.toString()}); 330 throw e; 331 } 332 } 333 } 334 AlertConfigurator.getAlertConfigurator( ).configure( ); 336 } 337 338 345 public void onReady() throws ServerLifecycleException { 346 347 try { 348 AdminEventListenerRegistry.addResourceDeployEventListener( 351 new ResourceManager(context)); 352 AdminEventListenerRegistry.addEventListener(JmsServiceEvent.eventType, 354 new JmsServiceEventListener()); 355 AdminEventListenerRegistry.addEventListener(JmsHostEvent.eventType, 356 new JmsHostEventListener()); 357 358 java.security.AccessController.doPrivileged( 361 new java.security.PrivilegedAction () { 362 public Object run() { 363 Thread.currentThread().setContextClassLoader 364 (commonClassLoader); 365 return null; 366 } 367 } 368 ); 369 370 383 String startupHook = null; 384 385 startupHook = System.getProperty( 386 "com.sun.enterprise.server.startupHook"); 387 if (startupHook != null) { 388 try { 389 Class hookClass = Class.forName(startupHook); 391 java.lang.reflect.Method hookMethod = 392 hookClass.getMethod("main", 393 new Class [] { ServerContext.class }); 394 hookMethod.invoke(null, new Object [] { context }); 395 } 396 catch (Exception ex) { 397 if (Debug.enabled) { 398 _logger.log(Level.FINE, "server.exception", ex); 399 } 400 } 401 } 402 403 } catch (Exception ee) { 404 throw new ServerLifecycleException(ee); 405 } 406 407 408 for (int i = 0; i < services.size(); i++) { 410 Object service = services.get(i); 411 412 if (service instanceof ServerLifecycle) { 413 try { 414 ((ServerLifecycle) service).onReady(context); 415 } catch (ServerLifecycleException e) { 416 _logger.log(Level.SEVERE, "service.notready", 417 new Object [] {service, e.toString()}); 418 } 419 } 420 } 421 } 422 423 429 public void onShutdown() throws ServerLifecycleException 430 { 431 432 for (int i = services.size(); i > 0; i--) { 434 Object service = services.get(i-1); 435 436 _logger.log(Level.FINE,"service.shutdown", 437 services.get(i-1)); 438 try { 439 if (service instanceof ServerLifecycle) { 440 ((ServerLifecycle) service).onShutdown(); 441 } 442 } catch (Exception e) { 443 _logger.log(Level.WARNING, "server.exception", e); 446 } 447 } 448 } 449 450 459 public void onTermination() throws ServerLifecycleException 460 { 461 if (_logger.isLoggable( Level.FINE ) ) { 463 _logger.log(Level.FINE, "Killing all pools in the appserver"); 464 } 465 try { 466 Switch.getSwitch().getPoolManager().killAllPools(); 467 } catch( Throwable t ) { 468 if (_logger.isLoggable( Level.FINE ) ) { 469 _logger.log(Level.FINE, "exception : " +t); 470 } 471 } 472 for (int i = services.size(); i > 0; i--) { 474 Object service = services.get(i-1); 475 476 _logger.log(Level.FINE,"service.shutdown", 477 services.get(i-1)); 478 try { 479 if (service instanceof ServerLifecycle) { 480 ((ServerLifecycle) service).onTermination(); 481 } 482 } catch (Exception e) { 483 _logger.log(Level.WARNING, "server.exception", e); 486 } 487 } 488 489 services = null; 490 } 491 492 498 public static ServerContext getServerContext() { 499 return context; 500 } 501 502 protected void setServerContext(ServerContext context) { 504 this.context = context; 505 } 506 507 private void printStartupInfo() { 508 _logger.log(Level.INFO, "j2eerunner.printstartinfo", 509 new Object [] { 510 System.getProperty("java.vm.name"), 511 System.getProperty("java.version"), 512 System.getProperty("java.vm.vendor") }); 513 } 514 } 515 | Popular Tags |