public class ConfigDef extends Object
ConfigDef.Validator
.
Moreover, you can specify the dependents of a configuration. The valid values and visibility of a configuration
may change according to the values of other configurations. You can override ConfigDef.Recommender
to get valid
values and set visibility of a configuration given the current configuration values.
To use the class:
ConfigDef defs = new ConfigDef(); // checkThis class can be used standalone or in combination withdefine(String, Type, Object, Importance, String)
for more details. defs.define("config_with_default", Type.STRING, "default string value", Importance.High, "Configuration with default value."); // checkdefine(String, Type, Object, Validator, Importance, String)
for more details. defs.define("config_with_validator", Type.INT, 42, Range.atLeast(0), Importance.High, "Configuration with user provided validator."); // checkdefine(String, Type, Importance, String, String, int, Width, String, List<String>)
for more details. defs.define("config_with_dependents", Type.INT, Importance.LOW, "Configuration with dependents.", "group", 1, Width.SHORT, "Config With Dependents", Arrays.asList("config_with_default","config_with_validator")); Map<String, String> props = new HashMap<>(); props.put("config_with_default", "some value"); props.put("config_with_dependents", "some other value"); Map<String, Object> configs = defs.parse(props); // will return "some value" String someConfig = (String) configs.get("config_with_default"); // will return default value of 42 int anotherConfig = (Integer) configs.get("config_with_validator"); // To validate the full configuration, use: List<ConfigValue> configValues = defs.validate(props); // TheConfigValue
contains updated configuration information given the current configuration values.
AbstractConfig
which provides some additional
functionality for accessing configs.Modifier and Type | Class and Description |
---|---|
static class |
ConfigDef.CaseInsensitiveValidString |
static class |
ConfigDef.CompositeValidator |
static class |
ConfigDef.ConcreteSubClassValidator |
static class |
ConfigDef.ConfigKey |
static class |
ConfigDef.Importance
The importance level for a configuration
|
static class |
ConfigDef.InstantiableClassValidator |
static class |
ConfigDef.LambdaValidator |
static class |
ConfigDef.ListSize |
static class |
ConfigDef.NonEmptyString |
static class |
ConfigDef.NonEmptyStringWithoutControlChars |
static class |
ConfigDef.NonNullValidator |
static class |
ConfigDef.Range
Validation logic for numeric ranges
|
static interface |
ConfigDef.Recommender
This is used by the
validate(Map) to get valid values for a configuration given the current
configuration values in order to perform full configuration validation and visibility modification. |
static class |
ConfigDef.Type
The type for a configuration value
|
static interface |
ConfigDef.Validator
Validation logic the user may provide to perform single configuration validation.
|
static class |
ConfigDef.ValidList |
static class |
ConfigDef.ValidString |
static class |
ConfigDef.Width
The width of a configuration value
|
Modifier and Type | Field and Description |
---|---|
static Object |
NO_DEFAULT_VALUE
A unique Java object which represents the lack of a default value.
|
Modifier and Type | Method and Description |
---|---|
Map<String,ConfigDef.ConfigKey> |
configKeys()
Get the configuration keys
|
static String |
convertToString(Object parsedValue,
ConfigDef.Type type) |
static Map<String,String> |
convertToStringMapWithPasswordValues(Map<String,?> configs)
Converts a map of config (key, value) pairs to a map of strings where each value
is converted to a string.
|
Map<String,Object> |
defaultValues() |
ConfigDef |
define(ConfigDef.ConfigKey key) |
ConfigDef |
define(String name,
ConfigDef.Type type,
ConfigDef.Importance importance,
String documentation)
Define a new configuration with no default value and no special validation logic
|
ConfigDef |
define(String name,
ConfigDef.Type type,
ConfigDef.Importance importance,
String documentation,
String group,
int orderInGroup,
ConfigDef.Width width,
String displayName)
Define a new configuration with no default value, no special validation logic, no dependents and no custom recommender
|
ConfigDef |
define(String name,
ConfigDef.Type type,
ConfigDef.Importance importance,
String documentation,
String group,
int orderInGroup,
ConfigDef.Width width,
String displayName,
ConfigDef.Recommender recommender)
Define a new configuration with no default value, no special validation logic and no custom recommender
|
ConfigDef |
define(String name,
ConfigDef.Type type,
ConfigDef.Importance importance,
String documentation,
String group,
int orderInGroup,
ConfigDef.Width width,
String displayName,
List<String> dependents)
Define a new configuration with no default value, no special validation logic and no custom recommender
|
ConfigDef |
define(String name,
ConfigDef.Type type,
ConfigDef.Importance importance,
String documentation,
String group,
int orderInGroup,
ConfigDef.Width width,
String displayName,
List<String> dependents,
ConfigDef.Recommender recommender)
Define a new configuration with no default value and no special validation logic
|
ConfigDef |
define(String name,
ConfigDef.Type type,
Object defaultValue,
ConfigDef.Importance importance,
String documentation)
Define a new configuration with no special validation logic
|
ConfigDef |
define(String name,
ConfigDef.Type type,
Object defaultValue,
ConfigDef.Importance importance,
String documentation,
String alternativeString)
Define a new configuration with no special validation logic
|
ConfigDef |
define(String name,
ConfigDef.Type type,
Object defaultValue,
ConfigDef.Importance importance,
String documentation,
String group,
int orderInGroup,
ConfigDef.Width width,
String displayName)
Define a new configuration with no special validation logic, not dependents and no custom recommender
|
ConfigDef |
define(String name,
ConfigDef.Type type,
Object defaultValue,
ConfigDef.Importance importance,
String documentation,
String group,
int orderInGroup,
ConfigDef.Width width,
String displayName,
ConfigDef.Recommender recommender)
Define a new configuration with no special validation logic and no custom recommender
|
ConfigDef |
define(String name,
ConfigDef.Type type,
Object defaultValue,
ConfigDef.Importance importance,
String documentation,
String group,
int orderInGroup,
ConfigDef.Width width,
String displayName,
List<String> dependents)
Define a new configuration with no special validation logic and no custom recommender
|
ConfigDef |
define(String name,
ConfigDef.Type type,
Object defaultValue,
ConfigDef.Importance importance,
String documentation,
String group,
int orderInGroup,
ConfigDef.Width width,
String displayName,
List<String> dependents,
ConfigDef.Recommender recommender)
Define a new configuration with no special validation logic
|
ConfigDef |
define(String name,
ConfigDef.Type type,
Object defaultValue,
ConfigDef.Validator validator,
ConfigDef.Importance importance,
String documentation)
Define a new configuration with no group, no order in group, no width, no display name, no dependents and no custom recommender
|
ConfigDef |
define(String name,
ConfigDef.Type type,
Object defaultValue,
ConfigDef.Validator validator,
ConfigDef.Importance importance,
String documentation,
String group,
int orderInGroup,
ConfigDef.Width width,
String displayName)
Define a new configuration with no dependents and no custom recommender
|
ConfigDef |
define(String name,
ConfigDef.Type type,
Object defaultValue,
ConfigDef.Validator validator,
ConfigDef.Importance importance,
String documentation,
String group,
int orderInGroup,
ConfigDef.Width width,
String displayName,
ConfigDef.Recommender recommender)
Define a new configuration with no dependents
|
ConfigDef |
define(String name,
ConfigDef.Type type,
Object defaultValue,
ConfigDef.Validator validator,
ConfigDef.Importance importance,
String documentation,
String group,
int orderInGroup,
ConfigDef.Width width,
String displayName,
List<String> dependents)
Define a new configuration with no custom recommender
|
ConfigDef |
define(String name,
ConfigDef.Type type,
Object defaultValue,
ConfigDef.Validator validator,
ConfigDef.Importance importance,
String documentation,
String group,
int orderInGroup,
ConfigDef.Width width,
String displayName,
List<String> dependents,
ConfigDef.Recommender recommender)
Define a new configuration
|
ConfigDef |
define(String name,
ConfigDef.Type type,
Object defaultValue,
ConfigDef.Validator validator,
ConfigDef.Importance importance,
String documentation,
String group,
int orderInGroup,
ConfigDef.Width width,
String displayName,
List<String> dependents,
ConfigDef.Recommender recommender,
String alternativeString)
Define a new configuration
|
ConfigDef |
defineBalancerConfigs() |
ConfigDef |
defineInternal(String name,
ConfigDef.Type type,
Object defaultValue,
ConfigDef.Importance importance)
Define a new internal configuration.
|
ConfigDef |
defineInternal(String name,
ConfigDef.Type type,
Object defaultValue,
ConfigDef.Importance importance,
String documentation)
Define a new internal configuration.
|
ConfigDef |
defineInternal(String name,
ConfigDef.Type type,
Object defaultValue,
ConfigDef.Validator validator,
ConfigDef.Importance importance,
String documentation)
Define a new internal configuration.
|
void |
embed(String keyPrefix,
String groupPrefix,
int startingOrd,
ConfigDef child) |
List<String> |
groups()
Get the groups for the configuration
|
Set<String> |
names()
Returns unmodifiable set of properties names defined in this ConfigDef
|
Map<String,Object> |
parse(Map<?,?> props)
Parse and validate configs against this configuration definition.
|
static Object |
parseType(String name,
Object value,
ConfigDef.Type type)
Parse a value according to its expected type.
|
String |
toEnrichedRst()
Configs with new metadata (group, orderInGroup, dependents) formatted with reStructuredText, suitable for embedding in Sphinx
documentation.
|
String |
toHtml() |
String |
toHtml(int headerDepth,
Function<String,String> idGenerator)
Converts this config into an HTML list that can be embedded into docs.
|
String |
toHtml(int headerDepth,
Function<String,String> idGenerator,
Map<String,String> dynamicUpdateModes)
Converts this config into an HTML list that can be embedded into docs.
|
String |
toHtml(Map<String,String> dynamicUpdateModes)
Converts this config into an HTML list that can be embedded into docs.
|
String |
toHtmlTable() |
String |
toHtmlTable(Map<String,String> dynamicUpdateModes)
Converts this config into an HTML table that can be embedded into docs.
|
String |
toRst()
Get the configs formatted with reStructuredText, suitable for embedding in Sphinx
documentation.
|
List<ConfigValue> |
validate(Map<String,String> props)
Validate the current configuration values with the configuration definition.
|
Map<String,ConfigValue> |
validateAll(Map<String,String> props) |
ConfigDef |
withClientSaslSupport()
Add standard SASL client configuration options.
|
ConfigDef |
withClientSslSupport()
Add standard SSL client configuration options.
|
public static final Object NO_DEFAULT_VALUE
public ConfigDef()
public ConfigDef(ConfigDef base)
public Set<String> names()
Set
instance containing the keyspublic ConfigDef define(ConfigDef.ConfigKey key)
public ConfigDef define(String name, ConfigDef.Type type, Object defaultValue, ConfigDef.Validator validator, ConfigDef.Importance importance, String documentation, String group, int orderInGroup, ConfigDef.Width width, String displayName, List<String> dependents, ConfigDef.Recommender recommender)
name
- the name of the config parametertype
- the type of the configdefaultValue
- the default value to use if this config isn't presentvalidator
- the validator to use in checking the correctness of the configimportance
- the importance of this configdocumentation
- the documentation string for the configgroup
- the group this config belongs toorderInGroup
- the order of this config in the groupwidth
- the width of the configdisplayName
- the name suitable for displaydependents
- the configurations that are dependents of this configurationrecommender
- the recommender provides valid values given the parent configuration valuespublic ConfigDef define(String name, ConfigDef.Type type, Object defaultValue, ConfigDef.Validator validator, ConfigDef.Importance importance, String documentation, String group, int orderInGroup, ConfigDef.Width width, String displayName, List<String> dependents, ConfigDef.Recommender recommender, String alternativeString)
name
- the name of the config parametertype
- the type of the configdefaultValue
- the default value to use if this config isn't presentvalidator
- the validator to use in checking the correctness of the configimportance
- the importance of this configdocumentation
- the documentation string for the configgroup
- the group this config belongs toorderInGroup
- the order of this config in the groupwidth
- the width of the configdisplayName
- the name suitable for displaydependents
- the configurations that are dependents of this configurationrecommender
- the recommender provides valid values given the parent configuration valuesalternativeString
- the string which will be used to override the string of defaultValuepublic ConfigDef define(String name, ConfigDef.Type type, Object defaultValue, ConfigDef.Validator validator, ConfigDef.Importance importance, String documentation, String group, int orderInGroup, ConfigDef.Width width, String displayName, List<String> dependents)
name
- the name of the config parametertype
- the type of the configdefaultValue
- the default value to use if this config isn't presentvalidator
- the validator to use in checking the correctness of the configimportance
- the importance of this configdocumentation
- the documentation string for the configgroup
- the group this config belongs toorderInGroup
- the order of this config in the groupwidth
- the width of the configdisplayName
- the name suitable for displaydependents
- the configurations that are dependents of this configurationpublic ConfigDef define(String name, ConfigDef.Type type, Object defaultValue, ConfigDef.Validator validator, ConfigDef.Importance importance, String documentation, String group, int orderInGroup, ConfigDef.Width width, String displayName, ConfigDef.Recommender recommender)
name
- the name of the config parametertype
- the type of the configdefaultValue
- the default value to use if this config isn't presentvalidator
- the validator to use in checking the correctness of the configimportance
- the importance of this configdocumentation
- the documentation string for the configgroup
- the group this config belongs toorderInGroup
- the order of this config in the groupwidth
- the width of the configdisplayName
- the name suitable for displayrecommender
- the recommender provides valid values given the parent configuration valuespublic ConfigDef define(String name, ConfigDef.Type type, Object defaultValue, ConfigDef.Validator validator, ConfigDef.Importance importance, String documentation, String group, int orderInGroup, ConfigDef.Width width, String displayName)
name
- the name of the config parametertype
- the type of the configdefaultValue
- the default value to use if this config isn't presentvalidator
- the validator to use in checking the correctness of the configimportance
- the importance of this configdocumentation
- the documentation string for the configgroup
- the group this config belongs toorderInGroup
- the order of this config in the groupwidth
- the width of the configdisplayName
- the name suitable for displaypublic ConfigDef define(String name, ConfigDef.Type type, Object defaultValue, ConfigDef.Importance importance, String documentation, String group, int orderInGroup, ConfigDef.Width width, String displayName, List<String> dependents, ConfigDef.Recommender recommender)
name
- the name of the config parametertype
- the type of the configdefaultValue
- the default value to use if this config isn't presentimportance
- the importance of this configdocumentation
- the documentation string for the configgroup
- the group this config belongs toorderInGroup
- the order of this config in the groupwidth
- the width of the configdisplayName
- the name suitable for displaydependents
- the configurations that are dependents of this configurationrecommender
- the recommender provides valid values given the parent configuration valuespublic ConfigDef define(String name, ConfigDef.Type type, Object defaultValue, ConfigDef.Importance importance, String documentation, String group, int orderInGroup, ConfigDef.Width width, String displayName, List<String> dependents)
name
- the name of the config parametertype
- the type of the configdefaultValue
- the default value to use if this config isn't presentimportance
- the importance of this configdocumentation
- the documentation string for the configgroup
- the group this config belongs toorderInGroup
- the order of this config in the groupwidth
- the width of the configdisplayName
- the name suitable for displaydependents
- the configurations that are dependents of this configurationpublic ConfigDef define(String name, ConfigDef.Type type, Object defaultValue, ConfigDef.Importance importance, String documentation, String group, int orderInGroup, ConfigDef.Width width, String displayName, ConfigDef.Recommender recommender)
name
- the name of the config parametertype
- the type of the configdefaultValue
- the default value to use if this config isn't presentimportance
- the importance of this configdocumentation
- the documentation string for the configgroup
- the group this config belongs toorderInGroup
- the order of this config in the groupwidth
- the width of the configdisplayName
- the name suitable for displayrecommender
- the recommender provides valid values given the parent configuration valuespublic ConfigDef define(String name, ConfigDef.Type type, Object defaultValue, ConfigDef.Importance importance, String documentation, String group, int orderInGroup, ConfigDef.Width width, String displayName)
name
- the name of the config parametertype
- the type of the configdefaultValue
- the default value to use if this config isn't presentimportance
- the importance of this configdocumentation
- the documentation string for the configgroup
- the group this config belongs toorderInGroup
- the order of this config in the groupwidth
- the width of the configdisplayName
- the name suitable for displaypublic ConfigDef define(String name, ConfigDef.Type type, ConfigDef.Importance importance, String documentation, String group, int orderInGroup, ConfigDef.Width width, String displayName, List<String> dependents, ConfigDef.Recommender recommender)
name
- the name of the config parametertype
- the type of the configimportance
- the importance of this configdocumentation
- the documentation string for the configgroup
- the group this config belongs toorderInGroup
- the order of this config in the groupwidth
- the width of the configdisplayName
- the name suitable for displaydependents
- the configurations that are dependents of this configurationrecommender
- the recommender provides valid values given the parent configuration valuepublic ConfigDef define(String name, ConfigDef.Type type, ConfigDef.Importance importance, String documentation, String group, int orderInGroup, ConfigDef.Width width, String displayName, List<String> dependents)
name
- the name of the config parametertype
- the type of the configimportance
- the importance of this configdocumentation
- the documentation string for the configgroup
- the group this config belongs toorderInGroup
- the order of this config in the groupwidth
- the width of the configdisplayName
- the name suitable for displaydependents
- the configurations that are dependents of this configurationpublic ConfigDef define(String name, ConfigDef.Type type, ConfigDef.Importance importance, String documentation, String group, int orderInGroup, ConfigDef.Width width, String displayName, ConfigDef.Recommender recommender)
name
- the name of the config parametertype
- the type of the configimportance
- the importance of this configdocumentation
- the documentation string for the configgroup
- the group this config belongs toorderInGroup
- the order of this config in the groupwidth
- the width of the configdisplayName
- the name suitable for displayrecommender
- the recommender provides valid values given the parent configuration valuepublic ConfigDef define(String name, ConfigDef.Type type, ConfigDef.Importance importance, String documentation, String group, int orderInGroup, ConfigDef.Width width, String displayName)
name
- the name of the config parametertype
- the type of the configimportance
- the importance of this configdocumentation
- the documentation string for the configgroup
- the group this config belongs toorderInGroup
- the order of this config in the groupwidth
- the width of the configdisplayName
- the name suitable for displaypublic ConfigDef define(String name, ConfigDef.Type type, Object defaultValue, ConfigDef.Validator validator, ConfigDef.Importance importance, String documentation)
name
- the name of the config parametertype
- the type of the configdefaultValue
- the default value to use if this config isn't presentvalidator
- the validator to use in checking the correctness of the configimportance
- the importance of this configdocumentation
- the documentation string for the configpublic ConfigDef define(String name, ConfigDef.Type type, Object defaultValue, ConfigDef.Importance importance, String documentation)
name
- The name of the config parametertype
- The type of the configdefaultValue
- The default value to use if this config isn't presentimportance
- The importance of this config: is this something you will likely need to change.documentation
- The documentation string for the configpublic ConfigDef define(String name, ConfigDef.Type type, Object defaultValue, ConfigDef.Importance importance, String documentation, String alternativeString)
name
- The name of the config parametertype
- The type of the configdefaultValue
- The default value to use if this config isn't presentimportance
- The importance of this config: is this something you will likely need to change.documentation
- The documentation string for the configalternativeString
- The string which will be used to override the string of defaultValuepublic ConfigDef define(String name, ConfigDef.Type type, ConfigDef.Importance importance, String documentation)
name
- The name of the config parametertype
- The type of the configimportance
- The importance of this config: is this something you will likely need to change.documentation
- The documentation string for the configpublic ConfigDef defineInternal(String name, ConfigDef.Type type, Object defaultValue, ConfigDef.Importance importance)
name
- The name of the config parametertype
- The type of the configdefaultValue
- The default value to use if this config isn't presentimportance
- The importance of this config (i.e. is this something you will likely need to change?)public ConfigDef defineInternal(String name, ConfigDef.Type type, Object defaultValue, ConfigDef.Importance importance, String documentation)
name
- The name of the config parametertype
- The type of the configdefaultValue
- The default value to use if this config isn't presentimportance
- The importance of this config (i.e. is this something you will likely need to change?)documentation
- The documentation string for the configpublic ConfigDef defineInternal(String name, ConfigDef.Type type, Object defaultValue, ConfigDef.Validator validator, ConfigDef.Importance importance, String documentation)
name
- The name of the config parametertype
- The type of the configdefaultValue
- The default value to use if this config isn't presentvalidator
- The validator to use in checking the correctness of the configimportance
- The importance of this config (i.e. is this something you will likely need to change?)documentation
- The documentation string for the configpublic ConfigDef defineBalancerConfigs()
public Map<String,ConfigDef.ConfigKey> configKeys()
public List<String> groups()
public ConfigDef withClientSslSupport()
public ConfigDef withClientSaslSupport()
public Map<String,Object> parse(Map<?,?> props)
props
- The configs to parse and validate.public List<ConfigValue> validate(Map<String,String> props)
props
- the current configuration valuespublic static Object parseType(String name, Object value, ConfigDef.Type type)
name
- The config namevalue
- The config valuetype
- The expected typepublic static String convertToString(Object parsedValue, ConfigDef.Type type)
public static Map<String,String> convertToStringMapWithPasswordValues(Map<String,?> configs)
public String toHtmlTable()
public String toHtmlTable(Map<String,String> dynamicUpdateModes)
dynamicUpdateModes
is non-empty, a "Dynamic Update Mode" column
will be included n the table with the value of the update mode. Default
mode is "read-only".dynamicUpdateModes
- Config name -> update mode mappingpublic String toRst()
public String toEnrichedRst()
public String toHtml()
public String toHtml(int headerDepth, Function<String,String> idGenerator)
headerDepth
- The top level header depth in the generated HTML.idGenerator
- A function for computing the HTML id attribute in the generated HTML from a given config name.public String toHtml(Map<String,String> dynamicUpdateModes)
dynamicUpdateModes
is non-empty, a "Dynamic Update Mode" label
will be included in the config details with the value of the update mode. Default
mode is "read-only".dynamicUpdateModes
- Config name -> update mode mapping.public String toHtml(int headerDepth, Function<String,String> idGenerator, Map<String,String> dynamicUpdateModes)
dynamicUpdateModes
is non-empty, a "Dynamic Update Mode" label
will be included in the config details with the value of the update mode. Default
mode is "read-only".headerDepth
- The top level header depth in the generated HTML.idGenerator
- A function for computing the HTML id attribute in the generated HTML from a given config name.dynamicUpdateModes
- Config name -> update mode mapping.