使用 SolrJ API 獲取分片領導者

private final String COLLECTION_NAME = "myCollection";
private final String ZOOKEPER_CLIENT_TIMEOUT_MS = "1000000"

   private Map<String, String> getShardLeaders(CloudSolrServer cloudSolrServer) throws InterruptedException, KeeperException {
        Map<String, String> shardleaders = new TreeMap<String, String>();
        ZkStateReader zkStateReader = cloudSolrServer.getZkStateReader();
        for (Slice slice : zkStateReader.getClusterState().getSlices(COLLECTION_NAME)) {
            shardleaders.put(slice.getName(), zkStateReader.getLeaderUrl(COLLECTION_NAME, slice.getName(), ZOOKEPER_CLIENT_TIMEOUT_MS));
        }
        return shardleaders;
    }