Skip to content

Instantly share code, notes, and snippets.

@patricker
Created December 14, 2019 18:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save patricker/b611f6c3b1c96cd80203527f2135b11e to your computer and use it in GitHub Desktop.
Save patricker/b611f6c3b1c96cd80203527f2135b11e to your computer and use it in GitHub Desktop.
Dremio Pluggable Helper
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