net.codescore.exe
Class Grader

java.lang.Object
  extended by net.codescore.exe.Grader

public class Grader
extends Object

This class compiles, executes and generates a diff file for a given submission.

Author:
Adam Cornett

Field Summary
private  CompetitionManager compMan
           
private  org.apache.commons.logging.Log log
           
 int MAX_RUNTIME
          The maximum runtime for a program in milliseconds
protected  GradingMode mode
          The mode of this grader
private  ProcessBuilder pb
           
static String PRB_NAME_VAR
          This is the place-holder for the Unix problem name.
static String SRC_FILE_VAR
          This is the place-holder for the source file name.
private  Submission submission
           
 
Constructor Summary
Grader(Submission s, CompetitionManager cm, GradingMode mode)
          Create a new Grader
 
Method Summary
private  void commitChanges()
           
 CompileResult compile()
          Compile the submission to machine/byte code
 ExecutionResult execute()
          Execute the program.
private  ObjectContext getOC()
           
 Submission getSubmission()
           
private  ExecutionResult returnER(ExecutionResult er)
          A helper method for cleaning up after execution
private  void scoreSub()
           
static void scoreSubmission(TeamSubmission ts, CompetitionManager cm)
          Score a submission
private  void setCompileError()
           
private  void setCorrect()
           
private  void setRunError()
           
private  void setTimeError()
           
private  int watchTime(ExecutionResult er)
          This method watches an execution and if it exceeds MAX_RUNTIME it will kill the process and set the status of the submission to indicate that it exceeded the maximum allowable runtime.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PRB_NAME_VAR

public static final String PRB_NAME_VAR
This is the place-holder for the Unix problem name. When it is encountered in the process commands it is replaced with the Unix name of the problem.

See Also:
_Problem.getUnixName(), Constant Field Values

SRC_FILE_VAR

public static final String SRC_FILE_VAR
This is the place-holder for the source file name. When it is encountered in the process commands, it is replaced with the absolute path name of the source file.

See Also:
File.getAbsoluteFile(), TeamSubmission.getSrcFile(), Constant Field Values

MAX_RUNTIME

public final int MAX_RUNTIME
The maximum runtime for a program in milliseconds


compMan

private final CompetitionManager compMan

log

private org.apache.commons.logging.Log log

pb

private ProcessBuilder pb

submission

private final Submission submission

mode

protected final GradingMode mode
The mode of this grader

See Also:
GradingMode
Constructor Detail

Grader

public Grader(Submission s,
              CompetitionManager cm,
              GradingMode mode)
Create a new Grader

Parameters:
s - The submission to be graded
cm - The competition manager to pull settings from
mode - The mode for this grader
Method Detail

scoreSubmission

public static void scoreSubmission(TeamSubmission ts,
                                   CompetitionManager cm)
Score a submission

Parameters:
ts - The submission to score
cm - Needed to get the scoring mode and the competition start time if using a time based scoring method.
See ScoringMode for details on each mode.

compile

public CompileResult compile()
                      throws IOException
Compile the submission to machine/byte code

Returns:
A CompileResult that holds references to the input/output/error streams of the compiler process
Throws:
IOException - If the source file cannot be written to disk, or the process fails to start.

execute

public ExecutionResult execute()
                        throws IOException
Execute the program. This method will call the compile() method at the start of execution.

Returns:
An ExecutionResult which holds references to the exit code of the process and its input/output/error streams.
Throws:
IOException - see compile()
See Also:
compile()

getSubmission

public Submission getSubmission()

commitChanges

private void commitChanges()

getOC

private ObjectContext getOC()

returnER

private ExecutionResult returnER(ExecutionResult er)
                          throws IOException
A helper method for cleaning up after execution

Parameters:
er - The ExecutionResult to be cleaned up and returned
Returns:
The ExecutionResult passed in
Throws:
IOException - see ExecutionResult.cleanup()

scoreSub

private void scoreSub()

setCompileError

private void setCompileError()

setCorrect

private void setCorrect()

setRunError

private void setRunError()

setTimeError

private void setTimeError()

watchTime

private int watchTime(ExecutionResult er)
               throws InterruptedException
This method watches an execution and if it exceeds MAX_RUNTIME it will kill the process and set the status of the submission to indicate that it exceeded the maximum allowable runtime.

Parameters:
er - The ExecutionResult to watch.
Returns:
If the execution completes, the exit value of the execution. If the execution exceeds the time limit, -1.
Throws:
InterruptedException - If this thread is interrupted while waiting for the execution finish.
See Also:
TeamSubmission#setStatus(net.launchpad.codescore.dbo.ProblemStatus)


Copyright 2008 © Adam Cornett, Andrew Conner All Rights Reserved.