druid icon indicating copy to clipboard operation
druid copied to clipboard

Make Coordinator IndexingServiceHelpers pluggable

Open guobingkun opened this issue 10 years ago • 0 comments

Follow up of the discussion in https://github.com/druid-io/druid/pull/1998#issuecomment-197463285

Currently IndexingServiceHelpers are added according to the settings of configuration, see here. Rather than having all the config.isXXX checks there, it makes sense to have a pluggable approach for allowing the dynamic configuration to bring in implementations for helpers without having to have hard-coded sets of available helpers. Plus, it will also make it possible for extensions to plug helpers in.

To make this work, there needs to be some Guice util that could conditionally bind an item into a set. The condition is driven by the value set in the runtime.properties.

An example would be:

public class ConditionalMultibind<T>
{

  public static <T> ConditionalMultibind<T> create(Properties properties, Binder binder, Class<T> interfaceClazz)
  {
    return new ConditionalMultibind<T>(properties, Multibinder.<T>newSetBinder(binder, interfaceClazz));
  }

  public static <T> ConditionalMultibind<T> create(
      Properties properties,
      Binder binder,
      Class<T> interfaceClazz,
      Class<? extends Annotation> annotationType
  )
  {
    return new ConditionalMultibind<T>(properties, Multibinder.newSetBinder(binder, interfaceClazz, annotationType));
  }

  private final Properties properties;
  private final Multibinder<T> multibinder;

  public ConditionalMultibind(Properties properties, Multibinder<T> multibinder)
  {
    this.properties = properties;
    this.multibinder = multibinder;
  }

  public ConditionalMultibind conditionBinder(
      String property,
      Predicate<String> condition,
      Class<? extends T> target
  )
  {
    final String value = properties.getProperty(property);
    if (value == null) {
      return this;
    }
    if (condition.apply(value)) {
      multibinder.addBinding().to(target);
    }
    return this;
  }

}

guobingkun avatar Mar 18 '16 15:03 guobingkun