1 23 24 37 package com.sun.enterprise.server; 38 39 import com.sun.enterprise.admin.event.AdminEventListenerException; 40 import com.sun.enterprise.admin.event.AdminEventResult; 41 import com.sun.enterprise.admin.event.BaseDeployEvent; 42 import com.sun.enterprise.admin.server.core.AdminService; 43 import com.sun.enterprise.config.ConfigBean; 44 import com.sun.enterprise.config.ConfigContext; 45 import com.sun.enterprise.config.ConfigException; 46 import com.sun.enterprise.config.serverbeans.ApplicationHelper; 47 import com.sun.enterprise.config.serverbeans.ApplicationRef; 48 import com.sun.enterprise.config.serverbeans.Server; 49 import com.sun.enterprise.config.serverbeans.ServerBeansFactory; 50 import com.sun.enterprise.deployment.Application; 51 import com.sun.enterprise.deployment.backend.DeployableObjectType; 52 import com.sun.enterprise.instance.BaseManager; 53 import com.sun.enterprise.management.StateManageable; 54 import com.sun.logging.LogDomains; 55 import java.io.File ; 56 import java.util.Hashtable ; 57 import java.util.List ; 58 import java.util.logging.Level ; 59 import java.util.logging.Logger ; 60 import java.util.Set ; 61 import javax.management.MBeanException ; 62 import javax.management.MBeanServer ; 63 import javax.management.ObjectName ; 64 65 85 public abstract class AbstractManager implements MonitorListener { 86 87 88 protected ClassLoader parentClassLoader; 89 90 91 protected ApplicationRegistry registry; 92 93 94 protected BaseManager configManager; 95 96 97 protected Hashtable id2loader; 98 99 100 protected ReloadMonitor reloadMonitor = null; 101 102 103 protected boolean systemAppsLoaded = false; 104 105 106 static Logger _logger = LogDomains.getLogger(LogDomains.CORE_LOGGER); 107 108 114 AbstractManager(ClassLoader parentClassLoader, BaseManager configMgr) 115 { 116 117 this.id2loader = new Hashtable (); 118 this.parentClassLoader = parentClassLoader; 119 this.configManager = configMgr; 120 121 this.registry = ApplicationRegistry.getInstance(); 123 124 boolean monitor = this.configManager.isDynamicReloadEnabled(); 126 if (monitor) { 127 this.reloadMonitor = ReloadMonitor.getInstance( 128 this.configManager.getReloadPollIntervalInMillis()); 129 } 130 } 131 132 137 void load() { 138 139 final ClassLoader connCL = this.parentClassLoader; 141 java.security.AccessController.doPrivileged( 142 new java.security.PrivilegedAction () { 143 public Object run() { 144 Thread.currentThread().setContextClassLoader(connCL); 145 return null; 146 } 147 } 148 ); 149 150 152 List appList = null; 154 try { 155 appList = this.configManager.listIds(); 156 } catch (ConfigException confEx) { 157 _logger.log(Level.WARNING, 158 "core.error_while_getting_deployed_applist", confEx); 159 return; 160 } 161 162 boolean jsr77 = true; 164 165 for (int i=0; i<appList.size(); i++) { 167 168 String id = (String ) appList.get(i); 170 171 try { 172 if (this.configManager.isSystem(id)) { 173 continue; 174 } 175 } catch (ConfigException confEx) { 176 _logger.log(Level.WARNING, 177 "core.error_while_loading_app", confEx); 178 } 179 180 try { 181 AbstractLoader loader = getLoader(id); 183 184 loader.createRootMBean(); 186 187 ConfigContext ctx = configManager.getConfigContext(); 189 if (isEnabled(ctx, id)) { 190 191 try { 193 loader.setState(StateManageable.STARTING_STATE); 194 } catch (MBeanException mbe) { 195 _logger.log(Level.WARNING, 196 "core.error_while_setting_jsr77_state",mbe); 197 } 198 199 203 id2loader.put(id, loader); 204 205 if (loader.load(jsr77) == true) { 207 try { 209 loader.setState(StateManageable.RUNNING_STATE); 210 } catch (MBeanException mbe) { 211 _logger.log(Level.WARNING, 212 "core.error_while_setting_jsr77_state",mbe); 213 } 214 215 } else { 216 try { 218 loader.setState(StateManageable.FAILED_STATE); 219 } catch (MBeanException mbe) { 220 _logger.log(Level.WARNING, 221 "core.error_while_setting_jsr77_state",mbe); 222 } 223 224 _logger.log(Level.WARNING, 225 "core.application_not_loaded", id); 226 } 227 addToReloadMonitor(id); 229 } else if (! isEnabled(ctx, id)) { 230 try { 233 loader.setState(StateManageable.STOPPED_STATE); 234 loader.createLeafMBeans(); 235 } catch (MBeanException mbe) { 236 _logger.log(Level.WARNING, 237 "core.error_while_setting_jsr77_state",mbe); 238 } 239 240 } 241 } catch (ConfigException confEx) { 242 _logger.log(Level.WARNING, 243 "core.error_while_loading_app", confEx); 244 } catch (Throwable t) { 245 _logger.log(Level.WARNING, 246 "core.unexpected_error_occured_while_loading_app", t); 247 } 248 } 249 } 250 255 void loadSystem() { 256 257 boolean jsr77 = true; 259 260 if(systemAppsLoaded) 261 return; 262 263 List appList = null; 265 try { 266 appList = this.configManager.listIds(); 267 } catch (ConfigException confEx) { 268 _logger.log(Level.WARNING, 269 "core.error_while_getting_deployed_applist", confEx); 270 return; 271 } 272 273 for (int i=0; i<appList.size(); i++) { 275 276 String id = (String ) appList.get(i); 278 loadOneSystemApp(id, jsr77); 279 280 } 281 systemAppsLoaded = true; 282 } 283 284 285 public void loadOneSystemApp(String id, boolean jsr77) { 286 final ClassLoader connCL = this.parentClassLoader; 288 final ClassLoader cl = (ClassLoader ) 289 java.security.AccessController.doPrivileged( 290 new java.security.PrivilegedAction () { 291 public Object run() { 292 ClassLoader cloader = Thread.currentThread().getContextClassLoader(); 293 Thread.currentThread().setContextClassLoader(connCL); 294 return cloader; 295 } 296 } 297 ); 298 299 try { 300 ConfigContext ctx = configManager.getConfigContext(); 302 if (ResourcesUtil.getInstance().belongToSystemRar(id) || 303 (this.configManager.isSystem(id) 304 && isEnabled(ctx, id))) { 305 306 AbstractLoader loader = getLoader(id); 308 309 loader.createRootMBean(); 311 312 316 id2loader.put(id, loader); 317 318 if ( ! loader.load(jsr77) ) { 320 _logger.log(Level.WARNING, 321 "core.application_not_loaded", id); 322 } 323 } 324 325 } catch (ConfigException confEx) { 326 _logger.log(Level.SEVERE, 327 "core.error_while_loading_system_app", confEx); 328 } catch (Throwable t) { 329 _logger.log(Level.SEVERE, 330 "core.unexpected_error_occured_while_loading_system_app", t); 331 } 332 333 if (cl != connCL) { 334 java.security.AccessController.doPrivileged( 335 new java.security.PrivilegedAction () { 336 public Object run() { 337 Thread.currentThread().setContextClassLoader(cl); 338 return null; 339 } 340 } 341 ); 342 } 343 344 } 345 346 347 351 void shutdown() { 352 353 try { 354 if (this.reloadMonitor != null) { 356 this.reloadMonitor.stop(); 357 } 358 } catch (Throwable t) { 359 _logger.log(Level.WARNING, 360 "core.unexpected_error_occured_while_app_shutdown", t); 361 } 362 } 363 364 371 protected void addToReloadMonitor(String id) throws ConfigException { 372 373 if (this.reloadMonitor != null && !(this.configManager.isSystem(id))) { 375 String mPath = this.configManager.getLocation(id) 376 + File.separator + ReloadMonitor.RELOAD_FILE; 377 MonitorableEntry entry = 378 new MonitorableEntry(id, new File (mPath), this); 379 this.reloadMonitor.addMonitorableEntry(entry); 380 } 381 } 382 383 388 protected void removeFromReloadMonitor(String id) { 389 395 400 } 401 402 404 412 public boolean reload(MonitorableEntry entry) { 413 return false; 414 } 415 416 425 public boolean deploy(MonitorableEntry entry, File archive) { 426 return false; 427 } 428 429 431 438 protected abstract AbstractLoader getLoader(String id); 439 440 445 ClassLoader getParentClassLoader() { 446 return this.parentClassLoader; 447 } 448 449 454 public boolean isRegistered(String id) { 455 return this.configManager.isRegistered(id); 456 } 457 458 461 protected boolean loadJSR77(String appName, DeployableObjectType type) { 462 ObjectName jsr77mBeanObjectName = null; 463 try { 464 String domainName = null; 465 AdminService adminService = AdminService.getAdminService(); 466 if (adminService != null) { 467 domainName = adminService.getAdminContext().getDomainName(); 468 } else { 469 return false; 470 } 471 472 String j2eeType = null; 475 if (type.isAPP()) { 476 j2eeType = "J2EEApplication"; 477 } else if (type.isEJB()) { 478 j2eeType = "EJBModule"; 479 } else if (type.isCONN()) { 480 j2eeType = "ResourceAdapterModule"; 481 } else if (type.isCAR()) { 482 j2eeType = "AppClientModule"; 483 } else if (type.isWEB()) { 484 return false; 485 } 486 487 String instanceName = 488 ApplicationServer.getServerContext().getInstanceName(); 489 490 StringBuffer sb = new StringBuffer (""); 492 sb.append(domainName + ":"); 493 sb.append("j2eeType=" + j2eeType + ","); 494 sb.append("name=" + appName + ","); 495 if (!type.isAPP()) { 496 sb.append("J2EEApplication=null" + ","); 497 } 498 sb.append("J2EEServer=" + instanceName + "," + "*"); 499 500 MBeanServer mbs = adminService.getAdminContext().getMBeanServer(); 502 503 ObjectName objNamePattern = new ObjectName (sb.toString()); 504 java.util.Set s = mbs.queryNames(objNamePattern, null); 505 if (s != null && s.size()>0) { 506 ObjectName [] objNameArr = 507 (ObjectName []) s.toArray( new ObjectName [s.size()]); 508 if (objNameArr.length>0) { 509 jsr77mBeanObjectName = objNameArr[0]; 510 } 511 } 512 } catch (Exception ex) { 513 } 515 516 return jsr77mBeanObjectName == null; 517 } 518 519 528 protected boolean isEnabled (ConfigContext config, String moduleName) { 529 try { 530 ConfigBean app = ApplicationHelper.findApplication(config, moduleName); 531 532 Server server = ServerBeansFactory.getServerBean(config); 533 ApplicationRef appRef = server.getApplicationRefByRef(moduleName); 534 535 return ((app != null && app.isEnabled()) && 536 (appRef != null && appRef.isEnabled())); 537 } catch (ConfigException e) { 538 AdminEventListenerException ex = new AdminEventListenerException(); 539 ex.initCause(e); 540 _logger.log(Level.FINE, "Error in finding " + moduleName, e); 541 542 return false; 544 } 545 } 546 547 protected void registerException(BaseDeployEvent event, String msg) { 548 AdminEventResult result = AdminEventResult.getAdminEventResult(event); 549 result.setResultCode(AdminEventResult.SUCCESS); 550 result.addException(event.getEffectiveDestination(), 551 new AdminEventListenerException(msg)); 552 } 553 } 554 | Popular Tags |