1 23 24 package com.sun.enterprise.server; 25 26 import com.sun.enterprise.admin.event.AdminEventListenerException; 27 import com.sun.enterprise.admin.event.AdminEventListenerRegistry; 28 import com.sun.enterprise.admin.event.BaseDeployEvent; 29 import com.sun.enterprise.admin.event.DeployEventListenerHelper; 30 import com.sun.enterprise.admin.event.ModuleDeployEvent; 31 import com.sun.enterprise.admin.event.ModuleDeployEventListener; 32 import com.sun.enterprise.config.ConfigContext; 33 import com.sun.enterprise.config.ConfigException; 34 import com.sun.enterprise.deployment.backend.DeployableObjectType; 35 import com.sun.enterprise.instance.ConnectorModulesManager; 36 import com.sun.enterprise.management.StateManageable; 37 import com.sun.enterprise.util.i18n.StringManager; 38 import com.sun.logging.LogDomains; 39 import java.util.logging.Level ; 40 import java.util.logging.Logger ; 41 import javax.management.MBeanException ; 42 43 44 50 public class StandAloneConnectorModulesManager extends AbstractManager 51 implements ModuleDeployEventListener { 52 55 58 static Logger _logger = LogDomains.getLogger(LogDomains.CORE_LOGGER); 59 private static StringManager localStrings = StringManager.getManager( 60 "com.sun.enterprise.server"); 61 62 69 StandAloneConnectorModulesManager( 70 ConnectorModulesManager connectorManager, ClassLoader parentClassLoader) { 71 super(parentClassLoader, connectorManager); 73 AdminEventListenerRegistry.addModuleDeployEventListener(this); 74 } 75 76 protected AbstractLoader getLoader(String moduleId) { 77 return new ConnectorModuleLoader(moduleId, this.parentClassLoader, 78 (ConnectorModulesManager) this.configManager); 79 } 80 81 82 91 private boolean moduleDeployed( 92 boolean jsr77, ConfigContext config, String moduleName) 93 throws AdminEventListenerException { 94 95 boolean result = false; 96 boolean loadJSR77 = jsr77 || loadJSR77(moduleName, DeployableObjectType.CONN); 97 98 if (_logger.isLoggable(Level.FINEST)) { 99 _logger.log(Level.FINEST, 100 "In connector moduleDeployed event,name=" + moduleName); 101 } 102 103 AbstractLoader modLoader = getLoader(moduleName); 104 _logger.log(Level.FINEST, "After get loader"); 105 106 if (loadJSR77) { 108 try { 109 modLoader.createRootMBean(); 110 } catch (MBeanException mbe) { 111 _logger.log(Level.WARNING, 112 "core.error_while_creating_jsr77_root_mbean",mbe); 113 throw new AdminEventListenerException(mbe.getMessage()); 114 } 115 } 116 117 if (isEnabled(config, moduleName)) { 118 if (_logger.isLoggable(Level.FINEST)) { 119 _logger.log(Level.FINEST, 120 "Loading enabled moduleName: " + moduleName); 121 } 122 123 try { 125 modLoader.setState(StateManageable.STARTING_STATE); 126 } catch (MBeanException mbe) { 127 _logger.log(Level.WARNING, 128 "core.error_while_setting_jsr77_state",mbe); 129 } 130 131 boolean retSts = modLoader.load(jsr77); 132 133 if (retSts) { 134 this.id2loader.put(moduleName, modLoader); 135 136 try { 138 modLoader.setState(StateManageable.RUNNING_STATE); 139 } catch (MBeanException mbe) { 140 _logger.log(Level.WARNING, 141 "core.error_while_setting_jsr77_state",mbe); 142 } 143 144 result = true; 145 146 if (_logger.isLoggable(Level.FINE)) { 147 _logger.log(Level.FINE, 148 "Successfully loaded moduleName: " + moduleName); 149 } 150 } else { 151 _logger.log(Level.WARNING, 152 "core.error_while_loading_connector_module" + " " + 153 moduleName); 154 155 try { 157 if (loadJSR77) { 158 modLoader.deleteLeafAndRootMBeans(); 159 } 160 } catch (MBeanException mbe) { 161 _logger.log(Level.WARNING, 162 "core.error_while_deleting_jsr77_leaf_and_root_mbeans",mbe); 163 throw new AdminEventListenerException(mbe.getMessage()); 164 } 165 166 try { 168 modLoader.setState(StateManageable.FAILED_STATE); 169 } catch (MBeanException mbe) { 170 _logger.log(Level.WARNING, 171 "core.error_while_setting_jsr77_state",mbe); 172 } 173 174 String msg = localStrings.getString( 175 "connector.error_while_loading_connector_module", moduleName); 176 throw new AdminEventListenerException(msg); 177 } 178 } else { 179 result = false; 181 } 182 return result; 183 } 184 185 194 private boolean moduleUndeployed(boolean jsr77, String moduleName, boolean cascade) { 195 196 if (_logger.isLoggable(Level.FINEST)) { 197 _logger.log(Level.FINEST, 198 "In connector moduleUndeployed event,name=" + moduleName); 199 } 200 201 AbstractLoader modLoader = (ConnectorModuleLoader) this.id2loader.remove(moduleName); 203 204 if (modLoader == null) { 205 return true; 206 } 207 modLoader.setCascade(cascade); 208 209 try { 211 modLoader.setState(StateManageable.STOPPING_STATE); 212 } catch (MBeanException mbe) { 213 _logger.log(Level.WARNING, 214 "core.error_while_setting_jsr77_state",mbe); 215 } 216 217 boolean undeployed = modLoader.unload(jsr77); 218 219 if (undeployed) { 220 if (jsr77) { 221 try { 223 modLoader.deleteRootMBean(); 224 } catch (MBeanException mbe) { 225 _logger.log(Level.WARNING, 226 "core.error_while_deleting_jsr77_root_mbean",mbe); 227 } 228 } else { 229 try { 231 modLoader.setState(StateManageable.STOPPED_STATE); 232 } catch (MBeanException mbe) { 233 _logger.log(Level.WARNING, 234 "core.error_while_setting_jsr77_state",mbe); 235 } 236 } 237 } 238 239 return undeployed; 240 } 241 242 245 public synchronized void moduleDeployed(ModuleDeployEvent event) 246 throws AdminEventListenerException { 247 248 if (event.getModuleType().equals(event.TYPE_CONNECTOR)) { 249 DeployEventListenerHelper.getDeployEventListenerHelper().synchronize(event); 250 } 251 252 if(event.getForceDeploy() ) { 253 moduleEnabled(event); 254 return; 255 } else { 256 try { 260 ConnectorResourcesLoader connectorResourcesLoader = null; 261 ServerContext sc = ApplicationServer.getServerContext(); 262 connectorResourcesLoader= new ConnectorResourcesLoader(sc); 263 connectorResourcesLoader.loadRAConfigs(event.getModuleName()); 264 } catch (ConfigException e) { 265 _logger.log(Level.WARNING, "" + e.getMessage()); 266 AdminEventListenerException aele = new AdminEventListenerException(); 267 aele.initCause(e); 268 throw aele; 269 } 270 271 realDeployed(event); 272 } 273 } 274 275 280 private void realDeployed(ModuleDeployEvent event) throws AdminEventListenerException { 281 boolean jsr77 = false; 282 283 284 if (_logger.isLoggable(Level.FINEST)) { 285 _logger.log(Level.FINEST, 286 "In StandAloneConnectorModulesManager moduleDeployed"); 287 _logger.log(Level.FINEST, "ModuleType=" + event.getModuleType()); 288 } 289 290 if (event.getModuleType().equals(event.TYPE_CONNECTOR)) { 291 String modID = event.getModuleName(); 292 293 if (_logger.isLoggable(Level.FINEST)) { 294 _logger.log(Level.FINEST, "modID=" + modID); 295 } 296 297 try { 298 this.configManager.refreshConfigContext(event.getConfigContext()); 300 301 String action = event.getAction(); 305 if ((action.equals(BaseDeployEvent.DEPLOY)) || 306 (action.equals(BaseDeployEvent.REDEPLOY))) { 307 jsr77 = true; 308 } 309 310 if (isEnabled(event.getConfigContext(), modID) && 311 !moduleDeployed(jsr77, event.getConfigContext(), modID)) { 312 String msg = localStrings.getString("connector.connector_deployed_failed", 314 modID); 315 throw new AdminEventListenerException(msg); 316 } 317 } catch (ConfigException ce) { 318 throw new AdminEventListenerException(ce.getMessage()); 319 } 320 } 321 } 322 323 326 public synchronized void moduleUndeployed(ModuleDeployEvent event) 327 throws AdminEventListenerException { 328 if(event.getForceDeploy() ) { 330 try { 331 moduleDisabled(event); 332 } catch (AdminEventListenerException aele) { 333 _logger.log(Level.FINEST, "Error while UnDeploying module: " + event.getModuleName()); 334 throw aele; 335 } 336 } else { 337 realUndeployed(event); 338 } 339 } 340 341 346 private void realUndeployed(ModuleDeployEvent event) throws AdminEventListenerException { 347 boolean jsr77 = false; 348 349 if (_logger.isLoggable(Level.FINEST)) { 350 _logger.log(Level.FINEST, 351 "In StandAloneConnectorModulesManager moduleUndeployed"); 352 } 353 354 String action = event.getAction(); 355 356 if ((action.equals(BaseDeployEvent.UNDEPLOY)) || 357 (action.equals(BaseDeployEvent.REDEPLOY))) { 358 jsr77 = true; 359 } 360 361 try { 362 if (event.getModuleType().equals(event.TYPE_CONNECTOR)) { 363 String modID = event.getModuleName(); 364 365 if (_logger.isLoggable(Level.FINEST)) { 366 _logger.log(Level.FINEST, "UnDeploying module: " + modID); 367 } 368 369 boolean undeployed = false; 370 try { 371 ResourcesUtil.getInstance().setConfigContext(event.getConfigContext()); 372 ResourcesUtil.getInstance().setReinitConfigContext(false); 373 undeployed = moduleUndeployed(jsr77, modID, event.getCascade()); 374 } finally { 375 ResourcesUtil.getInstance().setReinitConfigContext(true); 376 } 377 378 if (!undeployed) { 379 String msg = localStrings.getString("connector.connector_undeployed_failed", 380 modID); 381 throw new AdminEventListenerException(msg); 382 } 383 384 this.configManager.refreshConfigContext(event.getConfigContext()); 386 } 387 } catch (ConfigException ce) { 388 throw new AdminEventListenerException(ce.getMessage()); 389 } 390 } 391 392 395 public synchronized void moduleRedeployed(ModuleDeployEvent event) 396 throws AdminEventListenerException { 397 if (event.getModuleType().equals(event.TYPE_CONNECTOR)) { 398 String modID = event.getModuleName(); 399 400 if (_logger.isLoggable(Level.FINEST)) { 401 _logger.log(Level.FINEST, "ReDeploying module: " + modID); 402 } 403 404 moduleUndeployed(event); 405 moduleDeployed(event); 406 } 407 } 408 409 412 public synchronized void moduleEnabled(ModuleDeployEvent event) 413 throws AdminEventListenerException { 414 if (_logger.isLoggable(Level.FINEST)) { 415 _logger.log(Level.FINEST, 416 "In StandAloneConnectorModulesManager moduleEnabled"); 417 } 418 419 if (event.getModuleType().equals(event.TYPE_CONNECTOR)) { 420 String modID = event.getModuleName(); 421 422 if (!isEnabled(event.getConfigContext(), event.getModuleName())) { 423 return; 424 } 425 426 if (_logger.isLoggable(Level.FINEST)) { 427 _logger.log(Level.FINEST, "Module : " + modID + " enabled..."); 428 } 429 String appName = event.getModuleName(); 430 ServerContext sc = ApplicationServer.getServerContext(); 431 ConnectorResourcesLoader connectorResourcesLoader = null; 432 try { 433 connectorResourcesLoader= 434 new ConnectorResourcesLoader(sc); 435 }catch(ConfigException ce) { 436 String msg = localStrings.getString( 437 "connector.connector_enable_failed",appName); 438 _logger.log(Level.SEVERE, 439 "core.failed_to_get_connectorresourcesloader"); 440 throw new AdminEventListenerException(msg); 441 } 442 ResourcesUtil resutil = ResourcesUtil.getInstance(); 443 resutil.setConfigContext(event.getConfigContext()); 444 resutil.setReinitConfigContext(false); 445 446 try { 447 connectorResourcesLoader.loadRAConfigs(appName); 448 realDeployed(event); 449 connectorResourcesLoader.load(appName); 450 } catch(AdminEventListenerException ex) { 451 throw ex; 452 } catch(Throwable th) { 453 AdminEventListenerException aele = 454 new AdminEventListenerException(); 455 aele.initCause(th); 456 throw aele; 457 }finally { 458 resutil.setReinitConfigContext(true); 459 } 460 } 461 } 462 463 466 public synchronized void moduleDisabled(ModuleDeployEvent event) 467 throws AdminEventListenerException { 468 if (_logger.isLoggable(Level.FINEST)) { 469 _logger.log(Level.FINEST, 470 "In StandAloneConnectorModulesManager moduleDisabled"); 471 } 472 473 if (event.getModuleType().equals(event.TYPE_CONNECTOR)) { 474 String modID = event.getModuleName(); 475 476 if (_logger.isLoggable(Level.FINEST)) { 477 _logger.log(Level.FINEST, "Module : " + modID + " disabled..."); 478 } 479 480 AbstractLoader modLoader = 481 (ConnectorModuleLoader) this.id2loader.get(modID); 482 event.setCascade(true); 483 realUndeployed(event); 484 } 485 } 486 487 488 495 public void moduleReferenceAdded(ModuleDeployEvent event) 496 throws AdminEventListenerException { 497 498 } 499 500 507 public void moduleReferenceRemoved(ModuleDeployEvent event) 508 throws AdminEventListenerException { 509 510 } 511 512 513 } 515 516 517 | Popular Tags |