private Multimap<String, TokenRange> describeCassandraTopology(final Keyspace keyspace) {
        try {
            @SuppressWarnings ("unchecked")
            ConnectionPool<Cassandra.Client> connectionPool = (ConnectionPool<Cassandra.Client>) keyspace.getConnectionPool();

            return connectionPool.executeWithFailover(
                    new AbstractKeyspaceOperationImpl<Multimap<String, TokenRange>>(EmptyKeyspaceTracerFactory.getInstance().newTracer(CassandraOperationType.DESCRIBE_RING), keyspace.getKeyspaceName()) {
                        @Override
                        protected Multimap<String, TokenRange> internalExecute(Cassandra.Client client, ConnectionContext state)
                                throws Exception {
                            Multimap<String, TokenRange> racks = ArrayListMultimap.create();
                            for (org.apache.cassandra.thrift.TokenRange tokenRange : client.describe_local_ring(getKeyspace())) {
                                // The final local endpoint "owns" the token range, the rest are for replication
                                EndpointDetails endpointDetails = Iterables.getLast(tokenRange.getEndpoint_details());
                                racks.put(endpointDetails.getRack(),
                                        new TokenRangeImpl(tokenRange.getStart_token(), tokenRange.getEnd_token(), tokenRange.getEndpoints()));
                            }
                            return Multimaps.unmodifiableMultimap(racks);
                        }
                    },
                    keyspace.getConfig().getRetryPolicy().duplicate()).getResult();
        } catch (ConnectionException e) {
            throw Throwables.propagate(e);
        }
    }
private Multimap < String , TokenRange > describeCassandraTopology ( final Keyspace keyspace ) { try { @ SuppressWarnings ( "unchecked" ) ConnectionPool < Cassandra . Client > connectionPool = ( ConnectionPool < Cassandra . Client > ) keyspace . getConnectionPool ( ) ; return connectionPool . executeWithFailover ( new AbstractKeyspaceOperationImpl < Multimap < String , TokenRange > > ( EmptyKeyspaceTracerFactory . getInstance ( ) . newTracer ( CassandraOperationType . DESCRIBE_RING ) , keyspace . getKeyspaceName ( ) ) { @ Override protected Multimap < String , TokenRange > internalExecute ( Cassandra . Client client , ConnectionContext state ) throws Exception { Multimap < String , TokenRange > racks = ArrayListMultimap . create ( ) ; for ( org . apache . cassandra . thrift . TokenRange tokenRange : client . describe_local_ring ( getKeyspace ( ) ) ) { EndpointDetails endpointDetails = Iterables . getLast ( tokenRange . getEndpoint_details ( ) ) ; racks . put ( endpointDetails . getRack ( ) , new TokenRangeImpl ( tokenRange . getStart_token ( ) , tokenRange . getEnd_token ( ) , tokenRange . getEndpoints ( ) ) ) ; } return Multimaps . unmodifiableMultimap ( racks ) ; } } , keyspace . getConfig ( ) . getRetryPolicy ( ) . duplicate ( ) ) . getResult ( ) ; } catch ( ConnectionException e ) { throw Throwables . propagate ( e ) ; } }
Gets the topology for a Cassandra keyspace as a Multimap, where the keys identify a rack (or availability zone
in Amazon) and the values are the token ranges for each host in that rack.  For example, for a well distributed
ring of 12 hosts and a replication factor of 3 this method would return a Multimap with 3 keys and each key would
contain 4 token ranges.