FileDocCategorySizeDatePackage
ASNativeLauncher.javaAPI DocGlassfish v2 API13484Fri May 04 22:24:30 BST 2007com.sun.enterprise.admin.servermgmt.launch

ASNativeLauncher

public class ASNativeLauncher extends ASLauncher
author
bnevins

Fields Summary
private String
java
private String
classpath
private String
installRoot
private String
instanceName
private String
instanceRoot
private String
processName
private String
returnValue
private String
nativeLauncher
private String
native1
private String
domainName
private String
classname
private File
currDir
private boolean
verbose
private boolean
userSetVerbose
private ArrayList
defines
private ArrayList
command
private ArrayList
args
private String
nativeName
private static final String
installRootTag
private static final String
javaRootTag
private static final String
instanceRootTag
private static final String
instanceNameTag
private static final String
domainNameTag
private static final String
verboseTag
private static final String
processNameTag
private static final String
returnTag
private static final String[]
jars
private static final boolean
debugger
Constructors Summary
public ASNativeLauncher(com.sun.enterprise.admin.servermgmt.pe.PEInstancesManager mgr)

        nativeName = mgr.getNativeName();
        classname = getClass().getSuperclass().getName();
    
Methods Summary
public java.lang.Processlaunch(java.lang.String[] Args, java.lang.String[] SecurityInfo)

        securityInfo = SecurityInfo;
        setArguments(Args);
        setup();
        return launch();
    
private java.lang.Processlaunch()

        ProcessBuilder pb = new ProcessBuilder(command);
        pb.directory(currDir);
        try
        {
            Process process = pb.start();
            ProcessStreamDrainer drainer = ProcessStreamDrainer.redirect("NativeLauncher", process);
            writeSecurityInfoToProcess(process);
          
            
            if (userSetVerbose) 
            {
                // native verbose -- hang here!!
                process.waitFor();
                //drainer.waitFor();
            }

            return process;
        }
        catch(Exception e)
        {
            throw new ASLauncherException(e);
        }
    
private booleanok(java.lang.String s)

        return s != null && s.length() > 0;
    
private booleanok(java.io.File f)

        return f != null && f.exists();
    
private voidsetArguments(java.lang.String[] Args)

        // TODO Bug: "debug" argument causes a JVM.dll not found error?!?
        args = new ArrayList<String>();
        args.add("start");
        args.add("display");
        //args.add("verbose");
        
        for(String arg : Args)
        {
            if("native".equalsIgnoreCase(arg))
                continue;

            // TODO
            if("debug".equalsIgnoreCase(arg))
                continue;

            if("verbose".equalsIgnoreCase(arg))
            {
                userSetVerbose = true;
                args.add(arg);
                continue;
            }
            
            if(args.contains(arg))  // no duplicates!
                continue;

            args.add(arg);
        }
    
private voidsetClasspath()

        classpath = new String();
        
        for(int i = 0; i < jars.length; i++)
        {
            if(i != 0)
                classpath += File.pathSeparator;
            
            classpath += verifyFile(installRoot + "/lib/" + jars[i]);
        }
    
private voidsetCommand()

        //"%AS_INSTALL%/lib/appservLauncher.exe" "%AS_INSTALL%/lib/appservDAS.exe %DOMAIN_NAME%"  "\"%~df0\" %CLI% display" 
        command = new ArrayList<String>();
        
        command.add(nativeLauncher);
        command.add(native1);
        command.add(java);
        command.add("-cp");
        command.add(classpath);
        
        for(String define : defines)
            command.add(define);
        
        command.add(classname);
        //command.add("start");
        //command.add("display");
        
        for(String arg : args)
        {
            command.add(arg);
        }
    
private voidsetCurrDir()

        currDir = new File(verifyFile(instanceRoot + "/config"));
    
private voidsetDefines()

        defines = new ArrayList<String>();
        
        defines.add("-D" + installRootTag + "=" + installRoot);
        defines.add("-D" + instanceRootTag + "=" + instanceRoot);
        defines.add("-D" + instanceNameTag + "=" + instanceName);
        defines.add("-D" + processNameTag + "=" + processName);
        defines.add("-Dcaller=cli");
        
        if(ok(returnValue))
            defines.add("-D" + returnTag + "=" + returnValue);
        
        //defines.add("-Dcom.sun.aas.verboseMode=" + Boolean.toString(verbose));
        if(debugger)
        {
            defines.add("-Xdebug");
            defines.add("-Xnoagent");
            defines.add("-Xrunjdwp:transport=dt_socket,address=5555,suspend=y,server=y");
            defines.add("-Djava.compiler=NONE");
        }
    
private voidsetDomainName()

        // this is used for "appservDAS.exe domainName"
        domainName = System.getProperty(domainNameTag);
    
private voidsetInstallRoot()

       installRoot = System.getProperty(installRootTag);
       installRoot = verifyFile(installRoot);
    
private voidsetInstanceName()

       instanceName = System.getProperty(instanceNameTag);
       
       if(!ok(instanceName))
           instanceName = "server";
    
private voidsetInstanceRoot()

       instanceRoot = System.getProperty(instanceRootTag);
       instanceRoot = verifyFile(instanceRoot);
    
private voidsetJava()

        String javaRoot = System.getProperty(SystemPropertyConstants.JAVA_ROOT_PROPERTY);
        String exeName = OS.isWindows() ? "java.exe" : "java";
        
        java = verifyFile(javaRoot + "/bin/" + exeName);
    
private voidsetNatives()

        String exe = "";
        
        if(OS.isWindows())
            exe = ".exe";
        
        nativeLauncher = verifyFile(installRoot + "/lib/" + "appservLauncher" + exe);
        native1 = verifyFile(installRoot + "/lib/" + nativeName + exe);
    
private voidsetProcessName()

       processName = System.getProperty(processNameTag);
       
       if(!ok(processName))
           processName = "as9-server";
    
private voidsetReturn()

        // do NOT send in a "-D" for this if it isn't already set
       returnValue = System.getProperty(returnTag);
       
       if(!ok(returnValue))
           returnValue = null;
    
private voidsetVerbose()

        // this looks bizarre and kludgy so I'll try to explain.
        // the native code which one does NOT want to touch unless absolutely
        // neccessary (it's a mess) -- will hang forever if "verbose" is passed in as an arg
        // We can't just get rid of it though because PEMain will look for a verbose
        // System Property.  If it does not see this System Property -- then you
        // will never see thread dumps -- which is the whole point of starting with native.
        
        verbose = false;
        
        for(String arg : args)
        {
            if("verbose".equalsIgnoreCase(arg))
            {
                verbose = true;
                return;
            }
        }
    
private voidsetup()

        // don't change the order of these unless you REALLY know what you are
        // doing!!
        setJava();
        setInstallRoot();
        setInstanceRoot();
        setInstanceName();
        setProcessName();
        setReturn();
        setDomainName();
        setClasspath();
        setVerbose();
        setDefines();
        setNatives();
        setCommand();
        setCurrDir();
    
private java.lang.StringverifyFile(java.lang.String s)

        if(!ok(s))
            // TODO
            throw new ASLauncherException("Null filename");
        
        File f = new File(s);
        
        if(!ok(f))
            // TODO
            throw new ASLauncherException("Bad File: " + s);
        
        return FileUtils.safeGetCanonicalPath(f);