public static <T> T getService(Class<? extends T> serviceInterface, T defaultService) {
        T service = defaultService;
        Exception error = null;

        // load custom implementation if any
        try {
            T s = findFirstService(serviceInterface);
            if (s != null) {
                service = s;
            }
        } catch (Exception t) {
            error = t;
        }

        if (service == null) {
            throw new IllegalStateException(String.format("Failed to get service %s", serviceInterface.getName()),
                    error);
        }

        return service;
    }
Load service according to given interface using
{@link java.util.ServiceLoader}, fallback to given default service or
supplier function if not found.

@param <T>              type of service
@param serviceInterface non-null service interface
@param defaultService   optionally default service
@return non-null service
clickhouse-data/src/main/java/com/clickhouse/data/ClickHouseUtils.java