org.rhq.core.system
Class ProcessExecution

java.lang.Object
  extended by org.rhq.core.system.ProcessExecution

public class ProcessExecution
extends Object

Provides information on what process to execute and how to execute it.

See Also:
JavaSystemInfo.executeProcess(ProcessExecution), ProcessExecutionUtility

Constructor Summary
ProcessExecution(String executable)
          Constructor for ProcessExecution that defines the full path to the executable that will be run.
 
Method Summary
 List<String> getArguments()
          Obtain the optional set of arguments to the executable as List.
 String[] getArgumentsAsArray()
          Obtain the optional set of arguments to the executable as String array
 Map<String,String> getEnvironmentVariables()
           
 String[] getEnvironmentVariablesAsArray()
          Returns a copy of this ProcessExecution's environment variables as an array of "name=value" Strings.
 String getExecutable()
           
 long getWaitForCompletion()
           
 String getWorkingDirectory()
           
 boolean isCaptureOutput()
           
 boolean isCheckExecutableExists()
          If true, then the executable should first be checked for its existence.
 boolean isKillOnTimeout()
           
 void setArguments(List<String> arguments)
          Sets an optional set of arguments to pass to the executable.
 void setArguments(String[] arguments)
          Sets an optional set of arguments to pass to the executable.
 void setCaptureOutput(boolean captureOutput)
          If true, the process's output will be captured and returned in the results.
 void setCheckExecutableExists(boolean checkExecutableExists)
           
 void setEnvironmentVariables(Map<String,String> environmentVariables)
          Sets an optional set of environment variables to pass to the process.
 void setExecutable(String executable)
          Sets the full path to the executable that will be run.
 void setKillOnTimeout(boolean killOnTimeout)
          If true, then the process will be forcibly killed if it doesn't exit within the wait time.
 void setWaitForCompletion(long waitForCompletion)
          The time, in milliseconds, to wait for the process to exit (will not wait if 0 or less).
 void setWorkingDirectory(String workingDirectory)
          If not null, will be the working directory of the new process (if null, the new process's working directory will be the current working directory of caller).
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ProcessExecution

public ProcessExecution(String executable)
Constructor for ProcessExecution that defines the full path to the executable that will be run. See the other setter methods in this class for the additional things you can set when executing a process.

Parameters:
executable - the full path to the executable that will be run
Method Detail

getExecutable

@NotNull
public String getExecutable()

setExecutable

public void setExecutable(@NotNull
                          String executable)
Sets the full path to the executable that will be run.

Parameters:
executable - the full path to the executable that will be run

getArguments

@Nullable
public List<String> getArguments()
Obtain the optional set of arguments to the executable as List.

Returns:
List of arguments or null if no arguments are set.

getArgumentsAsArray

@Nullable
public String[] getArgumentsAsArray()
Obtain the optional set of arguments to the executable as String array

Returns:
Array of arguments or null if no arguments are set.

setArguments

public void setArguments(@Nullable
                         List<String> arguments)
Sets an optional set of arguments to pass to the executable.

Parameters:
arguments - an optional set of arguments to pass to the executable

setArguments

public void setArguments(@Nullable
                         String[] arguments)
Sets an optional set of arguments to pass to the executable.

Parameters:
arguments - an optional set of arguments to pass to the executable

getEnvironmentVariables

@Nullable
public Map<String,String> getEnvironmentVariables()

getEnvironmentVariablesAsArray

@Nullable
public String[] getEnvironmentVariablesAsArray()
Returns a copy of this ProcessExecution's environment variables as an array of "name=value" Strings. Note, since the array is only a copy of the environmentVariables property, modifications made to it will have no effect on this ProcessExecution.

Returns:
a copy of this ProcessExecution's environment variables as an array of "name=value" Strings

setEnvironmentVariables

public void setEnvironmentVariables(@Nullable
                                    Map<String,String> environmentVariables)
Sets an optional set of environment variables to pass to the process. If null, the new process will inherit the environment of the caller.

Parameters:
environmentVariables - an optional set of environment variables to pass to the process

getWorkingDirectory

@Nullable
public String getWorkingDirectory()

setWorkingDirectory

public void setWorkingDirectory(@Nullable
                                String workingDirectory)
If not null, will be the working directory of the new process (if null, the new process's working directory will be the current working directory of caller).

Parameters:
workingDirectory - The directory the process should get as working directory.

getWaitForCompletion

public long getWaitForCompletion()

setWaitForCompletion

public void setWaitForCompletion(long waitForCompletion)
The time, in milliseconds, to wait for the process to exit (will not wait if 0 or less).

Parameters:
waitForCompletion - The wait time in ms.

isCaptureOutput

public boolean isCaptureOutput()

setCaptureOutput

public void setCaptureOutput(boolean captureOutput)
If true, the process's output will be captured and returned in the results. This may be ignored if waitForCompletion is 0 or less. Be careful setting this to true, you must ensure that the process will not write a lot of output - you might run out of memory if the process is a long-lived daemon process that outputs a lot of log messages, for example. By default, output is *not* captured.

Parameters:
captureOutput - whether or not this process's output (stdout+stderr) should be captured and returned in the results

isKillOnTimeout

public boolean isKillOnTimeout()

setKillOnTimeout

public void setKillOnTimeout(boolean killOnTimeout)
If true, then the process will be forcibly killed if it doesn't exit within the wait time. If false, the process will be allowed to continue to run for as long as it needs - getWaitForCompletion() will only force the caller to "wake up" and not block waiting for the process to finish.

Parameters:
killOnTimeout - Should the process be killed after the timeout timed out?

isCheckExecutableExists

public boolean isCheckExecutableExists()
If true, then the executable should first be checked for its existence. If the executable does not exist, the execution should fail-fast. If false, the process will attempt to be executed no matter what. This will allow the operating system to check its executable PATH to find the executable as necessary.

Returns:
check flag (default is true)

setCheckExecutableExists

public void setCheckExecutableExists(boolean checkExecutableExists)

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2008-2009 RHQ Project Advisory Board (Red Hat, Inc.). All Rights Reserved.