}
}
public void startSession(String id, PrintWriter writer) {
logger.debug("trying to start session for {}", id);
SlaveBrowser browser = capturedBrowsers.getBrowser(id);
String sessionId = UUID.randomUUID().toString();
SlaveBrowser slaveBrowser = capturedBrowsers.getBrowser(id);
if (browser.tryLock(sessionId)) {
logger.debug("got session lock {} for {}", sessionId, id);
writer.write(sessionId);
slaveBrowser.resetCommandQueue();
slaveBrowser.clearResponseQueue();
browser.heartBeatLock(sessionId);
} else {
logger.debug("checking session status for {}", id);
// session is probably stalled
if (!browser.inUse()) {
logger.debug("forcing unlock for {}", id);
browser.forceUnlock();
slaveBrowser.resetCommandQueue();
slaveBrowser.clearResponseQueue();
writer.write(browser.tryLock(sessionId) ? sessionId : "FAILED");
} else {
logger.debug("session unvailable for {}", id);
writer.write("FAILED");
}