| java.lang.Object org.continuent.sequoia.controller.backup.backupers.NativeCommandExec
NativeCommandExec | public class NativeCommandExec (Code) | | This class defines a NativeCommandExec, which abstracts out native command
execution logic into a small and easily verified class that does not have
dependencies on backuper implementations. Once instantiated this class can
execute a series of commands in sequence.
author: Robert Hodges version: 1.0 |
Inner Class :class NativeCommand | |
Method Summary | |
public int | executeNativeCommand(String command, NativeCommandInputSource input, OutputStream output, int timeout, File workingDirectory, boolean ignoreStdErrOutput) Executes a native operating system command expressed as a String. | public int | executeNativeCommand(String command, NativeCommandInputSource input, OutputStream output, int timeout, boolean ignoreStdErrOutput) | public int | executeNativeCommand(String[] commands, NativeCommandInputSource input, OutputStream output, int timeout, File workingDirectory, boolean ignoreStdErrOutput) Executes a native operating system command expressed as an array. | public int | executeNativeCommand(String[] commands, NativeCommandInputSource input, OutputStream output, int timeout, boolean ignoreStdErrOutput) | public ArrayList | getStderr() Returns all stderr from the most recent command. | public ArrayList | getStdout() Returns all stdout from the most recent command. | public void | initOutput() Clears output arrays. | protected void | log(String name, ArrayList outArray) Utility routine to log output. | public void | logErrors() Write process error output to development log. | public void | logOutput() Write process standard output to development log. | protected int | manageCommandExecution(String commandText, Process process, NativeCommandInputSource inputSource, OutputStream output, int timeout, boolean ignoreStdErrOutput) Manages execution of a command once it has been started as a process. | public boolean | safelyExecNativeCommand(String cmd, NativeCommandInputSource input, OutputStream output, int timeout, File workingDirectory, boolean ignoreStdErrOutput) Utility method to execute a native command with careful logging and
coverage of all command outcomes. | public boolean | safelyExecNativeCommand(String cmd, NativeCommandInputSource input, OutputStream output, int timeout, boolean ignoreStdErrOutput) | public boolean | safelyExecNativeCommand(String[] cmds, NativeCommandInputSource input, OutputStream output, int timeout, File workingDirectory, boolean ignoreStdErrOutput) Utility method to execute a native command with careful logging and
coverage of all command outcomes. | public boolean | safelyExecNativeCommand(String[] cmds, NativeCommandInputSource input, OutputStream output, int timeout, boolean ignoreStdErrOutput) | protected boolean | safelyExecNativeCommand0(NativeCommand nc, NativeCommandInputSource input, OutputStream output, int timeout, File workingDirectory, boolean ignoreStdErrOutput) Internal method to execute a native command with careful logging and
coverage of all command outcomes. |
NativeCommandExec | public NativeCommandExec()(Code) | | Creates a new NativeCommandExec object
|
executeNativeCommand | public int executeNativeCommand(String command, NativeCommandInputSource input, OutputStream output, int timeout, File workingDirectory, boolean ignoreStdErrOutput) throws IOException, InterruptedException(Code) | | Executes a native operating system command expressed as a String.
Parameters: command - String of command to execute Parameters: input - Native command input Parameters: output - Optional output to catch standard out Parameters: timeout - Time in seconds to await command (0 = forever) Parameters: workingDirectory - working directory for the command (null to inheritfrom Sequoia working dir) Parameters: ignoreStdErrOutput - true if output on std error should be ignored,else any output on stderr will be considered as a failure 0 if successful, any number otherwise exception: IOException - if an I/O error occurs throws: InterruptedException - If there is a timeout failure |
executeNativeCommand | public int executeNativeCommand(String[] commands, NativeCommandInputSource input, OutputStream output, int timeout, File workingDirectory, boolean ignoreStdErrOutput) throws IOException, InterruptedException(Code) | | Executes a native operating system command expressed as an array.
Parameters: commands - Array of strings (command + args) to execute Parameters: input - Native command input Parameters: output - Command output stream Parameters: timeout - Time in seconds to await command (0 = forever) Parameters: workingDirectory - working directory for the command (null to inheritfrom Sequoia working dir) Parameters: ignoreStdErrOutput - true if output on std error should be ignored,else any output on stderr will be considered as a failure 0 if successful, any number otherwise exception: IOException - if an I/O error occurs throws: InterruptedException - If there is a timeout failure |
getStderr | public ArrayList getStderr()(Code) | | Returns all stderr from the most recent command.
stderr contents (may be truncated) |
getStdout | public ArrayList getStdout()(Code) | | Returns all stdout from the most recent command.
stdout contents (may be truncated) |
initOutput | public void initOutput()(Code) | | Clears output arrays.
|
log | protected void log(String name, ArrayList outArray)(Code) | | Utility routine to log output.
Parameters: name - Output type e.g., stdout or stderr Parameters: outArray - List of lines of output |
logErrors | public void logErrors()(Code) | | Write process error output to development log.
|
logOutput | public void logOutput()(Code) | | Write process standard output to development log.
|
manageCommandExecution | protected int manageCommandExecution(String commandText, Process process, NativeCommandInputSource inputSource, OutputStream output, int timeout, boolean ignoreStdErrOutput) throws InterruptedException(Code) | | Manages execution of a command once it has been started as a process.
Parameters: commandText - The command text for logging messages Parameters: process - The process object used to manage the command Parameters: inputSource - Input source object or null if no input Parameters: output - Optional output stream to catch standard out Parameters: timeout - Time in seconds to await command (0 = forever) Parameters: ignoreStdErrOutput - true if output on std error should be ignored,else any output on stderr will be considered as a failure 0 if successful, any number otherwise throws: InterruptedException - If there is a timeout failure |
safelyExecNativeCommand | public boolean safelyExecNativeCommand(String cmd, NativeCommandInputSource input, OutputStream output, int timeout, File workingDirectory, boolean ignoreStdErrOutput)(Code) | | Utility method to execute a native command with careful logging and
coverage of all command outcomes.
Parameters: cmd - Command string Parameters: input - Array containing lines of input Parameters: output - Optional output stream to catch data written to standardoutput Parameters: timeout - Timeout in seconds (0 = infinite) Parameters: workingDirectory - working directory for the command (null to inheritfrom Sequoia working dir) Parameters: ignoreStdErrOutput - true if output on std error should be ignored,else any output on stderr will be considered as a failure true if command is successful |
safelyExecNativeCommand | public boolean safelyExecNativeCommand(String[] cmds, NativeCommandInputSource input, OutputStream output, int timeout, File workingDirectory, boolean ignoreStdErrOutput)(Code) | | Utility method to execute a native command with careful logging and
coverage of all command outcomes.
Parameters: cmds - Command array Parameters: input - Input source for native command Parameters: output - Optional output stream to catch data written to standardoutput Parameters: timeout - Timeout in seconds (0 = infinite) Parameters: workingDirectory - working directory for the command (null to inheritfrom Sequoia working dir) Parameters: ignoreStdErrOutput - true if output on std error should be ignored,else any output on stderr will be considered as a failure true if command is successful |
safelyExecNativeCommand0 | protected boolean safelyExecNativeCommand0(NativeCommand nc, NativeCommandInputSource input, OutputStream output, int timeout, File workingDirectory, boolean ignoreStdErrOutput)(Code) | | Internal method to execute a native command with careful logging and
coverage of all command outcomes. This method among other things logs
output fully in the event of a failure.
Parameters: cmd - Command holder object Parameters: input - Command input source Parameters: output - Optional output stream to catch data written to standardoutput Parameters: timeout - Timeout in seconds (0 = infinite) Parameters: workingDirectory - working directory for the command (null to inheritfrom Sequoia working dir) Parameters: ignoreStdErrOutput - true if output on std error should be ignored,else any output on stderr will be considered as a failure true if command is successful |
|
|