com.continuent.tungsten.replicator.util
Class ProcessHelper

java.lang.Object
  extended by com.continuent.tungsten.replicator.util.ProcessHelper

public class ProcessHelper
extends java.lang.Object

Implements a simple helper to execute operating system processes with consistent logging and handling of errors.

Version:
1.0
Author:
Robert Hodges

Constructor Summary
ProcessHelper()
          Create a new helper.
 
Method Summary
 void configure()
          Configure the helper.
 void exec(java.lang.String description, java.lang.String baseCommand)
          Convenience method to execute a command that is given as a single string.
 void exec(java.lang.String description, java.lang.String[] baseCommand)
          Convenience method to execute command without providing input or output.
 void exec(java.lang.String description, java.lang.String[] baseCommand, java.io.InputStream stdin, java.io.File stdout, java.io.File stderr, boolean stdoutAppend, boolean stderrAppend)
          Execute a command accompanied by a description.
 java.lang.String getCmdPrefix()
           
 java.util.List<java.lang.String> getOutputLines()
           
 java.lang.String[] mergeArrays(java.lang.String[] a1, java.lang.String[] a2)
           
 void setCmdPrefix(java.lang.String cmdPrefix)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ProcessHelper

public ProcessHelper()
Create a new helper.

Method Detail

getCmdPrefix

public java.lang.String getCmdPrefix()

setCmdPrefix

public void setCmdPrefix(java.lang.String cmdPrefix)

configure

public void configure()
Configure the helper. This must called before executing any commands.


exec

public void exec(java.lang.String description,
                 java.lang.String[] baseCommand,
                 java.io.InputStream stdin,
                 java.io.File stdout,
                 java.io.File stderr,
                 boolean stdoutAppend,
                 boolean stderrAppend)
          throws BackupException
Execute a command accompanied by a description. A command prefix such as 'sudo' is added automatically.

Parameters:
description - Text description of the command
baseCommand - Command as an array but without 'sudo' or other prefix
stdin - InputStream for process stdin
stdout - File to receive stdout
stderr - File to receive stderr
stdoutAppend - If true append to stdout file
stderrAppend - If true append to stderr file
Throws:
BackupException - If the command fails

exec

public void exec(java.lang.String description,
                 java.lang.String[] baseCommand)
          throws BackupException
Convenience method to execute command without providing input or output.

Parameters:
description - Text description of the command
baseCommand - Command as an array but without 'sudo' or other prefix
Throws:
BackupException - If the command fails

exec

public void exec(java.lang.String description,
                 java.lang.String baseCommand)
          throws BackupException
Convenience method to execute a command that is given as a single string.

Parameters:
description - Text description of the command
baseCommand - Un-prefixed command; arguments must be space-separate
Throws:
BackupException - If the command fails

mergeArrays

public java.lang.String[] mergeArrays(java.lang.String[] a1,
                                      java.lang.String[] a2)

getOutputLines

public java.util.List<java.lang.String> getOutputLines()