util
Class CommandLineRunner

java.lang.Object
  extended by iterator.AbstractIterator
      extended by util.CommandLineRunner
All Implemented Interfaces:
Iterable
Direct Known Subclasses:
Cart3DRunner, PanairRunnerShevell

public abstract class CommandLineRunner
extends AbstractIterator

Utility to assist running a tool from the command line. Firstly, CommandLine is a superior to Runtime for many reasons described in its javadoc. This class, in addition, provides for a designated scratch directory, and the facility to monitor a job once it's launched. This is often the case with advanced analysis tools, which need to be launched and then monitored for completion. Simplifies interfacing with a job scheduler such as PBS.

Author:
dgorur

Field Summary
protected  CommandLine commandLine
           
protected static int DEFAULT_POLL_INTERVAL
          qstat poll interval in seconds.
protected static java.lang.String DEFAULT_RUN_COMMAND
          Command to run the tool, usually a symlink to a script.
protected static java.lang.String DEFAULT_SCRATCH_DIR
          Scratch directory, if required
protected static java.lang.String DEFAULT_STATUS_COMMAND
          Status command to check on CART3D.
protected static double DEFAULT_TIMEOUT_INTERVAL
          Timeout interval in seconds.
protected  java.lang.String statArgument
           
protected  double timeElapsed
           
 
Fields inherited from class iterator.AbstractIterator
diagnosticString, iter
 
Constructor Summary
CommandLineRunner()
          Default constructor.
CommandLineRunner(boolean inline)
           
 
Method Summary
 java.lang.String getArgList()
          Returns the argList.
 int getPollInterval()
          Returns the pollInterval.
 java.lang.String getRunCommand()
          Returns the command used to run the tool/analysis.
 java.lang.String getScratchDir()
          Returns the directory for any file I/O that this task may need.
 java.lang.String getStatusCommand()
          Returns the command to check for monitoring completion.
 double getTimeoutInterval()
          Returns the timeout interval.
 void init()
          Initialization routine
 boolean isInline()
          Returns the inline.
 boolean isTerminated()
          Returns true after a timeout.
 void iterate()
          Iterates until termination.
 void run()
          Runs the task that this class manages.
 void run(java.util.ArrayList<java.lang.String> args)
           
 void run(java.lang.String arg)
           
 void setArgList(java.lang.String argList)
          Sets the argList.
 void setInline(boolean inline)
          Sets the inline.
 void setPollInterval(int pollInterval)
          Sets the interval at which the system is queried for completion of the running task.
 void setRunCommand(java.lang.String runCommand)
          Sets the run command.
 void setScratchDir(java.lang.String scratchDir)
          Sets the scratch directory to be used for any file IO that this task generates.
 void setStatusCommand(java.lang.String statusCommand)
          Sets the command to query completion of this task.
 void setTimeoutInterval(double timeoutInterval)
          Sets the timeout interval.
 void singleIteration()
          Sleeps for a designated sleep interval.
protected  void updateDiagnostics()
          Provides access to the diagnosticString, so that the user has flexibility over multiple methods accessing this string at different times.
 
Methods inherited from class iterator.AbstractIterator
isVerbose, printDiagnostics, setVerbose
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_POLL_INTERVAL

protected static int DEFAULT_POLL_INTERVAL
qstat poll interval in seconds.


DEFAULT_RUN_COMMAND

protected static java.lang.String DEFAULT_RUN_COMMAND
Command to run the tool, usually a symlink to a script.


DEFAULT_SCRATCH_DIR

protected static java.lang.String DEFAULT_SCRATCH_DIR
Scratch directory, if required


DEFAULT_STATUS_COMMAND

protected static java.lang.String DEFAULT_STATUS_COMMAND
Status command to check on CART3D.


DEFAULT_TIMEOUT_INTERVAL

protected static double DEFAULT_TIMEOUT_INTERVAL
Timeout interval in seconds.


commandLine

protected CommandLine commandLine

statArgument

protected java.lang.String statArgument

timeElapsed

protected double timeElapsed
Constructor Detail

CommandLineRunner

public CommandLineRunner()
Default constructor.


CommandLineRunner

public CommandLineRunner(boolean inline)
Method Detail

getArgList

public java.lang.String getArgList()
Returns the argList.

Returns:
the argList.

getPollInterval

public int getPollInterval()
Returns the pollInterval.

Returns:
the pollInterval.

getRunCommand

public java.lang.String getRunCommand()
Returns the command used to run the tool/analysis.

Returns:
the run command.

getScratchDir

public java.lang.String getScratchDir()
Returns the directory for any file I/O that this task may need.

Returns:
the scratch directory.

getStatusCommand

public java.lang.String getStatusCommand()
Returns the command to check for monitoring completion.

Returns:
the status command.

getTimeoutInterval

public double getTimeoutInterval()
Returns the timeout interval.

Returns:
the timeout interval.

init

public void init()
          throws Exceptions.ComputationException
Description copied from interface: Iterable
Initialization routine

Throws:
Exceptions.ComputationException

isTerminated

public boolean isTerminated()
Returns true after a timeout.

Returns:
true when done.
See Also:
Iterable.isTerminated()

iterate

public void iterate()
Description copied from interface: Iterable
Iterates until termination.

Specified by:
iterate in interface Iterable
Overrides:
iterate in class AbstractIterator

run

public void run(java.util.ArrayList<java.lang.String> args)
Parameters:
args -

run

public void run(java.lang.String arg)
Parameters:
arg -

run

public void run()
Runs the task that this class manages.


setArgList

public void setArgList(java.lang.String argList)
Sets the argList.

Parameters:
argList - the given argList.

setPollInterval

public void setPollInterval(int pollInterval)
Sets the interval at which the system is queried for completion of the running task.

Parameters:
pollInterval - interval the given poll interval.

setRunCommand

public void setRunCommand(java.lang.String runCommand)
Sets the run command.

Parameters:
runCommand - the given run command.

setScratchDir

public void setScratchDir(java.lang.String scratchDir)
Sets the scratch directory to be used for any file IO that this task generates.

Parameters:
scratchDir - the given scratch directory.

setStatusCommand

public void setStatusCommand(java.lang.String statusCommand)
Sets the command to query completion of this task. Can be void if the task runs in one shot, as opposed to a job that is launched, runs in the background, and needs to be checked on for completion.

Parameters:
statusCommand - the given status command.

setTimeoutInterval

public void setTimeoutInterval(double timeoutInterval)
Sets the timeout interval.

Parameters:
timeoutInterval - the given interval.

singleIteration

public void singleIteration()
Sleeps for a designated sleep interval.

See Also:
Iterable.singleIteration()

updateDiagnostics

protected void updateDiagnostics()
Description copied from class: AbstractIterator
Provides access to the diagnosticString, so that the user has flexibility over multiple methods accessing this string at different times.

Specified by:
updateDiagnostics in class AbstractIterator

isInline

public boolean isInline()
Returns the inline.

Returns:
the inline.

setInline

public void setInline(boolean inline)
Sets the inline.

Parameters:
inline - the given inline.