Created
December 14, 2019 18:47
-
-
Save patricker/b611f6c3b1c96cd80203527f2135b11e to your computer and use it in GitHub Desktop.
Dremio Pluggable Helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected <IFACE, IMPL extends IFACE> Class<? extends IFACE> setupPluggableService( | |
final Class<IFACE> bind, | |
final Class<IMPL> defaultBind, | |
final SingletonRegistry registry, | |
final DremioConfig config, | |
final ScanResult scanResult, | |
final String configKey) { | |
//If we want to make it pluggable in the future, but haven't setup a key for it, just use the default implementation | |
final String keyValue = StringUtils.isEmpty(configKey) ? null : config.getString(configKey); | |
if (keyValue == null) { | |
registry.bind(bind, defaultBind); | |
logger.info(defaultBind.getName() + " service is configured."); | |
return defaultBind; | |
} | |
// Find class by FQN or Partial Name match | |
final List<String> allowedProviders = new ArrayList<>(); | |
final Set<Class<? extends IFACE>> implementations = scanResult.getImplementations(bind); | |
for (Class<? extends IFACE> clazz : implementations) { | |
if (clazz.getName().toLowerCase().contains(keyValue)) { | |
registry.bind(bind, clazz); | |
logger.info(clazz.getName() + " service is configured."); | |
return clazz; | |
} | |
allowedProviders.add(clazz.getName()); | |
} | |
final String providers = String.join(",", allowedProviders); | |
logger.error("Unknown value '{}' set for {}. Accepted string contains values are [{}]", keyValue, configKey, providers); | |
throw new RuntimeException( | |
String.format("Unknown service type '%s' set in config path '%s'", keyValue, configKey)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment