FileDocCategorySizeDatePackage
ManagedAdminServerInstance.javaAPI DocGlassfish v2 API13618Fri May 04 22:33:56 BST 2007com.sun.enterprise.admin.server.core.mbean.config

ManagedAdminServerInstance

public class ManagedAdminServerInstance extends ConfigMBeanBase
The MBean that represents the Admin Server Instance for iAS SE. In other words it represents the management interface of the Admin Server Instance. ObjectName of this MBean is ias:type=server-instance, name=admin-server

Fields Summary
private static final String[]
MAPLIST
private static final String[]
ATTRIBUTES
private static final String[]
OPERATIONS
private static final Logger
_logger
private ManagedServerInstance
mDelegate
private boolean
mRestartNeeded
Constructors Summary
public ManagedAdminServerInstance()


       
    
        this.setDescriptions(MAPLIST, ATTRIBUTES, OPERATIONS);
        this.initialize(ObjectNames.kServerInstance, new String[]{ServerManager.ADMINSERVER_ID});
    
Methods Summary
public booleanapplyConfigChanges()
Copies the file from backup directory to the real config directory so that the configuration is stored on disk. There is no guarantee of any transactional support. In case of admin server instance only server.xml file is edited in the backup directory, so this method only copies server.xml. (The other conf files for admin instance are edited directly in live configuration area). As there is no dynamic reconfiguration for admin server, the admin instance always requires restart for new settings to take affect.

return
True means requires restart.

        try {
            InstanceEnvironment ie = new InstanceEnvironment(
                    ServerManager.ADMINSERVER_ID);
            // Force write of server.xml changes because the check to ensure
            // that manual edits are not lost (the method canApplyConfigChanges)
            // is already invoked from MBeanServer just before invoking this
            // (applyConfigChanges) method.
            //ie.applyServerXmlChanges(true);
            initDelegate();
            ConfigContext ctx = mDelegate.getConfigContext(
                    ServerManager.ADMINSERVER_ID);
            ctx.resetConfigChangeList();
            mRestartNeeded = true;
            /* New for 8.0 - temporary - gen server.xml b4 notif */
            /* This call most likely goes away */
            if (ManagedServerInstance.PORT_DOMAIN_TO_SERVER) {
                final String domainXMLPath = ie.getConfigFilePath();
                final String serverXMLPath = System.getProperty(Constants.IAS_ROOT) 
                    + "/" 
                    + ie.getName()
                    + "/config/" 
                    + ie.kServerXMLFileName;
                new Domain2ServerTransformer(domainXMLPath, serverXMLPath).transform();
            }
            /* New for 8.0 - temporary - gen server.xml b4 notif */
        } catch (ConfigException ce) {
            _logger.log(Level.INFO, "mbean.config.admin.apply_failed",
                    ce.getLocalizedMessage());
            _logger.log(Level.FINEST, ce.getMessage(), ce);
            throw new ServerInstanceException(ce.getLocalizedMessage());
        }
        return mRestartNeeded;
    
public booleancanApplyConfigChanges()
Can config changes be applied. This method returns true
  • if live server.xml has not been manually edited or
  • if live server.xml has been manully edited but no other changes have been made through the GUI or CLI to backup server.xml.
. This method is explicitly coded to not throw any exception and will return false in case there is any exception in processing.

return
true if config changes can be applied, false otherwise

        boolean canApply = false;
        try {
            initDelegate();
            //InstanceEnvironment ie = new InstanceEnvironment(
                   // ServerManager.ADMINSERVER_ID);
            /*
            if (ie.hasHotXmlChanged()) {
                if (ie.canReloadManualXmlChanges()) {
                    ie.useManualServerXmlChanges();
                    mDelegate.reloadAfterChange(ie);
                    canApply = true;
                }
            } else {
             */
                canApply = true;
                /*
            }
                 **/
        } catch (Exception ex) {
            _logger.log(Level.INFO, "mbean.config.admin.canapply_failed",
                    ex.getLocalizedMessage());
            _logger.log(Level.FINEST, ex.getLocalizedMessage(), ex);
        }
        return canApply;
    
public com.sun.enterprise.admin.util.HostAndPortgetHostAndPort()

        return getHttpListenerHostPort();
    
private com.sun.enterprise.admin.util.HostAndPortgetHttpListenerHostPort()
Returns the host & port of the http listener 'http-listener-1'. (host by default is localhost).

        HostAndPort hAndp = null;
        try
        {
//ms1            Server          server  = (Server) super.getBaseConfigBean();
            Config          config  = (Config) super.getConfigBeanByXPath(ServerXPathHelper.XPATH_CONFIG);
            HttpService     https   = config.getHttpService();
            
            HttpListener[] hlArray = https.getHttpListener();
            //check not needed since there should always be atleast 1 httplistener
            //if you don't find one, use first one.
            HttpListener ls = hlArray[0];
            //default is the first one that is enabled.
            for(int i = 0;i<hlArray.length;i++) {
                if(hlArray[i].isEnabled()) {
                    ls = hlArray[i];
                    break;
                }
            }
            
            String          port    = ls.getPort();
            int             intPort = Integer.parseInt (port);
            hAndp = new HostAndPort("localhost", intPort);
        }
        catch (Exception e)
        {
            throw new ServerInstanceException(e.getLocalizedMessage());
        }
        return hAndp;
    
private synchronized voidinitDelegate()

        if (mDelegate != null)
        {
            return;
        }
        try
        {
            HostAndPort hp = getHttpListenerHostPort();
            mDelegate = new ManagedServerInstance(ServerManager.ADMINSERVER_ID, 
                                                  hp, false);
        }
        catch (ServerInstanceException sie)
        {
            throw sie;
        }
        catch (PortInUseException piue)
        {
        }
        catch (Exception e)
        {
            throw new ServerInstanceException(e.getLocalizedMessage());
        }
    
public booleanisApplyNeeded(boolean check)
Is apply changes required. This method added to sync up with ManagedServerInstance. SOM uses same object for admin server mbean non admin server mbean. Therefore the method signatures should be same.

param
check not used

        return isApplyNeeded();
    
public booleanisApplyNeeded()
Is apply changes required. This method returns true if any changes have been made to server.xml that have not been applied yet.

return
true if there are changes to backup server.xml and that have not been applied to live server.xml

        boolean applyNeeded = false;
        try
        {
            initDelegate();
            ConfigContext ctx = mDelegate.getConfigContext(
                    ServerManager.ADMINSERVER_ID);
            applyNeeded = ctx.isChanged();
        } catch (ConfigException ce) {
            _logger.log(Level.INFO, "mbean.config.admin.applyneeded_failed",
                    ce.getMessage());
            _logger.log(Level.FINEST, ce.getMessage(), ce);
            throw new ServerInstanceException(ce.getLocalizedMessage());
        }
        return applyNeeded;
    
public booleanisRestartNeeded()
Is restart needed. For admin server instance, there is no dynamic reconfiguration, so restart is needed whenever any change is applied.

return
true if restart is required.

        return mRestartNeeded;
    
public booleanuseManualConfigChanges()
Use manual config changes. This method is invoked if the user decides to keep the hand edits to server.xml.

return
true if restart is required.

        try {
            initDelegate();
            InstanceEnvironment ie =
                    new InstanceEnvironment(ServerManager.ADMINSERVER_ID);
            // copy server.xml from hot to back
            //ie.useManualServerXmlChanges();
            // Reinitialize mbeans
            mDelegate.reloadAfterChange(ie);
            // Set restart needed to true because we do not know whether admin
            // server is already running with the changes in server.xml -- the
            // policy is say restart is needed unless you know otherwise.
            mRestartNeeded = true;
        } catch (ConfigException ce) {
            _logger.log(Level.INFO, "mbean.config.admin.usemanual_failed",
                    ce.getMessage());
            _logger.log(Level.FINEST, ce.getMessage(), ce);
            throw new ServerInstanceException(ce.getLocalizedMessage());
        }
        return mRestartNeeded;