org.iges.grads.server
Class Task

java.lang.Object
  |
  +--org.iges.grads.server.Task

public class Task
extends java.lang.Object

A wrapper for invoking an external process.


Field Summary
protected  java.lang.String[] cmd
           
protected  java.lang.String cmdString
           
protected  java.lang.String[] env
           
protected static java.lang.String ERROR_INDICATOR
          String that subprocesses can print to indicate to the server that an error has occurred in their processing.
protected  java.lang.StringBuffer output
           
protected  long timeLimit
           
protected  java.io.File workDir
           
 
Constructor Summary
Task(java.lang.String[] cmd, java.lang.String[] env, java.io.File workDir, long timeLimit)
          Sets up an external process.
 
Method Summary
protected  java.lang.String buildCmdString(java.lang.String[] cmd)
          Turns an array of Strings into a single space-separated String
protected  void checkErrors()
          Parses output looking for error messages, defined as lines beginning with the string contained in ERROR_INDICATOR (currently "error: ").
protected  void finish(java.lang.Process process, long startTime)
          Waits for a running process to complete (or time out), and then performs cleanup and error-handling tasks.
 java.lang.String getCmd()
          Returns a printable string version of the external command.
 java.lang.String getOutput()
          Returns a string version of the command's console output
 void run()
          Executes the external process, returning when it is finished or when it exceeds the time limit specified in the constructor.
 void run(long timeLimit)
          Executes the external process, returning when it is finished or when it exceeds the time limit specified.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ERROR_INDICATOR

protected static java.lang.String ERROR_INDICATOR
String that subprocesses can print to indicate to the server that an error has occurred in their processing.


output

protected java.lang.StringBuffer output

cmdString

protected java.lang.String cmdString

cmd

protected java.lang.String[] cmd

env

protected java.lang.String[] env

workDir

protected java.io.File workDir

timeLimit

protected long timeLimit
Constructor Detail

Task

public Task(java.lang.String[] cmd,
            java.lang.String[] env,
            java.io.File workDir,
            long timeLimit)
Sets up an external process.

Method Detail

run

public void run()
         throws AnagramException
Executes the external process, returning when it is finished or when it exceeds the time limit specified in the constructor.

Throws:
AnagramException - If the process fails, or if the output parser finds an error message in the output.

run

public void run(long timeLimit)
         throws AnagramException
Executes the external process, returning when it is finished or when it exceeds the time limit specified.

Parameters:
timeLimit - Overrides the time limit specified in the constructor.
Throws:
AnagramException - If the process fails, or if there is an error message (a line beginning with "error: ") in the output.

getCmd

public java.lang.String getCmd()
Returns a printable string version of the external command.


getOutput

public java.lang.String getOutput()
Returns a string version of the command's console output


buildCmdString

protected java.lang.String buildCmdString(java.lang.String[] cmd)
Turns an array of Strings into a single space-separated String


finish

protected void finish(java.lang.Process process,
                      long startTime)
               throws AnagramException
Waits for a running process to complete (or time out), and then performs cleanup and error-handling tasks.

AnagramException

checkErrors

protected void checkErrors()
                    throws AnagramException
Parses output looking for error messages, defined as lines beginning with the string contained in ERROR_INDICATOR (currently "error: "). The remainder of the line is treated as an error message to pass to the user.

Throws:
AnagramException - if a line containing an error message is found.