if (clientIds.containsKey(clientId)) {
int timeout = 5000;
log.info("Got duplicate client with id: " + clientId + ". Giving the existing client " + timeout + " millis to prove it's alive.");
// Assert that the existing client is alive
BrokerClient existingClient = (BrokerClient) clientIds.get(clientId);
JMSException ex = null;
boolean isValid = true;
try {
existingClient.validateConnection(timeout);
} catch (JMSException e) {
isValid = false;
ex = e;
}
if (isValid) {
// The existing client is valid, so kick the new client
log.info("Client: " + clientId + " on transport: " + existingClient.getChannel()
+ "' is alive, rejecting new client on transport: " + client.getChannel());
throw new InvalidClientIDException("Duplicate clientId: " + info);
} else {
// A transport error occured or the existing client did not
// respond in time, so kick it and let the new client connect.
log.info("Replacing client: " + clientId + " on transport: " + existingClient.getChannel() + " ("
+ ex.getMessage() + ") with client on transport: " + client.getChannel());
// @TODO: Not sure this is the proper way to close the existing client
existingClient.cleanUp();
existingClient.stop();
}
}
getBroker().addClient(client, info);
log.info("Adding new client: " + clientId + " on transport: " + client.getChannel());