synchronized public void performHostDiscovery(MetricRegistry metricRegistry) {
        // Host discovery is not idempotent; only take action if it hasn't been performed.
        if (_hostDiscoveryPerformed) {
            return;
        }

        Iterable<String> hosts = null;

        // Statically configured list of seeds.
        if (_seeds != null) {
            hosts = Splitter.on(',').trimResults().split(_seeds);
        }

        // Perform ZooKeeper discovery to find the seeds.
        if (_zooKeeperServiceName != null) {
            checkState(hosts == null, "Too many host discovery mechanisms configured.");
            checkState(_curator != null,
                    "ZooKeeper host discovery is configured but withZooKeeperHostDiscovery() was not called.");

            try (HostDiscovery hostDiscovery = new ZooKeeperHostDiscovery(_curator, _zooKeeperServiceName, metricRegistry)) {
                List<String> hostList = Lists.newArrayList();
                for (ServiceEndPoint endPoint : hostDiscovery.getHosts()) {
                    // The host:port is in the end point ID
                    hostList.add(endPoint.getId());

                    // The partitioner class name is in the json-encoded end point payload
                    if (_partitioner == null && endPoint.getPayload() != null) {
                        JsonNode payload = JsonHelper.fromJson(endPoint.getPayload(), JsonNode.class);
                        String partitioner = payload.path("partitioner").textValue();
                        if (partitioner != null) {
                            _partitioner = CassandraPartitioner.fromClass(partitioner);
                        }
                    }
                }
                hosts = hostList;
            } catch (IOException ex) {
                // suppress any IOExceptions that might result from closing our ZooKeeperHostDiscovery
            }
        }

        checkState(hosts != null, "No Cassandra host discovery mechanisms are configured.");
        //noinspection ConstantConditions
        checkState(!Iterables.isEmpty(hosts), "Unable to discover any Cassandra seed instances.");
        checkState(_partitioner != null, "Cassandra partitioner not configured or discoverable.");
        _seeds = Joiner.on(',').join(hosts);
        _hostDiscoveryPerformed = true;
    }
synchronized public void performHostDiscovery ( MetricRegistry metricRegistry ) { if ( _hostDiscoveryPerformed ) { return ; } Iterable < String > hosts = null ; if ( _seeds != null ) { hosts = Splitter . on ( ',' ) . trimResults ( ) . split ( _seeds ) ; } if ( _zooKeeperServiceName != null ) { checkState ( hosts == null , "Too many host discovery mechanisms configured." ) ; checkState ( _curator != null , "ZooKeeper host discovery is configured but withZooKeeperHostDiscovery() was not called." ) ; try ( HostDiscovery hostDiscovery = new ZooKeeperHostDiscovery ( _curator , _zooKeeperServiceName , metricRegistry ) ) { List < String > hostList = Lists . newArrayList ( ) ; for ( ServiceEndPoint endPoint : hostDiscovery . getHosts ( ) ) { hostList . add ( endPoint . getId ( ) ) ; if ( _partitioner == null && endPoint . getPayload ( ) != null ) { JsonNode payload = JsonHelper . fromJson ( endPoint . getPayload ( ) , JsonNode . class ) ; String partitioner = payload . path ( "partitioner" ) . textValue ( ) ; if ( partitioner != null ) { _partitioner = CassandraPartitioner . fromClass ( partitioner ) ; } } } hosts = hostList ; } catch ( IOException ex ) { } } checkState ( hosts != null , "No Cassandra host discovery mechanisms are configured." ) ; checkState ( ! Iterables . isEmpty ( hosts ) , "Unable to discover any Cassandra seed instances." ) ; checkState ( _partitioner != null , "Cassandra partitioner not configured or discoverable." ) ; _seeds = Joiner . on ( ',' ) . join ( hosts ) ; _hostDiscoveryPerformed = true ; }
Discover Cassandra seeds and partitioner, if not statically configured.