All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.openlineage.client.transports.TransportResolver Maven / Gradle / Ivy

There is a newer version: 1.26.0
Show newest version
/*
/* Copyright 2018-2024 contributors to the OpenLineage project
/* SPDX-License-Identifier: Apache-2.0
*/

package io.openlineage.client.transports;

import java.util.Optional;
import java.util.ServiceLoader;
import java.util.function.Predicate;
import java.util.stream.StreamSupport;

public class TransportResolver {

  public static Class resolveTransportConfigByType(String type) {
    TransportBuilder builder = getTransportBuilder(b -> b.getType().equalsIgnoreCase(type));
    return builder.getConfig().getClass();
  }

  public static String resolveTransportTypeByConfigClass(Class transportConfigClass) {
    TransportBuilder builder =
        getTransportBuilder(b -> b.getConfig().getClass().equals(transportConfigClass));
    return builder.getType();
  }

  public static Transport resolveTransportByConfig(TransportConfig transportConfig) {
    TransportBuilder builder =
        getTransportBuilder(b -> b.getConfig().getClass().equals(transportConfig.getClass()));
    return builder.build(transportConfig);
  }

  private static TransportBuilder getTransportBuilder(Predicate predicate) {
    ServiceLoader loader = ServiceLoader.load(TransportBuilder.class);
    Optional optionalBuilder =
        StreamSupport.stream(loader.spliterator(), false).filter(predicate).findFirst();

    return optionalBuilder.orElseThrow(
        () -> new IllegalArgumentException("Failed to find TransportBuilder"));
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy