@Override public boolean visible(String name, Map<String, Object> parsedConfig) { return base.visible(unprefixed(name), unprefixed(parsedConfig)); } };
@Override public List<Object> validValues(String name, Map<String, Object> parsedConfig) { return base.validValues(unprefixed(name), unprefixed(parsedConfig)); }
/** * Add standard SSL client configuration options. * @return this */ public ConfigDef withClientSslSupport() { SslConfigs.addClientSslSupport(this); return this; }
/** * Define a new configuration with no special validation logic * @param name The name of the config parameter * @param type The type of the config * @param defaultValue The default value to use if this config isn't present * @param importance The importance of this config: is this something you will likely need to change. * @param documentation The documentation string for the config * @return This ConfigDef so you can chain calls */ public ConfigDef define(String name, Type type, Object defaultValue, Importance importance, String documentation) { return define(name, type, defaultValue, null, importance, documentation); }
@Override public void ensureValid(String name, Object value) { if (value == null) { // Pass in the string null to avoid the spotbugs warning throw new ConfigException(name, "null", "entry must be non null"); } }
/** * Define a new internal configuration. Internal configuration won't show up in the docs and aren't * intended for general use. * @param name The name of the config parameter * @param type The type of the config * @param defaultValue The default value to use if this config isn't present * @param importance * @return This ConfigDef so you can chain calls */ public ConfigDef defineInternal(final String name, final Type type, final Object defaultValue, final Importance importance) { return define(new ConfigKey(name, type, defaultValue, null, importance, "", "", -1, Width.NONE, name, Collections.<String>emptyList(), null, true)); }
@Test public void testValidators() { testValidators(Type.INT, Range.between(0, 10), 5, new Object[]{1, 5, 9}, new Object[]{-1, 11, null}); testValidators(Type.STRING, ValidString.in("good", "values", "default"), "default", new Object[]{"good", "values", "default"}, new Object[]{"bad", "inputs", null}); testValidators(Type.LIST, ConfigDef.ValidList.in("1", "2", "3"), "1", new Object[]{"1", "2", "3"}, new Object[]{"4", "5", "6"}); testValidators(Type.STRING, new ConfigDef.NonNullValidator(), "a", new Object[]{"abb"}, new Object[] {null}); testValidators(Type.STRING, ConfigDef.CompositeValidator.of(new ConfigDef.NonNullValidator(), ValidString.in("a", "b")), "a", new Object[]{"a", "b"}, new Object[] {null, -1, "c"}); testValidators(Type.STRING, new ConfigDef.NonEmptyStringWithoutControlChars(), "defaultname", new Object[]{"test", "name", "test/test", "test\u1234", "\u1324name\\", "/+%>&):??<&()?-", "+1", "\uD83D\uDE01", "\uF3B1", " test \n\r", "\n hello \t"}, new Object[]{"nontrailing\nnotallowed", "as\u0001cii control char", "tes\rt", "test\btest", "1\t2", ""}); }
/** * Get a list of configured instances of the given class specified by the given configuration key. The configuration * may specify either null or an empty string to indicate no configured instances. In both cases, this method * returns an empty list to indicate no configured instances. * @param key The configuration key for the class * @param t The interface the class should implement * @param configOverrides Configuration overrides to use. * @return The list of configured instances */ public <T> List<T> getConfiguredInstances(String key, Class<T> t, Map<String, Object> configOverrides) { return getConfiguredInstances(getList(key), t, configOverrides); }
@Override public void ensureValid(String name, Object value) { for (Validator validator: validators) { validator.ensureValid(name, value); } }
private Map<String, ConfigValue> validate(Map<String, Object> parsed, Map<String, ConfigValue> configValues) { Set<String> configsWithNoParent = getConfigsWithNoParent(); for (String name: configsWithNoParent) { validate(name, parsed, configValues); } return configValues; }
@SuppressWarnings("unchecked") public List<String> getList(String key) { return (List<String>) get(key); }
/** * A numeric range that checks both the upper (inclusive) and lower bound */ public static Range between(Number min, Number max) { return new Range(min, max); }
/** * Gets all original settings with the given prefix, stripping the prefix before adding it to the output. * * @param prefix the prefix to use as a filter * @return a Map containing the settings with the prefix */ public Map<String, Object> originalsWithPrefix(String prefix) { return originalsWithPrefix(prefix, true); }
@Override public void configure(Map<String, ?> configs) { FakeMetricsReporterConfig config = new FakeMetricsReporterConfig(configs); // Calling getString() should have the side effect of marking that config as used. config.getString(FakeMetricsReporterConfig.EXTRA_CONFIG); } }
@Override public void ensureValid(final String name, final Object value) { @SuppressWarnings("unchecked") List<String> values = (List<String>) value; for (String string : values) { validString.ensureValid(name, string); } }
/** * Add standard SASL client configuration options. * @return this */ public ConfigDef withClientSaslSupport() { SaslConfigs.addClientSaslSupport(this); return this; }
public String toString() { return validString.toString(); } }
/** * Define a new configuration with no default value and no special validation logic * @param name The name of the config parameter * @param type The type of the config * @param importance The importance of this config: is this something you will likely need to change. * @param documentation The documentation string for the config * @return This ConfigDef so you can chain calls */ public ConfigDef define(String name, Type type, Importance importance, String documentation) { return define(name, type, NO_DEFAULT_VALUE, null, importance, documentation); }
/** * A numeric range that checks only the lower bound * * @param min The minimum acceptable value */ public static Range atLeast(Number min) { return new Range(min, null); }
/** * Define a new configuration with no group, no order in group, no width, no display name, no dependents and no custom recommender * @param name the name of the config parameter * @param type the type of the config * @param defaultValue the default value to use if this config isn't present * @param validator the validator to use in checking the correctness of the config * @param importance the importance of this config * @param documentation the documentation string for the config * @return This ConfigDef so you can chain calls */ public ConfigDef define(String name, Type type, Object defaultValue, Validator validator, Importance importance, String documentation) { return define(name, type, defaultValue, validator, importance, documentation, null, -1, Width.NONE, name); }