Java Code Examples for org.apache.kafka.common.config.ConfigDef#Recommender

The following examples show how to use org.apache.kafka.common.config.ConfigDef#Recommender . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KafkaConfigProxyFactory.java    From kafka-connect-couchbase with Apache License 2.0 6 votes vote down vote up
protected ConfigDef.Recommender getDefaultRecommender(Method method) {
  CustomTypeHandler<?> customTypeHandler = customTypeMap.get(method.getReturnType());
  if (customTypeHandler != null) {
    ConfigDef.Recommender v = customTypeHandler.recommender();
    if (v != null) {
      return v;
    }
  }

  if (method.getReturnType().isEnum()) {
    //noinspection unchecked
    return new EnumRecommender((Class<? extends Enum<?>>) method.getReturnType());
  }

  return null;
}
 
Example 2
Source File: EnumRecommenderTest.java    From connect-utils with Apache License 2.0 5 votes vote down vote up
@Test
public void visible() {
  ConfigDef.Recommender recommender = Recommenders.enumValues(TestEnum.class);
  final List<Object> actual = recommender.validValues("asdf", ImmutableMap.of());
  final List<Object> expected = ImmutableList.copyOf(Arrays.stream(TestEnum.values()).map(Enum::toString).toArray());
  assertEquals(expected, actual);
}
 
Example 3
Source File: CharsetRecommenderTest.java    From connect-utils with Apache License 2.0 5 votes vote down vote up
@Test
public void validateDefault() {
  final ConfigDef.Recommender recommender = Recommenders.charset();
  final List<Object> expected = ImmutableList.copyOf(Charset.availableCharsets().keySet());
  final List<Object> actual = recommender.validValues("foo", ImmutableMap.of());
  assertEquals(expected, actual);
  assertTrue(recommender.visible("foo", ImmutableMap.of()));
}
 
Example 4
Source File: CharsetRecommenderTest.java    From connect-utils with Apache License 2.0 5 votes vote down vote up
@Test
public void minimalDefault() {
  final ConfigDef.Recommender recommender = Recommenders.charset(VisibleCallback.ALWAYS_VISIBLE, Charsets.UTF_8.name());
  final List<Object> expected = ImmutableList.of(Charsets.UTF_8.name());
  final List<Object> actual = recommender.validValues("foo", ImmutableMap.of());
  assertEquals(expected, actual);
  assertTrue(recommender.visible("foo", ImmutableMap.of()));
}
 
Example 5
Source File: KafkaConfigProxyFactory.java    From kafka-connect-couchbase with Apache License 2.0 5 votes vote down vote up
protected ConfigDef.Recommender getRecommender(Method method) {
  ConfigDef.Recommender userProvided = (ConfigDef.Recommender) invokeCompanion(method, "Recommender");
  if (userProvided != null) {
    return userProvided;
  }
  return getDefaultRecommender(method);
}
 
Example 6
Source File: ConfigKeyBuilder.java    From connect-utils with Apache License 2.0 4 votes vote down vote up
public ConfigDef.Recommender recommender() {
  return this.recommender;
}
 
Example 7
Source File: Recommenders.java    From connect-utils with Apache License 2.0 4 votes vote down vote up
public static ConfigDef.Recommender enumValues(Class<?> enumClass, String... excludes) {
  return enumValues(enumClass, VisibleCallback.ALWAYS_VISIBLE, excludes);
}
 
Example 8
Source File: Recommenders.java    From connect-utils with Apache License 2.0 4 votes vote down vote up
public static ConfigDef.Recommender enumValues(Class<?> enumClass, VisibleCallback visible, String... excludes) {
  return new EnumRecommender(enumClass, visible, excludes);
}
 
Example 9
Source File: Recommenders.java    From connect-utils with Apache License 2.0 4 votes vote down vote up
public static ConfigDef.Recommender charset() {
  return charset(VisibleCallback.ALWAYS_VISIBLE, Charset.availableCharsets().keySet());
}
 
Example 10
Source File: Recommenders.java    From connect-utils with Apache License 2.0 4 votes vote down vote up
public static ConfigDef.Recommender charset(VisibleCallback visible) {
  return charset(visible, Charset.availableCharsets().keySet());
}
 
Example 11
Source File: Recommenders.java    From connect-utils with Apache License 2.0 4 votes vote down vote up
public static ConfigDef.Recommender charset(VisibleCallback visible, String... charsets) {
  return charset(visible, ImmutableList.copyOf(charsets));
}
 
Example 12
Source File: Recommenders.java    From connect-utils with Apache License 2.0 4 votes vote down vote up
public static ConfigDef.Recommender charset(VisibleCallback visible, Iterable<String> charsets) {
  return new CharsetRecommender(charsets, visible);
}
 
Example 13
Source File: VisibleIfRecommenderTest.java    From connect-utils with Apache License 2.0 4 votes vote down vote up
@Test
public void visible() {
  ConfigDef.Recommender recommender = Recommenders.visibleIf("ssl.enabled", true);
  assertTrue(recommender.visible("somekey", ImmutableMap.of("ssl.enabled", true)));
  assertFalse(recommender.visible("somekey", ImmutableMap.of("ssl.enabled", false)));
}
 
Example 14
Source File: KafkaConfigProxyFactory.java    From kafka-connect-couchbase with Apache License 2.0 4 votes vote down vote up
default ConfigDef.Recommender recommender() {
  return null;
}
 
Example 15
Source File: Recommenders.java    From connect-utils with Apache License 2.0 2 votes vote down vote up
/**
 * Method is used to return a recommender that will mark a ConfigItem as visible if
 * the configKey is set to the specified value.
 *
 * @param configKey The setting to retrieve the value from.
 * @param value     The expected value.
 * @return recommender
 */
public static ConfigDef.Recommender visibleIf(String configKey, Object value) {
  return new VisibleIfRecommender(configKey, value, ValidValuesCallback.EMPTY);
}
 
Example 16
Source File: Recommenders.java    From connect-utils with Apache License 2.0 2 votes vote down vote up
/**
 * Method is used to return a recommender that will mark a ConfigItem as visible if
 * the configKey is set to the specified value.
 *
 * @param configKey           The setting to retrieve the value from.
 * @param value               The expected value.
 * @param validValuesCallback The expected value.
 * @return recommender
 */
public static ConfigDef.Recommender visibleIf(String configKey, Object value, ValidValuesCallback validValuesCallback) {
  return new VisibleIfRecommender(configKey, value, validValuesCallback);
}