1 23 24 29 30 package com.sun.ejb.base.sfsb.util; 31 32 import java.util.logging.Logger ; 33 import java.util.Properties ; 34 import com.sun.logging.LogDomains; 35 36 import com.sun.enterprise.config.ConfigContext; 37 import com.sun.enterprise.config.ConfigException; 38 39 import com.sun.enterprise.config.serverbeans.Applications; 40 import com.sun.enterprise.config.serverbeans.AvailabilityService; 41 import com.sun.enterprise.config.serverbeans.Cluster; 42 import com.sun.enterprise.config.serverbeans.ClusterHelper; 43 import com.sun.enterprise.config.serverbeans.Config; 44 import com.sun.enterprise.config.serverbeans.Domain; 45 import com.sun.enterprise.config.serverbeans.EjbContainerAvailability; 46 import com.sun.enterprise.config.serverbeans.EjbModule; 47 import com.sun.enterprise.config.serverbeans.J2eeApplication; 48 import com.sun.enterprise.config.serverbeans.Server; 49 import com.sun.enterprise.config.serverbeans.ServerHelper; 50 import com.sun.enterprise.config.serverbeans.ServerBeansFactory; 51 52 import com.sun.enterprise.deployment.Application; 53 import com.sun.enterprise.deployment.EjbDescriptor; 54 import com.sun.enterprise.deployment.runtime.IASEjbExtraDescriptors; 55 56 import com.sun.enterprise.server.ApplicationServer; 57 import com.sun.enterprise.server.ServerContext; 58 59 63 public class EJBServerConfigLookup { 64 65 69 protected final String DEFAULT_STORE_POOL_JNDI_NAME = "jdbc/hastore"; 70 71 75 protected final String DEFAULT_SFSB_HA_PERSISTENCE_TYPE = "file"; 76 77 81 protected final String DEFAULT_SFSB_NON_HA_PERSISTENCE_TYPE = "file"; 82 83 86 protected EjbDescriptor _ejbDescriptor = null; 87 protected boolean _haEnabled = false; 88 89 94 protected ConfigContext _configContext = null; 95 96 97 public EJBServerConfigLookup() { 98 if (_logger == null) { 99 _logger = LogDomains.getLogger(LogDomains.EJB_LOGGER); 100 } 101 } 102 103 104 public EJBServerConfigLookup(EjbDescriptor ejbDescriptor) { 105 this(); 106 _ejbDescriptor = ejbDescriptor; 107 } 108 109 110 public EJBServerConfigLookup(EjbDescriptor ejbDescriptor, ConfigContext configContext) { 111 this(ejbDescriptor); 112 _configContext = configContext; 113 } 114 115 118 protected static boolean _isDebugMonitoringEnabled = false; 119 120 static 121 { 122 _isDebugMonitoringEnabled = checkDebugMonitoringEnabled(); 123 } 124 125 129 public static boolean isMonitoringEnabled() { 130 return isDebugMonitoringEnabled(); 132 } 133 134 137 public static boolean isDebugMonitoringEnabled() { 138 return _isDebugMonitoringEnabled; 139 } 140 141 145 public boolean getAvailabilityEnabledFromConfig() { 146 _logger.finest("in EJBServerConfigLookup>>getAvailabilityEnabledFromConfig"); 147 AvailabilityService as = this.getAvailabilityService(); 148 if(as == null) { 149 _logger.fine("AvailabilityService was not defined - check domain.xml"); 150 return false; 151 } 152 return as.isAvailabilityEnabled(); 153 } 154 155 159 protected AvailabilityService getAvailabilityService() { 160 Config configBean = this.getConfigBean(); 161 if(configBean == null) { 162 return null; 163 } 164 return configBean.getAvailabilityService(); 165 } 166 167 171 protected ServerContext getServerContext() { 172 return ApplicationServer.getServerContext(); 173 } 174 175 179 protected ConfigContext getConfigContext() { 180 ServerContext serverCtx = this.getServerContext(); 181 if(serverCtx == null) { 182 return null; 183 } 184 return serverCtx.getConfigContext(); 185 } 186 187 191 protected ConfigContext getConfigContextDynamic() { 192 if (_configContext != null) { 193 return _configContext; 194 } else { 195 return getConfigContext(); 196 } 197 } 198 199 203 private Config getConfigBean() { 204 Config configBean = null; 205 ServerContext serverCtx = ApplicationServer.getServerContext(); 206 ConfigContext configCtx = serverCtx.getConfigContext(); 207 try { 208 configBean = ServerBeansFactory.getConfigBean(configCtx); 209 } catch (ConfigException ex) {} 210 211 return configBean; 212 } 213 214 218 private Applications getApplicationsBean() { 219 Applications applicationsBean = null; 220 Domain domainBean = null; 221 225 ConfigContext configCtx = this.getConfigContext(); 226 try { 227 domainBean = ServerBeansFactory.getDomainBean(configCtx); 228 if(domainBean != null) { 229 applicationsBean = domainBean.getApplications(); 230 } 231 } catch (ConfigException ex) {} 232 233 return applicationsBean; 234 } 235 236 240 private Applications getApplicationsBeanDynamic() { 241 Applications applicationsBean = null; 242 Domain domainBean = null; 243 ConfigContext configCtx = this.getConfigContextDynamic(); 244 try { 245 domainBean = ServerBeansFactory.getDomainBean(configCtx); 246 if(domainBean != null) { 247 applicationsBean = domainBean.getApplications(); 248 } 249 } catch (ConfigException ex) {} 250 251 return applicationsBean; 252 } 253 254 258 private Server getServerBean() { 259 Server serverBean = null; 260 264 ConfigContext configCtx = this.getConfigContext(); 265 try { 266 serverBean = ServerBeansFactory.getServerBean(configCtx); 267 } catch (ConfigException ex) {} 268 269 return serverBean; 270 } 271 272 276 private String getServerName() { 277 String result = null; 278 Server serverBean = this.getServerBean(); 279 if(serverBean != null) { 280 result = serverBean.getName(); 281 } 282 return result; 283 } 284 285 289 public String getClusterName() { 290 String result = null; 291 295 ConfigContext configCtx = this.getConfigContext(); 296 297 String serverName = this.getServerName(); 298 if(serverName == null) { 299 return result; 300 } 301 boolean isClustered = false; 302 try { 303 isClustered = ServerHelper.isServerClustered(configCtx, serverName); 304 } catch (ConfigException ex) {} 305 if(!isClustered) { 306 result = serverName + "_nc"; return result; 308 } 309 Cluster cluster = null; 310 try { 311 cluster = ClusterHelper.getClusterForInstance(configCtx, serverName); 312 } catch (ConfigException ex) {} 313 if(cluster != null) { 314 result = cluster.getName(); 315 } 316 return result; 317 } 318 319 329 public boolean calculateEjbAvailabilityEnabledFromConfig() { 330 _logger.finest("in EJBServerConfigLookup>>calculateEjbAvailabilityEnabledFromConfig"); 331 boolean isVirtual = this.isVirtualApplication(); 332 String appName = this.getApplicationName(); 333 334 boolean globalAvailability = 335 this.getAvailabilityEnabledFromConfig(); 336 boolean ejbContainerAvailability = 337 this.getEjbContainerAvailabilityEnabledFromConfig(globalAvailability); 338 boolean ejbDescriptorAvailability = true; 339 if (isVirtual) { 341 boolean ejbModuleAvailability = 342 this.getEjbModuleAvailability(appName, ejbContainerAvailability); 343 ejbDescriptorAvailability = 344 this.getAvailabilityEnabledFromEjbDescriptor(ejbModuleAvailability); 345 _haEnabled = globalAvailability 348 && ejbContainerAvailability 349 && ejbModuleAvailability 350 && ejbDescriptorAvailability; 351 } else { 352 boolean j2eeApplicationAvailability = 353 this.getJ2eeApplicationAvailability(appName, ejbContainerAvailability); 354 ejbDescriptorAvailability = 355 this.getAvailabilityEnabledFromEjbDescriptor(j2eeApplicationAvailability); 356 _haEnabled = globalAvailability 359 && ejbContainerAvailability 360 && j2eeApplicationAvailability 361 && ejbDescriptorAvailability; 362 } 363 return _haEnabled; 365 } 366 367 public String getPersistenceStoreType() { 368 return (_haEnabled) 369 ? getSfsbHaPersistenceTypeFromConfig() 370 : getSfsbNonHaPersistenceTypeFromConfig(); 371 } 372 373 377 private boolean isVirtualApplication() { 378 Application application = _ejbDescriptor.getApplication(); 379 return application.isVirtual(); 380 } 381 382 387 private String getApplicationName() { 388 Application application = _ejbDescriptor.getApplication(); 389 return application.getRegistrationName(); 390 } 391 392 396 public boolean getEjbContainerAvailabilityEnabledFromConfig() { 397 boolean globalAvailabilityEnabled = this.getAvailabilityEnabledFromConfig(); 398 _logger.finest("in EJBServerConfigLookup>>getEjbContainerAvailabilityEnabledFromConfig"); 399 EjbContainerAvailability eas = this.getEjbContainerAvailability(); 400 if(eas == null) { 401 _logger.fine("EjbContainerAvailability was not defined - check domain.xml"); 402 return globalAvailabilityEnabled; 403 } 404 405 String easString = eas.getAvailabilityEnabled(); 406 Boolean bool = this.toBoolean(easString); 407 if(bool == null) { 408 return globalAvailabilityEnabled; 409 } else { 410 return bool.booleanValue(); 411 } 412 } 413 414 418 public boolean getEjbContainerAvailabilityEnabledFromConfig(boolean inheritedValue) { 419 _logger.finest("in EJBServerConfigLookup>>getEjbContainerAvailabilityEnabledFromConfig"); 420 EjbContainerAvailability eas = this.getEjbContainerAvailability(); 421 if(eas == null) { 422 _logger.fine("EjbContainerAvailability was not defined - check domain.xml"); 423 return inheritedValue; 424 } 425 426 String easString = eas.getAvailabilityEnabled(); 427 Boolean bool = this.toBoolean(easString); 428 if(bool == null) { 429 return inheritedValue; 430 } else { 431 return bool.booleanValue(); 432 } 433 } 434 435 440 private EjbModule getEjbModuleByName(String name) { 441 EjbModule result = null; 442 Applications applicationsBean = this.getApplicationsBeanDynamic(); 443 if(applicationsBean == null) { 444 return null; 445 } 446 return applicationsBean.getEjbModuleByName(name); 447 } 448 449 457 private boolean getEjbModuleAvailability(String name, boolean inheritedValue) { 458 EjbModule ejbModule = 459 this.getEjbModuleByName(name); 460 if(ejbModule == null) { 463 return false; 464 } 467 476 return ejbModule.isAvailabilityEnabled(); 477 } 478 479 484 private J2eeApplication getJ2eeApplicationByName(String appName) { 485 J2eeApplication result = null; 486 Applications applicationsBean = this.getApplicationsBeanDynamic(); 487 if(applicationsBean == null) { 488 return null; 489 } 490 return applicationsBean.getJ2eeApplicationByName(appName); 491 } 492 493 501 private boolean getJ2eeApplicationAvailability(String appName, boolean inheritedValue) { 502 J2eeApplication j2eeApp = 503 this.getJ2eeApplicationByName(appName); 504 if(j2eeApp == null) { 507 return false; 508 } 511 520 return j2eeApp.isAvailabilityEnabled(); 521 } 522 523 526 private EjbContainerAvailability getEjbContainerAvailability() { 527 AvailabilityService availabilityServiceBean = this.getAvailabilityService(); 528 if(availabilityServiceBean == null) { 529 return null; 530 } 531 return availabilityServiceBean.getEjbContainerAvailability(); 532 } 533 534 538 public boolean getAvailabilityEnabledFromEjbDescriptor() { 539 _logger.finest("in EJBServerConfigLookup>>getAvailabilityEnabledFromEjbDescriptor"); 540 IASEjbExtraDescriptors extraDescriptors = 541 _ejbDescriptor.getIASEjbExtraDescriptors(); 542 if(extraDescriptors == null) { 543 return true; 544 } 545 String availabilityEnabledString = 546 extraDescriptors.getAttributeValue(extraDescriptors.AVAILABILITY_ENABLED); 547 548 Boolean bool = this.toBoolean(availabilityEnabledString); 549 if(bool == null) { 550 return true; 551 } else { 552 return bool.booleanValue(); 553 } 554 555 } 556 557 561 public boolean getAvailabilityEnabledFromEjbDescriptor(boolean inheritedValue) { 562 _logger.finest("in EJBServerConfigLookup>>getAvailabilityEnabledFromEjbDescriptor"); 563 IASEjbExtraDescriptors extraDescriptors = 564 _ejbDescriptor.getIASEjbExtraDescriptors(); 565 if(extraDescriptors == null) { 566 return inheritedValue; 567 } 568 String availabilityEnabledString = 569 extraDescriptors.getAttributeValue(extraDescriptors.AVAILABILITY_ENABLED); 570 571 Boolean bool = this.toBoolean(availabilityEnabledString); 572 if(bool == null) { 573 return inheritedValue; 574 } else { 575 return bool.booleanValue(); 576 } 577 578 } 579 580 586 public String getStorePoolJndiNameFromConfig() { 587 _logger.finest("in ServerConfigLookup>>getStorePoolJndiNameFromConfig"); 588 String result = DEFAULT_STORE_POOL_JNDI_NAME; 589 AvailabilityService as = this.getAvailabilityService(); 590 if(as == null) { 591 return result; 592 } 593 String storePoolJndiName = as.getStorePoolName(); 594 if(storePoolJndiName != null) { 595 result = storePoolJndiName; 596 } 597 return result; 598 } 599 600 604 public String getHaStorePoolJndiNameFromConfig() { 605 _logger.finest("in EJBServerConfigLookup>>getHaStorePoolJndiNameFromConfig"); 606 String result = this.getStorePoolJndiNameFromConfig(); 608 EjbContainerAvailability ejbContainerAvailabilityBean = 609 this.getEjbContainerAvailability(); 610 if(ejbContainerAvailabilityBean == null) { 611 return result; 612 } 613 String result2 = ejbContainerAvailabilityBean.getSfsbStorePoolName(); 614 if(result2 != null) { 615 result = result2; 616 } 617 return result; 618 } 619 620 624 public String getSfsbHaPersistenceTypeFromConfig() { 625 _logger.finest("in EJBServerConfigLookup>>getSfsbHaPersistenceTypeFromConfig"); 626 String result = DEFAULT_SFSB_HA_PERSISTENCE_TYPE; 627 EjbContainerAvailability ejbContainerAvailabilityBean = 628 this.getEjbContainerAvailability(); 629 if(ejbContainerAvailabilityBean == null) { 630 return result; 631 } 632 String result2 = ejbContainerAvailabilityBean.getSfsbHaPersistenceType(); 633 if(result2 != null) { 634 result = result2; 635 } 636 return result; 637 } 638 639 643 public String getSfsbNonHaPersistenceTypeFromConfig() { 644 _logger.finest("in EJBServerConfigLookup>>getSfsbNonHaPersistenceTypeFromConfig"); 645 String result = DEFAULT_SFSB_NON_HA_PERSISTENCE_TYPE; 646 EjbContainerAvailability ejbContainerAvailabilityBean = 647 this.getEjbContainerAvailability(); 648 if(ejbContainerAvailabilityBean == null) { 649 return result; 650 } 651 String result2 = ejbContainerAvailabilityBean.getSfsbPersistenceType(); 653 if(result2 != null) { 654 result = result2; 655 } 656 return result; 657 } 658 659 public static boolean checkDebugMonitoringEnabled() { 660 boolean result = false; 661 try 662 { 663 Properties props = System.getProperties(); 664 String str=props.getProperty("MONITOR_EJB_CONTAINER"); 665 if(null!=str) { 666 if( str.equalsIgnoreCase("TRUE")) 667 result=true; 668 } 669 } catch(Exception e) 670 { 671 } 673 return result; 674 } 675 676 680 protected Boolean toBoolean(String value){ 681 if(value == null) return null; 682 683 if (value.equalsIgnoreCase("true")) 684 return Boolean.TRUE; 685 if (value.equalsIgnoreCase("yes")) 686 return Boolean.TRUE; 687 if (value.equalsIgnoreCase("on") ) 688 return Boolean.TRUE; 689 if (value.equalsIgnoreCase("1")) 690 return Boolean.TRUE; 691 692 return Boolean.FALSE; 693 } 694 695 698 private static Logger _logger = null; 699 700 } 701 | Popular Tags |