SlaveBrowser browser) throws JsonParseException {
addResponseId(responseId, browser);
browser.heartBeat();
Command command = null;
if (isResponseValid(response)) {
Response res = gson.fromJson(response, Response.class);
logger.trace("response type: " + res.getResponseType());
// TODO (corysmith): Replace this with polymorphism,
// using the response type to create disposable actions.
switch (res.getResponseType()) {
case BROWSER_READY:
handleFileLoadResult(browser, res);
// TODO(corysmith): Move the loading of files to a browser into the
// server
browser.addResponse(
new Response(ResponseType.FILE_LOAD_RESULT.toString(), res.getResponse(), browser
.getBrowserInfo(), "", res.getExecutionTime()), false);
browser.ready();
break;
case FILE_LOAD_RESULT:
handleFileLoadResult(browser, res);
browser.addResponse(res, done);
break;
case NOOP:
break;
case LOG:
BrowserLog log = gson.fromJson(res.getResponse(), res.getGsonType());
if (log.getLevel() == 1000) {
logger.info("Error in browser: " + res.toString());
} else {
logger.info("Message from the browser: " + res.toString());
}
browser.addResponse(res, done);
break;
// reset the browsers fileset.
case RESET_RESULT:
browser.resetFileSet();
logger.debug("Clearing fileset for {}", browser);
handleFileLoadResult(browser, res);
// queue the load results for the next command to be run.
browser.addResponse(
new Response(ResponseType.FILE_LOAD_RESULT.toString(), res.getResponse(), browser
.getBrowserInfo(), "", res.getExecutionTime()), false);
browser.addResponse(res, done);
break;
case UNKNOWN:
logger.error("Recieved Unknown: " + response);
browser.addResponse(res, done);
break;
case BROWSER_PANIC:
logger.debug("Browser panic for {}", res.toString());
default:
browser.addResponse(res, done);
break;
}
logger.trace("Received:\n done: {} \n res:\n {}\n", new Object[] {done, res});