|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.sun.faban.common.Command
public class Command
Represents a command that can be sent to execute on any machine. It allows setting the command behavior before executing the command.
| Field Summary | |
|---|---|
static int |
BULK_LOG
Bulk logging of the stdout or stderr. |
static int |
CAPTURE
Captures the stream in a buffer for later retrieval. |
static int |
STDERR
Stream identifier for standard error output. |
static int |
STDOUT
Stream identifier for standard output. |
static String[] |
STREAM_NAME
String array representing the stream names stdout and stderr. |
static int |
TRICKLE_LOG
Trickle logging logs the stream whenever something is read from the corresponding stream. |
| Constructor Summary | |
|---|---|
Command(List<String> command)
Constructs a command from a pre-prepared list of command and arguments. |
|
Command(String... command)
Constructs a command from a string array passed in as a variable argument list. |
|
Command(String command)
Constructs a command from a command string with default settings. |
|
| Method Summary | |
|---|---|
CommandHandle |
execute()
Executes the command locally on this system. |
CommandHandle |
execute(CommandChecker checker,
Map<String,List<String>> extMap)
Called from the command agent allowing the agent to ensure the command will work in the agent environment. |
CommandHandle |
executeJava(CommandChecker checker,
List<String> extClassPath)
Called from the command agent to execute java allowing the agent to ensure the java command will work in the agent environment. |
String[] |
getEnvironment()
Obtains the current environment this command is set to run. |
byte[] |
getInput()
Obtains the data for the stdin of the command, if set. |
String |
getInputFile()
Obtains the file name to be used as input file to the command. |
Level |
getLogLevel(int streamId)
Obtains the current log level for a certain stream. |
String |
getOutputFile(int streamId)
Obtains the output file name, if set. |
int |
getStreamHandling(int streamId)
Obtains the stream handling mode for a certain stream associated with this command. |
String |
getWorkingDirectory()
Obtains the current working directory this command is set to run. |
boolean |
isDaemon()
Checks whether this command is set to be a daemon or not. |
boolean |
isSynchronous()
Checks whether the command is synchronous, i.e. |
static void |
main(String[] args)
Main is used for testing the command facility. |
static List<String> |
parseArgs(String command)
Parses the command and/or arguments from a command string and puts into a list. |
void |
register(List<CommandHandle> handleList)
Registers the command handle resulting from this command into a list of command handles. |
void |
setDaemon(boolean daemon)
The daemon property determines whether the process spawned from this command will again spawn children that keep outputting to stdout or stderr. |
void |
setEnvironment(String[] env)
Sets the environment variables in which this command should run in the form of name=value. |
void |
setInput(byte[] input)
Sets the data to be sent to stdin of the command. |
void |
setInputFile(String filePath)
Sets the input file for the command. |
void |
setLogLevel(int streamId,
Level level)
Sets the log level to log a certain stream. |
void |
setOutputFile(int streamId,
String fileName)
Directs the command to save the output from the stream to an output file, overwriting the output file if it already exists. |
void |
setOutputFile(int streamId,
String fileName,
boolean append)
Directs the command to save the output from the stream to an output file. |
void |
setStreamHandling(int streamId,
int mode)
Sets the stream handling mode for a certain stream associated with this command. |
void |
setSynchronous(boolean synchronous)
Sets this command to be synchronous. |
void |
setWorkingDirectory(String dir)
Sets the working directory to run this command. |
String |
toString()
Returns a string representation of this command. |
void |
waitMatch(int streamId,
String match)
Waits for the match string to match all or part of the corresponding stream before execute() returns. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final int STDOUT
public static final int STDERR
public static final String[] STREAM_NAME
public static final int BULK_LOG
public static final int TRICKLE_LOG
public static final int CAPTURE
| Constructor Detail |
|---|
public Command(String command)
command - The command stringpublic Command(String... command)
command - The command and argumentspublic Command(List<String> command)
command - List containing the command and arguments| Method Detail |
|---|
public static List<String> parseArgs(String command)
command - The command string.
public String toString()
toString in class Object
public CommandHandle execute(CommandChecker checker,
Map<String,List<String>> extMap)
throws IOException,
InterruptedException
checker - The command checkerextMap - The extended command map for the service/tool, if any
IOException - Error dealing with the stdin, stdout, or stderr
InterruptedException - The execute thread got interrupted.
public CommandHandle executeJava(CommandChecker checker,
List<String> extClassPath)
throws IOException,
InterruptedException
checker - The command checkerextClassPath - The extended classpath for the service/tool, if any
IOException - Error dealing with the stdin, stdout, or stderr
InterruptedException - The execute thread got interrupted.
public CommandHandle execute()
throws IOException,
InterruptedException
IOException - Error dealing with the stdin, stdout, or stderr
InterruptedException - The execute thread got interruptedpublic void setEnvironment(String[] env)
env - The shell environment relevant to this commandpublic String[] getEnvironment()
public void setWorkingDirectory(String dir)
dir - The command's working directory.public String getWorkingDirectory()
public void setSynchronous(boolean synchronous)
synchronous - True if the command shall be synchronouspublic boolean isSynchronous()
public void waitMatch(int streamId,
String match)
streamId - The stream identifier, STDOUT or STDERRmatch - The match string, null if execute shall not wait
public void setLogLevel(int streamId,
Level level)
streamId - The stream identifier, STDOUT or STDERRlevel - The log levelpublic Level getLogLevel(int streamId)
streamId - The stream identifier, STDOUT or STDERR
public void setStreamHandling(int streamId,
int mode)
streamId - The stream identifier, STDOUT or STDERRmode - The stream handling mode, BULK_LOG, TRICKLE_LOG, or CAPTUREpublic int getStreamHandling(int streamId)
streamId - The stream identifier, STDOUT or STDERR
public void setOutputFile(int streamId,
String fileName)
streamId - The stream identifier, STDOUT or STDERRfileName - The target file name on the target machine
public void setOutputFile(int streamId,
String fileName,
boolean append)
streamId - The stream identifier, STDOUT or STDERRfileName - The target file name on the target machineappend - Whether to append to the file or overwrite the filepublic String getOutputFile(int streamId)
streamId - The stream identifier, STDOUT or STDERR
public void setInput(byte[] input)
input - The data bufferpublic byte[] getInput()
public void setInputFile(String filePath)
filePath - The full path of the input file.public String getInputFile()
public void register(List<CommandHandle> handleList)
handleList - The list of command handlespublic void setDaemon(boolean daemon)
daemon - True for spawning daemons that write to stdout/stderrpublic boolean isDaemon()
public static void main(String[] args)
args - The command line arguments
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||