com.sun.enterprise.util
Class ProcessExecutor

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

public class ProcessExecutor
extends java.lang.Object

Version:
1.0
Author:
Kedar

Field Summary
static long kDefaultTimeoutMillis
           
static long kSleepTime
           
protected  java.lang.String[] mCmdStrings
           
protected  java.io.File mErrFile
           
protected  java.io.File mOutFile
           
 
Constructor Summary
ProcessExecutor(java.lang.String[] cmd)
          Creates new ProcessExecutor
ProcessExecutor(java.lang.String[] cmd, long timeoutSeconds)
          Creates new ProcessExecutor
ProcessExecutor(java.lang.String[] cmd, long timeoutSeconds, java.lang.String[] inputLines)
           
ProcessExecutor(java.lang.String[] cmd, long timeoutSeconds, java.lang.String[] inputLines, java.lang.String[] env, java.io.File workingDir)
          Creates a new ProcessExecutor that executes the given command.
ProcessExecutor(java.lang.String[] cmd, java.lang.String[] inputLines)
          Creates new ProcessExecutor
 
Method Summary
 void execute()
           
 java.lang.String[] execute(boolean bReturnOutputLines)
           
 java.lang.String[] execute(boolean bReturnOutputLines, boolean bStartUpTimeLimit)
           
protected  java.lang.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  java.lang.String getFileBuffer(java.io.File file)
          Returns the contents of a file as a String.
 java.lang.String getLastExecutionError()
          Returns the last LAST_BYTES bytes in the error stream of last execution as a String, if the ProcessExecutor was configured properly.
 java.lang.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  java.lang.String getLatestOutput(java.io.File f)
           
 int getProcessExitValue()
          Get the exit value of the process executed.
 java.lang.Process getSubProcess()
           
static void main(java.lang.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 java.lang.String[] mCmdStrings

mOutFile

protected java.io.File mOutFile

mErrFile

protected java.io.File mErrFile
Constructor Detail

ProcessExecutor

public ProcessExecutor(java.lang.String[] cmd)
Creates new ProcessExecutor


ProcessExecutor

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


ProcessExecutor

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


ProcessExecutor

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

ProcessExecutor

public ProcessExecutor(java.lang.String[] cmd,
                       long timeoutSeconds,
                       java.lang.String[] inputLines,
                       java.lang.String[] env,
                       java.io.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 java.lang.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 java.lang.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 java.lang.String[] execute(boolean bReturnOutputLines)
                           throws ExecException
Throws:
ExecException

getExceptionMessage

protected java.lang.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 java.lang.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 java.lang.String getFileBuffer(java.io.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 java.lang.String getLatestOutput(java.io.File f)

retainBuffers

public void retainBuffers()

getSubProcess

public java.lang.Process getSubProcess()

main

public static void main(java.lang.String[] args)


Copyright © 2012 GlassFish Community. All Rights Reserved.