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.AdminEventListenerRegistry; 41 import com.sun.enterprise.admin.event.BaseDeployEvent; 42 import com.sun.enterprise.admin.event.DeployEventListenerHelper; 43 import com.sun.enterprise.admin.event.ModuleDeployEvent; 44 import com.sun.enterprise.admin.event.ModuleDeployEventListener; 45 import com.sun.enterprise.config.ConfigException; 46 import com.sun.enterprise.instance.EjbModulesManager; 47 48 import com.sun.enterprise.security.acl.RoleMapper; 49 import com.sun.enterprise.deployment.Application; 50 51 import com.sun.enterprise.util.i18n.StringManager; 52 import com.sun.enterprise.deployment.backend.Deployer; 53 import com.sun.enterprise.deployment.backend.DeployerFactory; 54 import com.sun.enterprise.deployment.backend.DeploymentRequest; 55 import com.sun.enterprise.deployment.backend.DeploymentCommand; 56 import com.sun.enterprise.deployment.backend.DeployableObjectType; 57 import com.sun.enterprise.deployment.backend.IASDeploymentException; 58 import com.sun.enterprise.config.ConfigContext; 59 60 import java.util.logging.Logger ; 61 import java.util.logging.Level ; 62 import com.sun.logging.LogDomains; 63 64 import com.sun.enterprise.deployment.io.ApplicationDeploymentDescriptorFile; 66 import com.sun.enterprise.deployment.io.EjbDeploymentDescriptorFile; 67 import com.sun.enterprise.deployment.node.J2EEDocumentBuilder; 68 import java.util.Iterator ; 69 import com.sun.enterprise.deployment.EjbBundleDescriptor; 70 import javax.management.MBeanException ; 71 import com.sun.enterprise.management.StateManageable; 72 import com.sun.enterprise.deployment.autodeploy.AutoDirReDeployer; 73 74 82 public class StandAloneEJBModulesManager extends AbstractManager 83 implements ModuleDeployEventListener { 84 85 86 static Logger _logger = LogDomains.getLogger(LogDomains.CORE_LOGGER); 87 88 89 private static StringManager localStrings = 90 StringManager.getManager(StandAloneEJBModulesManager.class); 91 92 105 StandAloneEJBModulesManager(EjbModulesManager ejbManager, 106 ClassLoader parentClassLoader) { 107 108 super(parentClassLoader, ejbManager); 109 110 AdminEventListenerRegistry.addModuleDeployEventListener(this); 111 } 112 113 120 protected AbstractLoader getLoader(String moduleId) { 121 return new EJBModuleLoader(moduleId, this.parentClassLoader, 122 (EjbModulesManager)this.configManager); 123 } 124 125 private void holdRequest() { } 126 127 private void holdRequest(String appID) { } 128 129 131 138 public synchronized boolean reload(MonitorableEntry entry) { 139 140 String moduleName = entry.getId(); 141 boolean status = false; 142 143 try { 145 146 DeploymentRequest req = new DeploymentRequest( 147 this.configManager.getInstanceEnvironment(), 148 DeployableObjectType.EJB, 149 DeploymentCommand.DEPLOY); 150 151 req.setFileSource(entry.getMonitoredFile().getParentFile()); 153 154 req.setName(moduleName); 156 157 req.setForced(true); 159 160 AutoDirReDeployer deployer = new AutoDirReDeployer(req); 161 status = deployer.redeploy(); 162 163 } catch (IASDeploymentException de) { 164 _logger.log(Level.WARNING,"core.error_in_reload_ejb_module",de); 165 return false; 166 } 167 return status; 168 } 169 171 private boolean moduleDeployed(boolean jsr77, String moduleName, 172 ConfigContext dynamicConfigContext) 173 { 174 return moduleDeployed(jsr77, moduleName, true, dynamicConfigContext); 175 } 176 177 private boolean moduleDeployed(boolean jsr77, String moduleName, 178 boolean addToRM, ConfigContext dynamicConfigContext) 179 { 180 boolean result = false; 181 boolean loadJSR77 = jsr77 || loadJSR77(moduleName, DeployableObjectType.EJB); 182 183 AbstractLoader modLoader = null; 184 try { 185 186 modLoader = getLoader(moduleName); 187 modLoader.setConfigContext(dynamicConfigContext); 188 189 if (loadJSR77) { 191 try { 192 modLoader.createRootMBean(); 193 } catch (MBeanException mbe) { 194 _logger.log(Level.WARNING, 195 "core.error_while_creating_jsr77_root_mbean",mbe); 196 } 197 } 198 199 if (isEnabled(dynamicConfigContext, moduleName)) { 200 201 if (_logger.isLoggable(Level.FINEST)) { 202 _logger.log(Level.FINEST, 203 "Loading enabled ejb module: " + moduleName); 204 } 205 206 if (id2loader.get(moduleName) != null) { 208 return true; 209 } 210 211 try { 213 modLoader.setState(StateManageable.STARTING_STATE); 214 } catch (MBeanException mbe) { 215 _logger.log(Level.WARNING, 216 "core.error_while_setting_jsr77_state",mbe); 217 } 218 219 boolean retSts = modLoader.load(jsr77); 220 221 if (retSts) { 222 this.id2loader.put(moduleName, modLoader); 223 224 if (addToRM) { 226 addToReloadMonitor(moduleName); 227 } 228 229 try { 231 modLoader.setState(StateManageable.RUNNING_STATE); 232 } catch (MBeanException mbe) { 233 _logger.log(Level.WARNING, 234 "core.error_while_setting_jsr77_state",mbe); 235 } 236 237 result = true; 238 } else { 239 if (loadJSR77) { 240 try { 242 modLoader.deleteLeafAndRootMBeans(); 243 } catch (MBeanException mbe) { 244 _logger.log(Level.WARNING, 245 "core.error_while_deleting_jsr77_root_and_leaf_mbeans",mbe); 246 } 247 } else { 248 try { 250 modLoader.setState(StateManageable.FAILED_STATE); 251 } catch (MBeanException mbe) { 252 _logger.log(Level.WARNING, 253 "core.error_while_setting_jsr77_state",mbe); 254 } 255 } 256 257 _logger.log(Level.WARNING, 258 "core.error_while_loading_ejb_module"); 259 } 260 } else { 261 _logger.log(Level.INFO, "core.ejb_module_disabled", moduleName); 262 result = false; 264 } 265 } catch (ConfigException ce) { 266 _logger.log(Level.WARNING,"core.error_while_loading_ejb_module",ce); 267 result = false; 268 } finally { 269 if (modLoader != null) { 271 modLoader.setConfigContext(null); 272 } 273 } 274 return result; 275 } 276 277 287 private boolean moduleUnDeployed(String moduleName) { 288 return moduleUnDeployed(false, moduleName); 289 } 290 291 302 private boolean moduleUnDeployed(boolean jsr77, String moduleName) { 303 return moduleUnDeployed(jsr77, moduleName, true); 304 } 305 306 316 private boolean moduleUnDeployed(boolean jsr77, String moduleName, boolean clearRM) { 317 318 EJBModuleLoader modLoader = 319 (EJBModuleLoader) this.id2loader.remove(moduleName); 320 321 if (clearRM) { 323 removeFromReloadMonitor(moduleName); 324 } 325 326 if (modLoader == null) { 328 return true; 329 } 330 331 try { 333 modLoader.setState(StateManageable.STOPPING_STATE); 334 } catch (MBeanException mbe) { 335 _logger.log(Level.WARNING, 336 "core.error_while_setting_jsr77_state",mbe); 337 } 338 339 Application app = modLoader.getApplication(); 340 RoleMapper.removeRoleMapper(app.getRoleMapper().getName()); 341 342 if (jsr77) { 343 try { 345 modLoader.deleteRootMBean(); 346 } catch (MBeanException mbe) { 347 _logger.log(Level.WARNING, 348 "core.error_while_deleting_jsr77_root_mbean",mbe); 349 } 350 } else { 351 try { 353 modLoader.setState(StateManageable.STOPPED_STATE); 354 } catch (MBeanException mbe) { 355 _logger.log(Level.WARNING, 356 "core.error_while_setting_jsr77_state",mbe); 357 } 358 } 359 360 boolean undeployed = modLoader.unload(jsr77); 361 362 if (undeployed) { 363 _logger.log(Level.INFO, 364 "core.ejb_module_unload_successful", moduleName); 365 } else { 366 _logger.log(Level.INFO, 367 "core.ejb_module_not_unloaded", moduleName); 368 } 369 370 return undeployed; 371 } 372 373 375 378 public synchronized void moduleDeployed(ModuleDeployEvent event) 379 throws AdminEventListenerException { 380 381 boolean jsr77 = false; 382 383 if (event.getModuleTypeCode() == event.TYPE_EJBMODULE_CODE) { 384 385 DeployEventListenerHelper.getDeployEventListenerHelper().synchronize(event); 386 387 String modID = event.getModuleName(); 388 389 if (_logger.isLoggable(Level.FINEST)) { 390 _logger.log(Level.FINEST, 391 "Deploying EJB Module: " + modID); 392 } 393 394 try { 395 this.configManager.refreshConfigContext( 397 event.getConfigContext() ); 398 399 String action = event.getAction(); 401 if ((action.equals(BaseDeployEvent.DEPLOY)) || 402 (action.equals(BaseDeployEvent.REDEPLOY))) { 403 jsr77 = true; 404 } 405 406 if (isEnabled(event.getConfigContext(), modID) && 407 !moduleDeployed(jsr77, modID, event.getConfigContext())) { 408 409 String msg = localStrings.getString( 410 "standaloneejbmodulesmgr.ejbmodule_deployed_failed", 411 modID); 412 registerException(event, msg); 413 } 414 } catch (ConfigException ce) { 415 throw new AdminEventListenerException(ce.getMessage()); 416 } 417 } 418 } 419 420 423 public synchronized void moduleUndeployed(ModuleDeployEvent event) 424 throws AdminEventListenerException { 425 426 boolean jsr77 = false; 427 428 String action = event.getAction(); 429 if ((action.equals(BaseDeployEvent.UNDEPLOY)) || 430 (action.equals(BaseDeployEvent.REDEPLOY))) { 431 jsr77 = true; 432 } 433 434 try { 435 if (event.getModuleTypeCode() == event.TYPE_EJBMODULE_CODE) { 436 437 String modID = event.getModuleName(); 438 439 if (_logger.isLoggable(Level.FINEST)) { 440 _logger.log(Level.FINEST, 441 "Undeploying EJB Module: " + modID); 442 } 443 444 this.configManager.refreshConfigContext( 446 event.getOldConfigContext() ); 447 448 boolean undeployed = moduleUnDeployed(jsr77, modID); 449 450 if (!undeployed) { 451 String msg = localStrings.getString( 452 "standaloneejbmodulesmgr.ejbmodule_undeployed_failed", 453 modID); 454 registerException(event, msg); 455 } 456 } 457 } catch (ConfigException ce) { 458 throw new AdminEventListenerException(ce.getMessage()); 459 } 460 } 461 462 465 public synchronized void moduleRedeployed(ModuleDeployEvent event) 466 throws AdminEventListenerException { 467 468 if (event.getModuleTypeCode() == event.TYPE_EJBMODULE_CODE) { 469 470 String modID = event.getModuleName(); 471 472 if (_logger.isLoggable(Level.FINEST)) { 473 _logger.log(Level.FINEST, 474 "Redeploying EJB Module: " + modID); 475 } 476 477 moduleUndeployed(event); 478 moduleDeployed(event); 479 } 480 } 481 482 485 public synchronized void moduleEnabled(ModuleDeployEvent event) 486 throws AdminEventListenerException { 487 488 if (event.getModuleTypeCode() == event.TYPE_EJBMODULE_CODE) { 489 490 String modID = event.getModuleName(); 491 492 if (!isEnabled(event.getConfigContext(), modID)) { 493 return; 494 } 495 496 if (_logger.isLoggable(Level.FINEST)) { 497 _logger.log(Level.FINEST, "Enabling EJB Module: " + modID); 498 } 499 500 moduleDeployed(event); 501 } 502 } 503 504 507 public synchronized void moduleDisabled(ModuleDeployEvent event) 508 throws AdminEventListenerException { 509 510 if (event.getModuleTypeCode() == event.TYPE_EJBMODULE_CODE) { 511 512 String modID = event.getModuleName(); 513 514 if (_logger.isLoggable(Level.FINEST)) { 515 _logger.log(Level.FINEST, 516 "Disabling EJB Module: " + modID); 517 } 518 519 moduleUndeployed(event); 520 } 521 } 522 523 524 531 public void moduleReferenceAdded(ModuleDeployEvent event) 532 throws AdminEventListenerException { 533 534 } 535 536 543 public void moduleReferenceRemoved(ModuleDeployEvent event) 544 throws AdminEventListenerException { 545 546 } 547 548 549 550 552 553 } 554 | Popular Tags |