FileDocCategorySizeDatePackage
EJBServerConfigLookup.javaAPI DocGlassfish v2 API27829Tue Jun 12 11:02:38 BST 2007com.sun.ejb.base.sfsb.util

EJBServerConfigLookup

public class EJBServerConfigLookup extends Object
author
lwhite

Fields Summary
protected final String
DEFAULT_STORE_POOL_JNDI_NAME
The default store-pool-jndi-name (used by Ejb Container for Stateful Session Bean checkpointing and passivation to HADB
protected final String
DEFAULT_SFSB_HA_PERSISTENCE_TYPE
The default sfsb-ha-persistence-type (used by Ejb Container for Stateful Session Bean checkpointing and passivation to HADB
protected final String
DEFAULT_SFSB_NON_HA_PERSISTENCE_TYPE
The default sfsb-non-ha-persistence-type (used by Ejb Container for Stateful Session Bean checkpointing and passivation to HADB
private static final String
REPLICATED_TYPE
protected com.sun.enterprise.deployment.EjbDescriptor
_ejbDescriptor
The ejbDescriptor
protected boolean
_haEnabled
protected com.sun.enterprise.config.ConfigContext
_configContext
The config context passed in via constructor used when a dynamic config context is needed rather than usual run-time config context e.g. deployment
protected static boolean
_isDebugMonitoringEnabled
is monitoring enabled
private static final Logger
_logger
The logger to use for logging ALL web container related messages.
Constructors Summary
public EJBServerConfigLookup()
Creates a new instance of EJBServerConfigLookup

     

           
               
    
public EJBServerConfigLookup(com.sun.enterprise.deployment.EjbDescriptor ejbDescriptor)
Creates a new instance of EJBServerConfigLookup

        this();
        _ejbDescriptor = ejbDescriptor;        
    
public EJBServerConfigLookup(com.sun.enterprise.deployment.EjbDescriptor ejbDescriptor, com.sun.enterprise.config.ConfigContext configContext)
Creates a new instance of EJBServerConfigLookup

        this(ejbDescriptor);
        _configContext = configContext;        
    
Methods Summary
public booleancalculateEjbAvailabilityEnabledFromConfig()
Get the availability-enabled from domain.xml. This takes into account: global ejb-container-availability j2ee app if not stand-alone ejb-module (if stand-alone) return false if not found FIXME: need to add taking the availability-enabled of the bean itself

        _logger.finest("in EJBServerConfigLookup>>calculateEjbAvailabilityEnabledFromConfig");
        boolean isVirtual = this.isVirtualApplication();
        String appName = this.getApplicationName();
        
        boolean globalAvailability = 
            this.getAvailabilityEnabledFromConfig();
        boolean ejbContainerAvailability = 
            this.getEjbContainerAvailabilityEnabledFromConfig(globalAvailability);
        boolean ejbDescriptorAvailability = true;
//System.out.println("EJBServerConfigLookup: app isVirtual=" + isVirtual);        
        if (isVirtual) {
            boolean ejbModuleAvailability =
                this.getEjbModuleAvailability(appName, ejbContainerAvailability);
            ejbDescriptorAvailability =
                this.getAvailabilityEnabledFromEjbDescriptor(ejbModuleAvailability);
//System.out.println("virtual: ejbModuleAvailability= " + ejbModuleAvailability);
//System.out.println("virtual: ejbDescriptorAvailability= " + ejbDescriptorAvailability);
	    _haEnabled = globalAvailability 
                && ejbContainerAvailability
                && ejbModuleAvailability
                && ejbDescriptorAvailability;
        } else {
            boolean j2eeApplicationAvailability =
                this.getJ2eeApplicationAvailability(appName, ejbContainerAvailability);
            ejbDescriptorAvailability =
                this.getAvailabilityEnabledFromEjbDescriptor(j2eeApplicationAvailability);           
//System.out.println("non-virtual: j2eeApplicationAvailability= " + j2eeApplicationAvailability);
//System.out.println("non-virtual: ejbDescriptorAvailability= " + ejbDescriptorAvailability);            
	    _haEnabled = globalAvailability 
                && ejbContainerAvailability
                && j2eeApplicationAvailability
                && ejbDescriptorAvailability;            
        }
//System.out.println("_haEnabled returned = " + _haEnabled);        
	return _haEnabled;
    
public static booleancheckDebugMonitoringEnabled()

        boolean result = false;
	try
        {
            Properties props = System.getProperties();
            String str=props.getProperty("MONITOR_EJB_CONTAINER");
            if(null!=str) {
                if( str.equalsIgnoreCase("TRUE"))
                    result=true;
            } 
        } catch(Exception e)
        {
            //do nothing just return false
        }
        return result;
    
private java.lang.StringgetApplicationName()
return the name of the application to which the bean belongs it will be the j2ee app name if the bean is part of a j2ee app it will be the ejb module name if the bean is a stand-alone ejb module

        Application application = _ejbDescriptor.getApplication();
        return application.getRegistrationName();
    
private com.sun.enterprise.config.serverbeans.ApplicationsgetApplicationsBean()
Get the applications element from domain.xml. return null if not found

        Applications applicationsBean = null;
        Domain domainBean = null;
        /*
        ServerContext serverCtx = ApplicationServer.getServerContext();
        ConfigContext configCtx = serverCtx.getConfigContext();
         */
        ConfigContext configCtx = this.getConfigContext();
        try {
            domainBean = ServerBeansFactory.getDomainBean(configCtx);
            if(domainBean != null) {
                applicationsBean = domainBean.getApplications();
            }
        } catch (ConfigException ex) {}

        return applicationsBean;
    
private com.sun.enterprise.config.serverbeans.ApplicationsgetApplicationsBeanDynamic()
Get the applications element from domain.xml. return null if not found

        Applications applicationsBean = null;
        Domain domainBean = null;
        ConfigContext configCtx = this.getConfigContextDynamic();
        try {
            domainBean = ServerBeansFactory.getDomainBean(configCtx);
            if(domainBean != null) {
                applicationsBean = domainBean.getApplications();
            }
        } catch (ConfigException ex) {}

        return applicationsBean;
    
public booleangetAvailabilityEnabledFromConfig()
Get the availability-enabled from domain.xml. return false if not found

 
        _logger.finest("in EJBServerConfigLookup>>getAvailabilityEnabledFromConfig");
        AvailabilityService as = this.getAvailabilityService();
        if(as == null) {
            _logger.fine("AvailabilityService was not defined - check domain.xml");
            return false;
        }        
        return as.isAvailabilityEnabled();
    
public booleangetAvailabilityEnabledFromEjbDescriptor()
Get the availability-enabled for the bean from sun-ejb-jar.xml. return true if not found

 
        _logger.finest("in EJBServerConfigLookup>>getAvailabilityEnabledFromEjbDescriptor");
        IASEjbExtraDescriptors extraDescriptors = 
            _ejbDescriptor.getIASEjbExtraDescriptors();
        if(extraDescriptors == null) {
            return true;
        }
        String availabilityEnabledString = 
            extraDescriptors.getAttributeValue(extraDescriptors.AVAILABILITY_ENABLED);
        
        Boolean bool = this.toBoolean(availabilityEnabledString);
        if(bool == null) {
            return true;
        } else {
            return bool.booleanValue();
        }         
        
    
public booleangetAvailabilityEnabledFromEjbDescriptor(boolean inheritedValue)
Get the availability-enabled for the bean from sun-ejb-jar.xml. return defaultValue if not found

 
        _logger.finest("in EJBServerConfigLookup>>getAvailabilityEnabledFromEjbDescriptor");
        IASEjbExtraDescriptors extraDescriptors = 
            _ejbDescriptor.getIASEjbExtraDescriptors();
        if(extraDescriptors == null) {
            return inheritedValue;
        }
        String availabilityEnabledString = 
            extraDescriptors.getAttributeValue(extraDescriptors.AVAILABILITY_ENABLED);
        
        Boolean bool = this.toBoolean(availabilityEnabledString);
        if(bool == null) {
            return inheritedValue;
        } else {
            return bool.booleanValue();
        }         
        
    
protected com.sun.enterprise.config.serverbeans.AvailabilityServicegetAvailabilityService()
Get the availability-service element from domain.xml. return null if not found

        Config configBean = this.getConfigBean();
        if(configBean == null) {
            return null;
        }
        return configBean.getAvailabilityService();
    
public java.lang.StringgetClusterName()
Get the cluster name from domain.xml for this server. return null if not found

        String result = null;
        /*
        ServerContext serverCtx = ApplicationServer.getServerContext();
        ConfigContext configCtx = serverCtx.getConfigContext();
         */
        ConfigContext configCtx = this.getConfigContext();
        
        String serverName = this.getServerName();
        if(serverName == null) {
            return result;
        }
        boolean isClustered = false;
        try {
            isClustered = ServerHelper.isServerClustered(configCtx, serverName);
        } catch (ConfigException ex) {}
        if(!isClustered) {
            result = serverName + "_nc";    //non-clustered example: server1_nc
            return result;
        }
        Cluster cluster = null;
        try {
            cluster = ClusterHelper.getClusterForInstance(configCtx, serverName);
        } catch (ConfigException ex) {}
        if(cluster != null) {
            result = cluster.getName();
        }
        return result;
    
private com.sun.enterprise.config.serverbeans.ConfiggetConfigBean()
Get the config element from domain.xml. return null if not found

        Config configBean = null;
        ServerContext serverCtx = ApplicationServer.getServerContext();
        ConfigContext configCtx = serverCtx.getConfigContext(); 
        try {
            configBean = ServerBeansFactory.getConfigBean(configCtx);
        } catch (ConfigException ex) {}

        return configBean;
    
protected com.sun.enterprise.config.ConfigContextgetConfigContext()
Get the ConfigContext for this server return null if not found

        ServerContext serverCtx = this.getServerContext();
        if(serverCtx == null) {
            return null;
        }
        return serverCtx.getConfigContext();
    
protected com.sun.enterprise.config.ConfigContextgetConfigContextDynamic()
Get the ConfigContext for this server return null if not found

        if (_configContext != null) {
            return _configContext;
        } else {
            return getConfigContext();
        }
    
private com.sun.enterprise.config.serverbeans.EjbContainerAvailabilitygetEjbContainerAvailability()
return the ejb-container-availability element from domain.xml

        AvailabilityService availabilityServiceBean = this.getAvailabilityService();
        if(availabilityServiceBean == null) {
            return null;
        }
        return availabilityServiceBean.getEjbContainerAvailability();
    
public booleangetEjbContainerAvailabilityEnabledFromConfig()
Get the availability-enabled for the ejb container from domain.xml. return inherited global availability-enabled if not found

        boolean globalAvailabilityEnabled = this.getAvailabilityEnabledFromConfig();
        _logger.finest("in EJBServerConfigLookup>>getEjbContainerAvailabilityEnabledFromConfig");
        EjbContainerAvailability eas = this.getEjbContainerAvailability();
        if(eas == null) {
            _logger.fine("EjbContainerAvailability was not defined - check domain.xml");
            return globalAvailabilityEnabled;
        }
        
        String easString = eas.getAvailabilityEnabled();
        Boolean bool = this.toBoolean(easString);
        if(bool == null) {
            return globalAvailabilityEnabled;
        } else {
            return bool.booleanValue();
        }        
    
public booleangetEjbContainerAvailabilityEnabledFromConfig(boolean inheritedValue)
Get the availability-enabled for the ejb container from domain.xml. return inherited global availability-enabled if not found

        _logger.finest("in EJBServerConfigLookup>>getEjbContainerAvailabilityEnabledFromConfig");
        EjbContainerAvailability eas = this.getEjbContainerAvailability();
        if(eas == null) {
            _logger.fine("EjbContainerAvailability was not defined - check domain.xml");
            return inheritedValue;
        }
        
        String easString = eas.getAvailabilityEnabled();
        Boolean bool = this.toBoolean(easString);
        if(bool == null) {
            return inheritedValue;
        } else {
            return bool.booleanValue();
        }        
    
private booleangetEjbModuleAvailability(java.lang.String name, boolean inheritedValue)
return availability-enabled for the deployed ejb module from domain.xml based on the name return inheritedValue if module not found or module availability is not defined

param
name
param
inheritedValue

        EjbModule ejbModule =
            this.getEjbModuleByName(name);
    //FIXME remove after testing
//System.out.println("EJBServerConfigLookup>>getEjbModuleAvailability ejbModule = " + ejbModule);    
        if(ejbModule == null) {
            return false;
            //FIXME remove after testing
            //return inheritedValue;
        }
        /* FIXME: remove after testing
        String moduleString = ejbModule.getAvailabilityEnabled();
        Boolean bool = this.toBoolean(moduleString);
        if(bool == null) {
            return inheritedValue;
        } else {
            return bool.booleanValue();
        } 
         */
        return ejbModule.isAvailabilityEnabled();
    
private com.sun.enterprise.config.serverbeans.EjbModulegetEjbModuleByName(java.lang.String name)
Get the deployed ejb module from domain.xml based on the name return null if not found

param
name

        EjbModule result = null;
        Applications applicationsBean = this.getApplicationsBeanDynamic();
        if(applicationsBean == null) {
            return null;
        }
        return applicationsBean.getEjbModuleByName(name);
    
public java.lang.StringgetHaStorePoolJndiNameFromConfig()
Get the sfsb-store-pool-name from domain.xml. return DEFAULT_STORE_POOL_JNDI_NAME if not found

        _logger.finest("in EJBServerConfigLookup>>getHaStorePoolJndiNameFromConfig");
        //String result = DEFAULT_STORE_POOL_JNDI_NAME;
        String result = this.getStorePoolJndiNameFromConfig();
        EjbContainerAvailability ejbContainerAvailabilityBean =
            this.getEjbContainerAvailability();
        if(ejbContainerAvailabilityBean == null) {
            return result;
        }
        String result2 = ejbContainerAvailabilityBean.getSfsbStorePoolName();
        if(result2 != null) {
            result = result2;
        }
        return result; 
    
private booleangetJ2eeApplicationAvailability(java.lang.String appName, boolean inheritedValue)
return availability-enabled for the deployed j2ee application from domain.xml based on the app name return inheritedValue if module not found or j2ee application availability is not defined

param
appName
param
inheritedValue

        J2eeApplication j2eeApp =
            this.getJ2eeApplicationByName(appName);
//FIXME remove after testing
//System.out.println("EJBServerConfigLookup>>getJ2eeApplicationAvailability j2eeApp = " + j2eeApp);
        if(j2eeApp == null) {            
            return false;
            //FIXME remove after testing
            //return inheritedValue;
        }
        /*  FIXME remove after testing
        String appString = j2eeApp.getAvailabilityEnabled();
        Boolean bool = this.toBoolean(appString);
        if(bool == null) {
            return inheritedValue;
        } else {
            return bool.booleanValue();
        }
         */
        return j2eeApp.isAvailabilityEnabled();
    
private com.sun.enterprise.config.serverbeans.J2eeApplicationgetJ2eeApplicationByName(java.lang.String appName)
Get the deployed j2ee application from domain.xml based on the appName return null if not found

param
appName

        J2eeApplication result = null;
        Applications applicationsBean = this.getApplicationsBeanDynamic();
        if(applicationsBean == null) {
            return null;
        }
        return applicationsBean.getJ2eeApplicationByName(appName);
    
public java.lang.StringgetPersistenceStoreType()

	return (_haEnabled)
	    ? getSfsbHaPersistenceTypeFromConfig()
	    : getSfsbNonHaPersistenceTypeFromConfig();
    
private com.sun.enterprise.config.serverbeans.ServergetServerBean()
Get the server element from domain.xml. return null if not found

        Server serverBean = null;
        /*
        ServerContext serverCtx = ApplicationServer.getServerContext();
        ConfigContext configCtx = serverCtx.getConfigContext();
         */
        ConfigContext configCtx = this.getConfigContext();
        try {
            serverBean = ServerBeansFactory.getServerBean(configCtx);
        } catch (ConfigException ex) {}

        return serverBean;
    
protected com.sun.enterprise.server.ServerContextgetServerContext()
Get the ServerContext for this server return null if not found

        return ApplicationServer.getServerContext();
    
private java.lang.StringgetServerName()
Get the server name from domain.xml. return null if not found

        String result = null;
        Server serverBean = this.getServerBean();
        if(serverBean != null) {
            result = serverBean.getName();
        }
        return result;
    
public java.lang.StringgetSfsbHaPersistenceTypeFromConfig()
Get the sfsb-ha-persistence-type from domain.xml. return DEFAULT_SFSB_HA_PERSISTENCE_TYPE if not found

        _logger.finest("in EJBServerConfigLookup>>getSfsbHaPersistenceTypeFromConfig");
        String result = DEFAULT_SFSB_HA_PERSISTENCE_TYPE;
        EjbContainerAvailability ejbContainerAvailabilityBean =
            this.getEjbContainerAvailability();
        if(ejbContainerAvailabilityBean == null) {
            return result;
        }
        String result2 = ejbContainerAvailabilityBean.getSfsbHaPersistenceType();
        if(result2 != null) {
            result = result2;
        }
        return result; 
    
public java.lang.StringgetSfsbNonHaPersistenceTypeFromConfig()
Get the sfsb-non-ha-persistence-type from domain.xml. return DEFAULT_SFSB_NON_HA_PERSISTENCE_TYPE if not found

        _logger.finest("in EJBServerConfigLookup>>getSfsbNonHaPersistenceTypeFromConfig");
        String result = DEFAULT_SFSB_NON_HA_PERSISTENCE_TYPE;
        EjbContainerAvailability ejbContainerAvailabilityBean =
            this.getEjbContainerAvailability();
        if(ejbContainerAvailabilityBean == null) {
            return result;
        }
        //String result2 = ejbContainerAvailabilityBean.getSfsbNonHaPersistenceType();
        String result2 = ejbContainerAvailabilityBean.getSfsbPersistenceType();
        if(result2 != null) {
            result = result2;
        }
        return result; 
    
public java.lang.StringgetStorePoolJndiNameFromConfig()
Get the store-pool-jndi-name from domain.xml. This is the store-pool-name in element it represents the default for both web & ejb container return DEFAULT_STORE_POOL_JNDI_NAME if not found

        _logger.finest("in ServerConfigLookup>>getStorePoolJndiNameFromConfig");
        String result = DEFAULT_STORE_POOL_JNDI_NAME;
        AvailabilityService as = this.getAvailabilityService();
        if(as == null) {
            return result;
        }
        String storePoolJndiName = as.getStorePoolName();
        if(storePoolJndiName != null) {
            result = storePoolJndiName;
        }
        return result;
    
public static booleanisDebugMonitoringEnabled()
Is private (internal) monitoring enabled

        return _isDebugMonitoringEnabled;
    
public static booleanisMonitoringEnabled()
Is (any) monitoring enabled -- private or public Statistics gathering is based on this value

    
    
	
            _isDebugMonitoringEnabled = checkDebugMonitoringEnabled();
	
        //return (isDebugMonitoringEnabled() || isPublicMonitoringEnabled());
        return isDebugMonitoringEnabled();
    
private booleanisReplicationTypeMemory()

        return REPLICATED_TYPE.equalsIgnoreCase(getSfsbHaPersistenceTypeFromConfig());
    
private booleanisVirtualApplication()
return whether the bean is a "virtual" app - i.e. a stand-alone ejb module

        Application application = _ejbDescriptor.getApplication();
        return application.isVirtual();
    
public static final booleanneedToAddSFSBVersionInterceptors()

        boolean isClustered = false;
        boolean isEJBAvailabilityEnabled = false;
        boolean isStoreTypeMemory = false;

        
        try {
            EJBServerConfigLookup ejbSCLookup = new EJBServerConfigLookup();
            ConfigContext configCtx = ejbSCLookup.getConfigContext();
 
            isEJBAvailabilityEnabled = ejbSCLookup
                    .getEjbContainerAvailabilityEnabledFromConfig();
            _logger.log(Level.INFO,
                    "EJBSCLookup:: sc.getEjbContainerAvailabilityEnabledFromConfig() ==> "
                            + isEJBAvailabilityEnabled);
 
            try {
                isClustered = ServerHelper.isServerClustered(configCtx,
                        ejbSCLookup.getServerContext().getInstanceName());
            } catch (ConfigException conFigEx) {
                _logger.log(Level.INFO, "Got ConfigException. Will assume "
                        + "isClustered to be false", conFigEx);
                isClustered = false;
            }
            
            isStoreTypeMemory = ejbSCLookup.isReplicationTypeMemory();
        } catch (Exception ex) {
            _logger.log(Level.FINE,
                    "Got exception in needToAddSFSBVersionInterceptors ("
                        + ex + "). SFSBVersionInterceptors not added");
            _logger.log(Level.FINE, "Exception in needToAddSFSBVersionInterceptors", ex);
        }
 
        boolean result = isClustered && isEJBAvailabilityEnabled && isStoreTypeMemory;
        _logger.log(Level.FINE, "EJBServerConfigLookup::==> isClustered:"
                + isClustered + " ; isEJBAvailabilityEnabled: "
                + isEJBAvailabilityEnabled + " ; isStoreTypeMemory ==> "
                + isStoreTypeMemory + " ; result: " + result);
 
        // result = sc.getEjbContainerAvailabilityEnabledFromConfig();
        return result;
    
protected java.lang.BooleantoBoolean(java.lang.String value)
convert the input value to the appropriate Boolean value if input value is null, return null

        if(value == null) return null;
        
        if (value.equalsIgnoreCase("true"))
            return Boolean.TRUE;
        if (value.equalsIgnoreCase("yes"))
            return Boolean.TRUE;
        if (value.equalsIgnoreCase("on") )
            return Boolean.TRUE;
        if (value.equalsIgnoreCase("1"))
            return Boolean.TRUE;
    
        return Boolean.FALSE;