private void readResponse() throws AgentException, IOException {
socket.setSoTimeout(getTimeoutForJobType(currentJob.getType()));
String command = readLine();
if (command == null)
throw new AgentException("RESULT expected, but connection terminated; " + command);
StringTokenizer tokenizer = new StringTokenizer(command, " ");
try {
if (!tokenizer.nextToken().equals("RESULT"))
throw new AgentException("RESULT expected; " + command);
assertHasMoreTokens(tokenizer, command);
String expectedType = currentJob.getType().toString();
if (JobType.FEEDBACK.equals(currentJob.getType())) {
expectedType = "GRADE";
}
if (!tokenizer.nextToken().equals(expectedType))
throw new AgentException(currentJob.getType() + " expected; " + command);
assertHasMoreTokens(tokenizer, command);
String result = tokenizer.nextToken();
if (result.equals("OK") || result.equals("FAIL"))
currentJob.result = result;
else
throw new AgentException("OK or FAIL expected;" + command);
assertHasMoreTokens(tokenizer, command);
currentJob.setTask(tokenizer.nextToken());
} catch (NoSuchElementException e) {
throw new AgentException("NoSuchElementException: error parsing RESULT");
}
currentJob.output = recvBytes();
}