ClientData clientData;
long clientId;
try {
clientId = core.addClientAndConnect(host, port);
} catch (Exception e) {
throw new ClientConnectionException("Failed to connect to client "
+ " on host " + host + " and port " + port);
}
clientData = core.getClientData(clientId);
try {
clientData.handler.registerServer(clientId, core.getId(), token);
} catch (InvalidTokenException e) {
LOG.warn("Client rejected our token. clientId = " + clientId +
". token = " + token, e);
// Remove the client from our internal structures
core.removeClient(clientId);
// Raise an exception here since the client rejected us
throw new ClientConnectionException("Token rejected");
}
}