public ClickHouseClient build() {
        ClickHouseClient client = null;

        ClickHouseConfig conf = getConfig();
        int counter = 0;
        if (nodeSelector != null) {
            Throwable lastError = null;
            for (ClickHouseClient c : loadClients()) {
                try {
                    c.init(conf);
                    counter++;
                    if (nodeSelector == ClickHouseNodeSelector.EMPTY || nodeSelector.match(c)) {
                        client = c;
                        break;
                    }
                } catch (UnsupportedProtocolException e) {
                    if (nodeSelector.matchAnyOfPreferredProtocols(e.getProtocol())) {
                        lastError = e;
                    }
                } catch (Throwable e) {
                    log.warn("Skip client due to exception: " + e.getMessage(), e);
                }
            }

            if (client == null && lastError != null) {
                throw new ExceptionInInitializerError(lastError.getMessage());
            }
        }

        if (agent) {
            return new Agent(client, conf);
        } else if (client == null) {
            throw new IllegalStateException(
                    ClickHouseUtils.format("No suitable ClickHouse client(out of %d) found in classpath for %s.",
                            counter, nodeSelector));
        }
        return client;
    }
Builds an instance of {@link ClickHouseClient}. This method will use
{@link java.util.ServiceLoader} to load a suitable implementation based on
preferred protocol(s), or just the first one if no preference given.
{@link ClickHouseClient#accept(ClickHouseProtocol)} will be invoked during
the process to test if the implementation is compatible with the preferred
protocol(s) or not. At the end of process, if a suitable implementation is
found, {@link ClickHouseClient#init(ClickHouseConfig)} will be invoked for
initialization.

@return suitable client to handle preferred protocols
@throws IllegalStateException when no suitable client found in classpath
clickhouse-client/src/main/java/com/clickhouse/client/ClickHouseClientBuilder.java