com.atlassian.fisheye.plugins.scm.utils.process
Class ExternalProcess

java.lang.Object
  extended by com.atlassian.fisheye.plugins.scm.utils.process.ExternalProcess
All Implemented Interfaces:
Watchdog

public class ExternalProcess
extends java.lang.Object
implements Watchdog

This class manages the execution of an external process, using separate threads to process the process' IO requirements.


Constructor Summary
ExternalProcess(java.util.List<java.lang.String> command, ProcessHandler handler)
          Process an external command (the command and arguments are given as a list)
ExternalProcess(java.lang.String[] cmdArray, ProcessHandler handler)
          Process an external command.
ExternalProcess(java.lang.String commandLine, ProcessHandler handler)
          Process an external command.
 
Method Summary
 void cancel()
          Cancel should be called if you wish to interrupt process execution.
 void execute()
          Execute the external command.
 void executeWhile(java.lang.Runnable runnable)
          Executes the external command.
 void finish()
          Finish process execution.
 boolean finish(int maxWait)
          Wait a given time for the process to finish
 java.lang.String getCommandLine()
           
 ProcessHandler getHandler()
          Get the process handler for this process execution
 long getTimeoutTime()
           
 boolean isTimedOut()
           
 void resetWatchdog()
           
 void setEnvironment(java.lang.String[] environment)
           
 void setTimeout(long timeout)
           
 void setWorkingDir(java.io.File workingDir)
           
 void start()
          Start the external process and setup the IO pump threads needed to manage the process IO.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ExternalProcess

public ExternalProcess(java.lang.String[] cmdArray,
                       ProcessHandler handler)
Process an external command.

Parameters:
cmdArray - the command and its arguments as separate elements
handler - The handler for this execution. The handler supports the required IO operations

ExternalProcess

public ExternalProcess(java.util.List<java.lang.String> command,
                       ProcessHandler handler)
Process an external command (the command and arguments are given as a list)

Parameters:
command - A list containing the command and its arguments
handler - The process handler to manage the execution of this process.

ExternalProcess

public ExternalProcess(java.lang.String commandLine,
                       ProcessHandler handler)
Process an external command. The command is given as a single command line and parsed into the command and its arguments. Spaces are used as argument delimiters so if any command arguments need to contain spaces, the array or list based constructors should be used.

Parameters:
commandLine - the command and its arguments in a single line. If any arguments need to contain spaces, the array or list based constructors should be used.
handler - The handler for this execution. The handler supports the required IO operations
Method Detail

resetWatchdog

public void resetWatchdog()
Specified by:
resetWatchdog in interface Watchdog

getTimeoutTime

public long getTimeoutTime()

isTimedOut

public boolean isTimedOut()

setWorkingDir

public void setWorkingDir(java.io.File workingDir)

setEnvironment

public void setEnvironment(java.lang.String[] environment)

getHandler

public ProcessHandler getHandler()
Get the process handler for this process execution

Returns:
the ProcessHandler instance associated with this process execution.

start

public void start()
Start the external process and setup the IO pump threads needed to manage the process IO. If you call this method you must eventually call the finish() method. Using this method you may execute additional code between process start and finish.


finish

public void finish()
Finish process execution. This method should be called after you have called the start() method.


execute

public void execute()
Execute the external command. When this method returns, the process handler provided at construction time should be consulted to collect exit code, exceptions, process output, etc.


executeWhile

public void executeWhile(java.lang.Runnable runnable)
Executes the external command. While it is running, the given runnable is executed. The external command is not checked until the runnable completes

Parameters:
runnable - A task to perform while the external command is running.

getCommandLine

public java.lang.String getCommandLine()

finish

public boolean finish(int maxWait)
Wait a given time for the process to finish

Parameters:
maxWait - the maximum amount of time in milliseconds to wait for the process to finish
Returns:
true if the process has finished.

cancel

public void cancel()
Cancel should be called if you wish to interrupt process execution.

Specified by:
cancel in interface Watchdog

setTimeout

public void setTimeout(long timeout)