gov.sandia.cognition.io
Class ProcessLauncher

java.lang.Object
  extended by java.lang.Thread
      extended by gov.sandia.cognition.io.ProcessLauncher
All Implemented Interfaces:
Runnable

public class ProcessLauncher
extends Thread

Launches a process as a separate thread and monitors the stdout and stderr, throwing events when they update and exit

Since:
1.0
Author:
Kevin R. Dixon

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
ProcessLauncher(String command)
          Creates a new instance of ProcessLauncher
 
Method Summary
 void addListener(ProcessLauncherListener listener)
          Adds the listener to the event queue
 String getActualCommand()
          Getter for actualCommand
 Process getProcess()
          Getter for process
 void removeListener(ProcessLauncherListener listener)
          Removes the given object from the event queue
 void run()
          
protected  void setActualCommand(String actualCommand)
          Setter for actualCommand
protected  void setProcess(Process process)
          Setter for process
 void stopProcess()
          Stops the process.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ProcessLauncher

public ProcessLauncher(String command)
Creates a new instance of ProcessLauncher

Parameters:
command - String command, and all its arguments, to launch
Method Detail

run

public void run()

Specified by:
run in interface Runnable
Overrides:
run in class Thread

addListener

public void addListener(ProcessLauncherListener listener)
Adds the listener to the event queue

Parameters:
listener - Object that wishes to receive update events

removeListener

public void removeListener(ProcessLauncherListener listener)
Removes the given object from the event queue

Parameters:
listener - Object that no longer wants to receive update events

stopProcess

public void stopProcess()
Stops the process. The does not work on Windows, as we have to envelope the desired command using "cmd.exe /c". So the stop process call actually cancels cmd.exe, and happily lets the desired command continue running


getProcess

public Process getProcess()
Getter for process

Returns:
Internal process that is spawned from the command

setProcess

protected void setProcess(Process process)
Setter for process

Parameters:
process - Internal process that is spawned from the command

getActualCommand

public String getActualCommand()
Getter for actualCommand

Returns:
Actual command line passed to the Runtime.exec() command

setActualCommand

protected void setActualCommand(String actualCommand)
Setter for actualCommand

Parameters:
actualCommand - Actual command line passed to the Runtime.exec() command