@ Override 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 ) ) { try { monitor . onHostAdded ( host , pool ) ; if ( refresh ) { topology . addPool ( pool ) ; rebuildPartitions ( ) ; } pool . primeConnections ( config . getInitConnsPerHost ( ) ) ; } catch ( Exception e ) { // Ignore, pool will have been marked down internally } return true ; } else { return false ; } } }
Add host to the system . May need to rebuild the partition map of the system