if(computer==null) {
error(out, "No such slave: "+nodeName);
return;
}
Channel ch = computer.getChannel();
if(ch !=null) {
String c = request.getProperty("Cookie");
if (c!=null && c.equals(ch.getProperty(COOKIE_NAME))) {
// we think we are currently connected, but this request proves that it's from the party
// we are supposed to be communicating to. so let the current one get disconnected
LOGGER.info("Disconnecting "+nodeName+" as we are reconnected from the current peer");
try {
computer.disconnect(new ConnectionFromCurrentPeer()).get(15, TimeUnit.SECONDS);
} catch (ExecutionException e) {
throw new IOException2("Failed to disconnect the current client",e);
} catch (TimeoutException e) {
throw new IOException2("Failed to disconnect the current client",e);
}
} else {
error(out, nodeName + " is already connected to this master. Rejecting this connection.");
return;
}
}
out.println(Engine.GREETING_SUCCESS);
Properties response = new Properties();
String cookie = generateCookie();
response.put("Cookie",cookie);
writeResponseHeaders(out, response);
ch = jnlpConnect(computer);
ch.setProperty(COOKIE_NAME, cookie);
}