public final synchronized boolean addHost(Host host, boolean refresh) {
// Already exists
if (hosts.containsKey(host)) {
// Check to see if we are adding token ranges or if the token ranges changed
// which will force a rebuild of the token topology
Host existingHost = hosts.get(host).getHost();
if (existingHost.getTokenRanges().size() != host.getTokenRanges().size()) {
existingHost.setTokenRanges(host.getTokenRanges());
return true;
}
ArrayList<TokenRange> currentTokens = Lists.newArrayList(existingHost.getTokenRanges());
ArrayList<TokenRange> newTokens = Lists.newArrayList(host.getTokenRanges());
Collections.sort(currentTokens, compareByStartToken);
Collections.sort(newTokens, compareByStartToken);
for (int i = 0; i < currentTokens.size(); i++) {
if (!currentTokens.get(i).getStartToken().equals(newTokens.get(i).getStartToken()) ||
!currentTokens.get(i).getEndToken().equals(newTokens.get(i).getEndToken())) {
return false;
}
}
existingHost.setTokenRanges(host.getTokenRanges());
return true;
}
else {
HostConnectionPool<CL> pool = newHostConnectionPool(host, factory, config);
if (null == hosts.putIfAbsent(host, pool)) {