FileDocCategorySizeDatePackage
InstanceDefinition.javaAPI DocGlassfish v2 API16688Fri May 04 22:35:00 BST 2007com.sun.enterprise.instance

InstanceDefinition

public class InstanceDefinition extends Object
A class that defines the Server Instance so that it can be created. Identifies all the required attributes of an (iAS) Instance. Depends upon the value of Install Root ie. "com.sun.aas.instanceRoot"

Fields Summary
public static final int
DEFAULT_PORT
public static final int
DEFAULT_JMS_PORT
public static final String
DEFAULT_JMS_USER
public static final String
DEFAULT_JMS_PW
public static final String
SPACE
public static final String
WINDOWS_BIN_EXT
public static final String
BIN_DIR_NAME
public static final String
LIB_DIR_NAME
private String
mJavaHome
private String
mImqHome
private String
mServerName
private int
mHttpPort
private String
mIdentifier
private String
mMailHost
private String
mUser
private String
mDocRoot
private String
mPortString
private int
mJMSPort
private String
mJMSPortString
private String
mJMSUser
private String
mJMSPasswd
public static final String
UNIX_START_COMMAND_NAME
public static final String
UNIX_STOP_COMMAND_NAME
public static final String
UNIX_GETTOKENS_COMMAND_NAME
public static final String
UNIX_RESTART_COMMAND_NAME
public static final String
WIN_START_COMMAND_NAME
public static final String
WIN_STOP_COMMAND_NAME
public static final String
WIN_GETTOKENS_COMMAND_NAME
public final String
JMS_NODE_PATH
Constructors Summary
public InstanceDefinition(String serverName, int httpPort, String identifier, String mailHost, String user, String docRoot, int jmsPort, String jmsUser, String jmsPasswd)
Creates new InstanceDefinition.

param
serverName String representing the fully qualified hostName e.g. www.sun.com
param
httpPort is integer specifying port at which this server should start listening to requests.
param
identifier String that is the server-id e.g. prod_server.
param
mailHost is the name of the mail host.
param
user is the name of user with which we can start this instance. (Unix/Linux)
param
docRoot is the absolute location for the webserver docroot.
param
jmsPort integer represeting the port of jms-service.
param
jmsUser user name to connect to the jms-service.
param
jmsPasswd password to connect to the jms-service.


	 		  		         		              		        		        		              		         		       		        		       	
	
         
		       
              
		initialize(serverName, httpPort, identifier, mailHost, user, docRoot,
                   jmsPort, jmsUser, jmsPasswd);
    
public InstanceDefinition(String id, int port)
Creates new InstanceDefinition with the given parameters.

param
id String representing the unique id of the server. (e.g. prod_server)
param
port is the HTTP port. Note that the servername would default to the local machine's IP address, mailhost will default to the "localhost", server user will default to current user and docroot will default to /docs

        if (id == null || port <= 0)
            throw new IllegalArgumentException(Localizer.getValue(ExceptionType.ILLEGAL_PORT));
		String serverName	= createLocalHostName();
		String mailHost		= createLocalHostName();
		String user			= System.getProperty("user.name");
		String docRoot		= ServerManager.INSTANCE_CFG_ROOT
                + "/" + ServerManager.DOC_DIR_NAME;
		initialize(serverName, port, id, mailHost, user, docRoot,
                   DEFAULT_JMS_PORT, DEFAULT_JMS_USER, DEFAULT_JMS_PW);
	
Methods Summary
private java.lang.StringcreateLocalHostName()

		try {
			return InetAddress.getLocalHost().getHostName();
		}
		catch(UnknownHostException ue) {
		  return "localhost";
		}
	
public java.lang.StringgetAdminJavaHome()

        ConfigContext configContext;
        InstanceEnvironment instanceEnvironment = 
               new InstanceEnvironment(ServerManager.ADMINSERVER_ID);
        String fileUrl  = instanceEnvironment.getConfigFilePath();
        configContext   = ConfigFactory.createConfigContext(fileUrl);
        ConfigBean configbean = ConfigBeansFactory.getConfigBeanByXPath(
                configContext, ServerXPathHelper.XPATH_JAVACONFIG);
        mJavaHome = configbean.getAttributeValue(ServerTags.JAVA_HOME);
        return mJavaHome;
    
private java.lang.String[]getCompleteNonWindowsStartCommand()

        String[] names = new String[] {
            System.getProperty(Constants.IAS_ROOT),     /* upto domain */
            BIN_DIR_NAME,                               /* "bin" */
            UNIX_START_COMMAND_NAME                     /* "startserv" */
        };
        String programName = StringUtils.makeFilePath(names, false);
        
        return ( new String[]{programName} );
    
private java.lang.String[]getCompleteWindowsStartCommand()
Returns the windows start command. Note that it is [install-root]/bin/startsec.exe.


        String[] names = new String[] {
            System.getProperty(Constants.INSTALL_ROOT), /* install-root */
            BIN_DIR_NAME,                               /* "bin" */
            WIN_START_COMMAND_NAME                      /* "startsec.exe" */
        };
        String programName = StringUtils.makeFilePath(names, false);

        /* startsec requires server-id as the first(only) parameter */

        return ( new String[] {
            programName,                                /* path to strtsec */
            mIdentifier,                                /* "server-id" */
            System.getProperty(Constants.IAS_ROOT),     /* path to domain root */
        } );
    
public java.lang.StringgetDocRoot()

        return ( mDocRoot );
    
public java.lang.String[]getGetSecurityTokensCommand()
Returns the complete path of the gettokens command for getting security tokens of this instance. It returns the array of Strings which form the complete command line.

return
String[] representing getSecurityTokensCommand

		String[] command = null;
        String onlyCommand = null;
		if (OS.isWindows()) {
            onlyCommand = getWindowsSecTokensCommand();
        }
		else {
            onlyCommand = getNonWindowsSecTokensCommand();
		}
        
        command = new String[] {
            onlyCommand,                                /* path of gettokens     */
            mIdentifier,                                /* "instance-id": param1 */
            System.getProperty(Constants.IAS_ROOT),     /* path to domain root */
        };
		return ( command );
	
public java.lang.StringgetID()

		return mIdentifier;
	
private java.lang.StringgetNonWindowsSecTokensCommand()

        String[] names = new String[] {
            System.getProperty(Constants.INSTALL_ROOT),     /* install-root */
            LIB_DIR_NAME,                                   /* "lib"        */
            UNIX_GETTOKENS_COMMAND_NAME                     /* "gettokens" */ 
        };

        return ( StringUtils.makeFilePath(names, false) );
    
public intgetPort()

        return mHttpPort;
    
public java.lang.String[]getRestartCommand()
Returns the complete path of the restart script for restarting this instance. Note that it returns the platform-specific string that could be exec'ed.

return
String representing path of restart command for this instance.

        if (OS.isWindows()) {
            throw new UnsupportedOperationException(Localizer.getValue(ExceptionType.ILLEGAL_RESTART));
        }
        String[] restartCommand = new String[1];

		String[] names = new String[] { 
            System.getProperty(Constants.IAS_ROOT),             /* upto a domain */
            BIN_DIR_NAME,                                       /* "bin" */
            UNIX_RESTART_COMMAND_NAME                           /* "restartserv" */
        };
		restartCommand[0] = StringUtils.makeFilePath(names, false);

		return ( restartCommand );
	
public java.lang.StringgetServerName()

        return mServerName;
    
public java.lang.String[]getStartCommand()
Returns the complete path of the start command for starting this instance. Note that it returns the platform-specific string that could be exec'ed.

return
String representing path of start command for this instance.

		String[] startCommand = null;
        /* Note that for windows, the startup executable is stored
           at the install-root - one per installation. startsec.exe
           just takes the instance name as the only parameter.
        */
		if (OS.isWindows()) {
            startCommand = getCompleteWindowsStartCommand();
		}
		else {
        /* Note that for non-windows platforms, the startup executable is stored
           at the instance directory - one per instance. startserv
           script does not take any parameter.
        */
            startCommand = getCompleteNonWindowsStartCommand();
		}
		return ( startCommand );
	
public java.lang.String[]getStopCommand()
Returns the complete path of the stop command for stopping this instance. Note that it returns the platform-specific string that could be exec'ed.

return
String representing path of stop command for this instance.

		String[] stopCommand    = new String[1];

        String command          = null; 
		if (OS.isWindows()) {
			command = WIN_STOP_COMMAND_NAME;
		}
		else {
			command = UNIX_STOP_COMMAND_NAME;
		}
        String[] names = new String[] {
            System.getProperty(Constants.IAS_ROOT),     /*upto a domain */
            BIN_DIR_NAME,                               /* "bin"        */
            command                                     /* "stopserv" or "stopserv.bat"*/
        };

		stopCommand[0] = StringUtils.makeFilePath(names, false);
		
		return ( stopCommand );
	
public java.lang.StringgetUser()
Getter for the instance-user instance variable.

        return mUser;
    
private java.lang.StringgetWindowsSecTokensCommand()

        String[] names = new String[] {
            System.getProperty(Constants.INSTALL_ROOT),     /* install-root */
            BIN_DIR_NAME,                                   /* "bin"        */
            WIN_GETTOKENS_COMMAND_NAME                      /* "gettokens.exe" */
        }; 

        return ( StringUtils.makeFilePath(names, false) );
    
private voidinitialize(java.lang.String serverName, int httpPort, java.lang.String identifier, java.lang.String mailHost, java.lang.String user, java.lang.String docRoot, int jmsPort, java.lang.String jmsUser, java.lang.String jmsPasswd)

        if (serverName  == null||   identifier  == null||
            mailHost    == null||   user        == null||
            user        == null||   docRoot     == null|| 
            jmsUser     == null||   jmsPasswd   == null ) {
            throw new IllegalArgumentException();
        }
        if (httpPort <= 0 || jmsPort <= 0) {
            throw new IllegalArgumentException();
        }
		mServerName		= serverName;
		mHttpPort		= httpPort;
		mIdentifier		= identifier;
		mMailHost		= mailHost;
		mUser			= user;
		mDocRoot		= docRoot;
		mPortString		= "" + mHttpPort;
        mJMSPort        = jmsPort;
        mJMSPortString  = jmsPort +"";
        mJMSUser        = jmsUser;
        mJMSPasswd      = jmsPasswd;
	
public voidsetUser(java.lang.String user)
Sets the user (owner) of the instance.

        if ((user != null) && (user.length() > 0))
        {
            mUser = user;
        }
    
public java.lang.StringtoString()
Overridden definition of toString for this Instance Definition. Shows the ServerName, Port, Identifier, MailHostName, User and Doc Root for the instance.

		StringBuffer sb = new StringBuffer();
		sb.append(mServerName);
		sb.append(SPACE + mPortString);
		sb.append(SPACE + mIdentifier);
		sb.append(SPACE + mMailHost);
		sb.append(SPACE + mUser);
		sb.append(SPACE + mDocRoot);
		
		return ( sb.toString() );