FileDocCategorySizeDatePackage
DomainMBean.javaAPI DocGlassfish v2 API17785Wed May 16 14:38:04 BST 2007com.sun.enterprise.admin.mbeans

DomainMBean

public class DomainMBean extends com.sun.enterprise.admin.config.BaseConfigMBean implements com.sun.enterprise.admin.mbeanapi.IDomainMBean

Fields Summary
private static final com.sun.enterprise.util.i18n.StringManager
localStrings
private static final String
BUNDLED_DOMAINS_ROOT
private static final String
AUTOSTART_FILENAME
Constructors Summary
Methods Summary
private static voidaddClientHostNameProperty2SystemJmxConnector(com.sun.enterprise.config.serverbeans.Config someConfig)

        final com.sun.enterprise.config.serverbeans.AdminService as = someConfig.getAdminService();
        final JmxConnector jc    = as.getJmxConnectorByName(IAdminConstants.SYSTEM_CONNECTOR_NAME);
        final String hostValue   = System.getProperty(SystemPropertyConstants.HOST_NAME_PROPERTY);
        final String hostName    = IAdminConstants.HOST_PROPERTY_NAME;
        ElementProperty ep       = jc.getElementPropertyByName(hostName);

        if (ep == null) {
            ep = new ElementProperty();
            ep.setName(hostName);
            ep.setValue(hostValue);            
            jc.addElementProperty(ep);
        } else {
            ep.setValue(hostValue);
        }
    
private static voidaddClusterSupportElements(com.sun.enterprise.config.ConfigContext acc)

        final Domain domain = ConfigAPIHelper.getDomainConfigBean(acc);
        domain.setClusters(domain.newClusters());
        domain.setNodeAgents(domain.newNodeAgents());
        domain.setLoadBalancers(domain.newLoadBalancers());
        domain.setLbConfigs(domain.newLbConfigs());
    
public voidaddClusteringSupportUsingProfile(java.lang.String profile)

        final ConfigContext acc    = MBeanRegistryFactory.getAdminContext().getAdminConfigContext();
        if (ServerHelper.isClusterAdminSupported(acc)) {
            final String msg = localStrings.getString("domain.supports.cluster");
            throw new ConfigException(msg);
        }
        try {
            final Config defaultConfig = getTemplateConfig(profile);
            addConfig(acc, defaultConfig);
            addClusterSupportElements(acc);
            configurAdminServer(acc);
            
        } catch(final Exception e) {
            throw new ConfigException(e);
        }
    
private static voidaddConfig(com.sun.enterprise.config.ConfigContext acc, com.sun.enterprise.config.serverbeans.Config dc)

        final Configs configs = ConfigAPIHelper.getDomainConfigBean(acc).getConfigs();
        dc.setName(SystemPropertyConstants.TEMPLATE_CONFIG_NAME);
        configs.addConfig(dc);
        configureDefaultJmsHost(dc);
        addClientHostNameProperty2SystemJmxConnector(dc);
    
private voidcheckAutoStartSupported()

        if (!isAutoStartSupported()) {
            String msg = localStrings.getString(
                    "admin.mbeans.domain.autostart_not_supported");
            throw new MBeanConfigException(msg);
        }
    
private static voidconfigurAdminServer(com.sun.enterprise.config.ConfigContext acc)

        final Config dasc   = ServerHelper.getConfigForServer(acc, SystemPropertyConstants.DEFAULT_SERVER_INSTANCE_NAME);
        final JavaConfig jc = dasc.getJavaConfig();
        jc.addJvmOptions("-Djavax.management.builder.initial=com.sun.enterprise.ee.admin.AppServerMBeanServerBuilder");
        jc.addJvmOptions("-Dcom.sun.appserv.pluggable.features=com.sun.enterprise.ee.server.pluggable.EEPluggableFeatureImpl");
        addClientHostNameProperty2SystemJmxConnector(dasc);
    
private static voidconfigureDefaultJmsHost(com.sun.enterprise.config.serverbeans.Config tc)

        //this configures the default_JMS_Host's attributes
        //default JMS Host is pointed to by the default-jms-host attribute of jms-service.
        final JmsService js = tc.getJmsService();
        final String jmshn  = js.getDefaultJmsHost();
        final JmsHost jmsh  = js.getJmsHostByName(jmshn);
        jmsh.setAdminUserName(IASJmsUtil.DEFAULT_USER);
        jmsh.setAdminPassword(IASJmsUtil.DEFAULT_PASSWORD);
        jmsh.setHost(System.getProperty(SystemPropertyConstants.HOST_NAME_PROPERTY));
        //don't set the port as it is "tokenized" appropriately
    
private booleandisableAutoStart()

        File autoStartFile = getAutoStartFile();
        boolean success = true;
        if (autoStartFile.exists()) {
            success = autoStartFile.delete();
        }
        return success;
    
private booleanenableAutoStart()

        File autoStartFile = getAutoStartFile();
        boolean success = false;
        try {
            if (!autoStartFile.exists()) {
                success = autoStartFile.createNewFile();
            } else {
                success = true;
            }
        } catch (IOException ioe) {
            _sLogger.log(Level.FINE, "mbean.autostart_ioexception", ioe);
            _sLogger.log(Level.WARNING, "mbean.autostart_enable_error",
                    new Object[] {autoStartFile, ioe.getMessage()});
        }
        return success;
    
private static booleanexists(com.sun.enterprise.config.serverbeans.Config[] configs, java.lang.String configNamed)

        boolean exists = false;
        for (final Config c : configs) {
            if (c.getName().equals(configNamed)) {
                exists = true;
                break;
            }
        }
        return ( exists );
    
private java.io.FilegetAutoStartFile()

        return new File(getConfigDir(), AUTOSTART_FILENAME);
    
public java.lang.StringgetConfigDir()
Returns the absolute path of the config directory.

returns
the absolute path of the config directory.

        InstanceEnvironment env = 
                ApplicationServer.getServerContext().getInstanceEnvironment();
        return env.getConfigDirPath();
    
public javax.management.AttributeListgetDefaultAttributeValues(java.lang.String mbeanTypeName, java.lang.String[] attrNames)

        if(mbeanTypeName==null)
            return null;
        try {
            MBeanRegistryEntry entry = m_registry.findMBeanRegistryEntryByType(mbeanTypeName);
            if(attrNames==null)
            {
                attrNames = entry.getAttributeNames();
                if(attrNames==null || attrNames.length<1)
                    return null;
            }
            MBeanNamingDescriptor descr = entry.getNamingDescriptor();
            String className = descr.getMBeanClassName();
            Class cl = Class.forName(className);
            Method method = null;
            try {
                method = cl.getDeclaredMethod("getDefaultAttributeValues", new Class[]{(new String[0]).getClass()});
                return (AttributeList)method.invoke(null, new Object[]{attrNames});
            } catch (Exception e)
            {
                //no custom implementation - just ignore
            }
            // standard 
            return ConfigMBeanHelper.getDefaultAttributeValues(descr, attrNames); 
        } catch (Exception e)
        {
            _sLogger.fine("getDefaultAttributeValues(): Exception for mbeanTypeName:"+mbeanTypeName);
            return null;
        }
    
public javax.management.AttributeListgetDefaultCustomProperties(java.lang.String mbeanTypeName, javax.management.AttributeList attributeList)

        if(mbeanTypeName==null)
            return null;
        try {
            MBeanRegistryEntry entry = m_registry.findMBeanRegistryEntryByType(mbeanTypeName);
            MBeanNamingDescriptor descr = entry.getNamingDescriptor();
            String className = descr.getMBeanClassName();
            Class cl = Class.forName(className);
            Method method = cl.getDeclaredMethod("getDefaultCustomProperties", new Class[]{Class.forName("javax.management.AttributeList")});
            return (AttributeList)method.invoke(null, new Object[]{attributeList});
        } catch (Exception e)
        {
            _sLogger.fine("getDefaultCustomProperties(): Exception for mbeanTypeName:"+mbeanTypeName);
            return null;
        }
            
    
public java.lang.StringgetName()
Returns the name of this domain.

return
domain name


        String name = null;

        try {
            name = System.getProperty(SystemPropertyConstants.DOMAIN_NAME);
        } catch (Exception e) {
            String msg = localStrings.getString(
                    "admin.mbeans.domain.get_name_failed")
                    + " " + e.getLocalizedMessage();
            throw new MBeanConfigException(msg);
        }

        if (name == null) {
            String msg = localStrings.getString(
                    "admin.mbeans.domain.get_name_failed");
            throw new MBeanConfigException(msg);
        }

        return name;
    
private com.sun.enterprise.config.serverbeans.ConfiggetTemplateConfig(java.lang.String profile)

        final RepositoryConfig myRepos = new RepositoryConfig(); //all system properties are taken care of.
        final PEFileLayout layout = new PEFileLayout(myRepos);
        final File profileDomainXmlTemplate = layout.getPreExistingDomainXmlTemplateForProfile(profile);
        if (! profileDomainXmlTemplate.exists()) {
            final String msg = localStrings.getString("template.domain.xml.not.found",
                    profileDomainXmlTemplate.getAbsolutePath(), profile);
            throw new IllegalArgumentException(msg);
        }
        final ConfigContext tcc = ConfigFactory.createConfigContext(profileDomainXmlTemplate.getAbsolutePath(), true);
        //this created a config context from which we can just borrow the config element.
        final String tcn = SystemPropertyConstants.TEMPLATE_CONFIG_NAME;
        if (! exists(ConfigAPIHelper.getConfigsInDomain(tcc), tcn)) {
            final String msg = localStrings.getString("template.config.not.found", tcn, profileDomainXmlTemplate.getAbsolutePath());
            throw new IllegalArgumentException(msg);
        }
        final Config tc = ConfigAPIHelper.getConfigByName(tcc, tcn); // this has to exist
        return ( (Config)tc.clone() ); //cloning is required
    
public booleanisAutoStartEnabled()
Is auto start enabled for this domain.

throw
MBeanConfigException if autostart is not supported for this domain

        checkAutoStartSupported();
        File autoStartFile = getAutoStartFile();
        return autoStartFile.exists();
    
public booleanisAutoStartSupported()
Is autostart feature supported for this domain. Enabling autostart will result in a domain being started up at the time of machine startup (boot). The autostart feature is supported only on domains in default domain directory of Solaris bundled release.

returns
true if autostart feature is supported for this domain.


                                                           
       
        if (OS.isUnix()) {
            if (getConfigDir().startsWith(BUNDLED_DOMAINS_ROOT)) {
                return true;
            }
        }
        return false;
    
public java.lang.StringresolveTokens(java.lang.String value, java.lang.String instanceName)
Resolve tokens of the form ${..} in value.

param
value string value to resolve
param
instanceName - instance name for obtaining token values. If null, then DAS is used for resolution
returns
resolved string

    
                                            
           
    
        return resolveTokens(value, instanceName, false);
    
public java.lang.StringresolveTokens(java.lang.String value, java.lang.String instanceName, boolean bResolvePathesAsWell)
Resolve tokens of the form ${..} in value.

param
value string value to resolve
param
instanceName - instance name for obtaining token values. If null, then DAS is used for resolution
param
bResolvePathesAsWell - if true, resolves pathes as well (currently only for DAS!)
returns
resolved string

        //FIXME: bResolvePathesAsWell=true is working correct only for DAS 
        if(instanceName==null)
        {
            instanceName=MBeanRegistryFactory.getAdminContext().getServerName();
        }
        PropertyResolver resolver = new PropertyResolver(getConfigContext(), instanceName);
        return resolver.resolve(value, bResolvePathesAsWell);
    
public voidsetAutoStartEnabled(boolean state)
Set autostart enabled state.

param
state if true enables autostart, otherwise disables autostart
throw
MBeanConfigException if autostart is not supported or if there is an error in setting autostart state.

        checkAutoStartSupported();
        boolean success = (state ? enableAutoStart() : disableAutoStart());
        if (!success) {
            String msg = localStrings.getString(
                    "admin.mbeans.domain.set_autostart_failed");
            throw new MBeanConfigException(msg);
        }