com.sun.enterprise.util
Class ProcessExecutor

java.lang.Object
  extended by com.sun.enterprise.util.ProcessExecutor

public class ProcessExecutor
extends Object

Version:
1.0
Author:
Kedar

Field Summary
static long kDefaultTimeoutMillis
           
static long kSleepTime
           
protected  String[] mCmdStrings
           
protected  File mErrFile
           
protected  File mOutFile
           
 
Constructor Summary
ProcessExecutor(String[] cmd)
          Creates new ProcessExecutor
ProcessExecutor(String[] cmd, long timeoutSeconds)
          Creates new ProcessExecutor
ProcessExecutor(String[] cmd, long timeoutSeconds, String[] inputLines)
           
ProcessExecutor(String[] cmd, long timeoutSeconds, String[] inputLines, String[] env, File workingDir)
          Creates a new ProcessExecutor that executes the given command.
ProcessExecutor(String[] cmd, String[] inputLines)
          Creates new ProcessExecutor
 
Method Summary
 void execute()
           
 String[] execute(boolean bReturnOutputLines)
           
 String[] execute(boolean bReturnOutputLines, boolean bStartUpTimeLimit)
           
protected  String getExceptionMessage()
          Allows a subclass to control the error message returned when a non-zero exit code is returned from a failed execution
 boolean getExecutionRetentionFlag()
           
protected  String getFileBuffer(File file)
          Returns the contents of a file as a String.
 String getLastExecutionError()
          Returns the last LAST_BYTES bytes in the error stream of last execution as a String, if the ProcessExecutor was configured properly.
 String getLastExecutionOutput()
          Returns the last LAST_BYTES bytes in the output stream of last execution as a String, if the ProcessExecutor was configured properly.
protected  String getLatestOutput(File f)
           
 int getProcessExitValue()
          Get the exit value of the process executed.
 Process getSubProcess()
           
static void main(String[] args)
           
 void retainBuffers()
           
 void setExecutionRetentionFlag(boolean s)
          This is the setting after the fact that an instance of ProcessExecutor is created.
 void setVerbose(boolean verbose)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

kDefaultTimeoutMillis

public static final long kDefaultTimeoutMillis
See Also:
Constant Field Values

kSleepTime

public static final long kSleepTime
See Also:
Constant Field Values

mCmdStrings

protected String[] mCmdStrings

mOutFile

protected File mOutFile

mErrFile

protected File mErrFile
Constructor Detail

ProcessExecutor

public ProcessExecutor(String[] cmd)
Creates new ProcessExecutor


ProcessExecutor

public ProcessExecutor(String[] cmd,
                       String[] inputLines)
Creates new ProcessExecutor


ProcessExecutor

public ProcessExecutor(String[] cmd,
                       long timeoutSeconds)
Creates new ProcessExecutor


ProcessExecutor

public ProcessExecutor(String[] cmd,
                       long timeoutSeconds,
                       String[] inputLines)

ProcessExecutor

public ProcessExecutor(String[] cmd,
                       long timeoutSeconds,
                       String[] inputLines,
                       String[] env,
                       File workingDir)
Creates a new ProcessExecutor that executes the given command.

Parameters:
cmd - String that has command name and its command line arguments
timeoutSeconds - long integer timeout to be applied in seconds. After this time if the process to execute does not end, it will be destroyed.
Method Detail

setExecutionRetentionFlag

public void setExecutionRetentionFlag(boolean s)
This is the setting after the fact that an instance of ProcessExecutor is created. This is to be used in case the output and error of the last execute call has to be retained for latter analysis.

Parameters:
s - boolean representing whether to retain, true means the buffers will be retained, false otherwise.

getExecutionRetentionFlag

public boolean getExecutionRetentionFlag()

getLastExecutionError

public String getLastExecutionError()
Returns the last LAST_BYTES bytes in the error stream of last execution as a String, if the ProcessExecutor was configured properly. It may return null if the retentionFlag is set to false.


getLastExecutionOutput

public String getLastExecutionOutput()
Returns the last LAST_BYTES bytes in the output stream of last execution as a String, if the ProcessExecutor was configured properly. It may return null if the retentionFlag is set to false.


execute

public void execute()
             throws ExecException
Throws:
ExecException

execute

public String[] execute(boolean bReturnOutputLines)
                 throws ExecException
Throws:
ExecException

getExceptionMessage

protected String getExceptionMessage()
Allows a subclass to control the error message returned when a non-zero exit code is returned from a failed execution

Returns:

execute

public String[] execute(boolean bReturnOutputLines,
                        boolean bStartUpTimeLimit)
                 throws ExecException
Throws:
ExecException

getProcessExitValue

public int getProcessExitValue()
Get the exit value of the process executed. If this method is called before process execution is complete (i.e. before execute() method has returned, it will return -1. If sub process is terminated at timeout, the method will return -255


setVerbose

public void setVerbose(boolean verbose)

getFileBuffer

protected String getFileBuffer(File file)
Returns the contents of a file as a String. It never returns a null. If the file is empty, an empty string is returned.

Parameters:
file - the file to read

getLatestOutput

protected String getLatestOutput(File f)

retainBuffers

public void retainBuffers()

getSubProcess

public Process getSubProcess()

main

public static void main(String[] args)


Copyright © 2012 GlassFish Community. All Rights Reserved.