com.sun.faban.harness.tools
Class ToolContext

java.lang.Object
  extended by com.sun.faban.harness.tools.MasterToolContext
      extended by com.sun.faban.harness.tools.ToolContext
All Implemented Interfaces:
Serializable

public class ToolContext
extends MasterToolContext

This class is a subclass of MasterToolContext.

Author:
Sheetal Patil
See Also:
Serialized Form

Constructor Summary
ToolContext(String tool, ServiceContext ctx, ToolDescription desc, ToolWrapper wrapper)
          Constructs the tool context.
 
Method Summary
 CommandHandle exec(Command cmd, boolean useOutput)
          Executes a command, optionally use the stdout from this command as the tool output.
 CommandHandle exec(Command cmd, boolean useOutput, int stream)
          Executes a command, optionally use the stdout or stderr from this command as the tool output.
 String getOutputFile()
          Returns name of output file.
 ServiceContext getServiceContext()
          Returns ServiceContext for the tool.
 String getServiceProperty(String key)
          Obtains the service property for the given key.
 String getTmpDir()
          Obtains the temporary directory to be used for storing temporary files.
 List<String> getToolArgs()
          Returns list of tool arguments.
 String getToolName()
          Returns tool name.
 int getToolStatus()
          Returns tool status.
 CommandHandle java(Command cmd, boolean useOutput)
          Executes a command, optionally use the stdout from this command as the tool output.
 CommandHandle java(Command cmd, boolean useOutput, int stream)
          Executes a command, optionally use the stdout or stderr from this command as the tool output.
 void setOutputFile(String path)
          Sets the output file with the given path.
 void setOutputStream(CommandHandle handle)
          Sets the stdout from a command to be used as the tool output.
 void setOutputStream(CommandHandle handle, int stream)
          Sets the stdout or stderr from a command to be used as the tool output.
 
Methods inherited from class com.sun.faban.harness.tools.MasterToolContext
equals, getTool, getToolDescription, getToolId, getToolParams, getToolServiceContext, hashCode
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ToolContext

public ToolContext(String tool,
                   ServiceContext ctx,
                   ToolDescription desc,
                   ToolWrapper wrapper)
Constructs the tool context.

Parameters:
tool - The tool name
ctx - The service context, if any
desc - The tool description
wrapper - The tool wrapper responsible for invoking the tool.
Method Detail

getToolStatus

public int getToolStatus()
Returns tool status.

Returns:
tool status as String

getToolName

public String getToolName()
Returns tool name.

Returns:
tool name as String

getToolArgs

public List<String> getToolArgs()
Returns list of tool arguments.

Returns:
list of tool args

getOutputFile

public String getOutputFile()
Returns name of output file.

Returns:
output file name

setOutputFile

public void setOutputFile(String path)
Sets the output file with the given path.

Parameters:
path - The output file path.

getServiceProperty

public String getServiceProperty(String key)
Obtains the service property for the given key.

Parameters:
key - The service property name
Returns:
property as string

getServiceContext

public ServiceContext getServiceContext()
Returns ServiceContext for the tool.

Returns:
ServiceContext The service context

exec

public CommandHandle exec(Command cmd,
                          boolean useOutput)
                   throws IOException,
                          InterruptedException
Executes a command, optionally use the stdout from this command as the tool output. This is a convenience method for automatically setting the output. It otherwise has the same functionality as RunContext.exec().

Parameters:
cmd - The command to execute
useOutput - Whether to use the output from this command
Returns:
The command handle to this command
Throws:
IOException - The command failed to execute
InterruptedException - Interrupted waiting for the command

exec

public CommandHandle exec(Command cmd,
                          boolean useOutput,
                          int stream)
                   throws IOException,
                          InterruptedException
Executes a command, optionally use the stdout or stderr from this command as the tool output. This is a convenience method for automatically setting the output. It otherwise has the same functionality as RunContext.exec().

Parameters:
cmd - The command to execute
useOutput - Whether to use the output from this command
stream - The stream to use as the output, STDOUT or STDERR
Returns:
The command handle to this command
Throws:
IOException - The command failed to execute
InterruptedException - Interrupted waiting for the command

java

public CommandHandle java(Command cmd,
                          boolean useOutput)
                   throws IOException,
                          InterruptedException
Executes a command, optionally use the stdout from this command as the tool output. This is a convenience method for automatically setting the output. It otherwise has the same functionality as RunContext.exec().

Parameters:
cmd - The command to execute
useOutput - Whether to use the output from this command
Returns:
The command handle to this command
Throws:
IOException - The command failed to execute
InterruptedException - Interrupted waiting for the command

java

public CommandHandle java(Command cmd,
                          boolean useOutput,
                          int stream)
                   throws IOException,
                          InterruptedException
Executes a command, optionally use the stdout or stderr from this command as the tool output. This is a convenience method for automatically setting the output. It otherwise has the same functionality as RunContext.exec().

Parameters:
cmd - The command to execute
useOutput - Whether to use the output from this command
stream - The stream to use as the output, STDOUT or STDERR
Returns:
The command handle to this command
Throws:
IOException - The command failed to execute
InterruptedException - Interrupted waiting for the command

setOutputStream

public void setOutputStream(CommandHandle handle)
Sets the stdout from a command to be used as the tool output.

Parameters:
handle - The command handle to the command to capture.

setOutputStream

public void setOutputStream(CommandHandle handle,
                            int stream)
Sets the stdout or stderr from a command to be used as the tool output.

Parameters:
handle - The command handle to the command to capture
stream - The stream to use as the output, STDOUT or STDERR

getTmpDir

public String getTmpDir()
Obtains the temporary directory to be used for storing temporary files.

Returns:
Name of the temporary directory