public class AbstractConfig
extends java.lang.Object
This class holds both the original configuration that was provided as well as the parsed
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
CONFIG_PROVIDERS_CONFIG |
Constructor and Description |
---|
AbstractConfig(ConfigDef definition,
java.util.Map<?,?> originals)
Construct a configuration with a ConfigDef and the configuration properties,
which can include properties for zero or more
ConfigProvider
that will be used to resolve variables in configuration property values. |
AbstractConfig(ConfigDef definition,
java.util.Map<?,?> originals,
boolean doLog)
Construct a configuration with a ConfigDef and the configuration properties,
which can include properties for zero or more
ConfigProvider
that will be used to resolve variables in configuration property values. |
AbstractConfig(ConfigDef definition,
java.util.Map<?,?> originals,
java.util.Map<java.lang.String,?> configProviderProps,
boolean doLog)
Construct a configuration with a ConfigDef and the configuration properties, which can include properties
for zero or more
ConfigProvider that will be used to resolve variables in configuration property
values. |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(java.lang.Object o) |
protected java.lang.Object |
get(java.lang.String key) |
java.lang.Boolean |
getBoolean(java.lang.String key) |
java.lang.Class<?> |
getClass(java.lang.String key) |
<T> T |
getConfiguredInstance(java.lang.String key,
java.lang.Class<T> t)
Get a configured instance of the give class specified by the given configuration key.
|
<T> java.util.List<T> |
getConfiguredInstances(java.util.List<java.lang.String> classNames,
java.lang.Class<T> t,
java.util.Map<java.lang.String,java.lang.Object> configOverrides)
Get a list of configured instances of the given class specified by the given configuration key.
|
<T> java.util.List<T> |
getConfiguredInstances(java.lang.String key,
java.lang.Class<T> t)
Get a list of configured instances of the given class specified by the given configuration key.
|
<T> java.util.List<T> |
getConfiguredInstances(java.lang.String key,
java.lang.Class<T> t,
java.util.Map<java.lang.String,java.lang.Object> configOverrides)
Get a list of configured instances of the given class specified by the given configuration key.
|
java.lang.Double |
getDouble(java.lang.String key) |
java.lang.Integer |
getInt(java.lang.String key) |
java.util.List<java.lang.String> |
getList(java.lang.String key) |
java.lang.Long |
getLong(java.lang.String key) |
org.apache.kafka.common.config.types.Password |
getPassword(java.lang.String key) |
java.lang.Short |
getShort(java.lang.String key) |
java.lang.String |
getString(java.lang.String key) |
int |
hashCode() |
void |
ignore(java.lang.String key) |
void |
logUnused()
Log warnings for any unused configurations
|
java.util.Map<java.lang.String,java.lang.Object> |
originals() |
java.util.Map<java.lang.String,java.lang.String> |
originalsStrings()
Get all the original settings, ensuring that all values are of type String.
|
java.util.Map<java.lang.String,java.lang.Object> |
originalsWithPrefix(java.lang.String prefix)
Gets all original settings with the given prefix, stripping the prefix before adding it to the output.
|
java.util.Map<java.lang.String,java.lang.Object> |
originalsWithPrefix(java.lang.String prefix,
boolean strip)
Gets all original settings with the given prefix.
|
protected java.util.Map<java.lang.String,java.lang.Object> |
postProcessParsedConfig(java.util.Map<java.lang.String,java.lang.Object> parsedValues)
Called directly after user configs got parsed (and thus default values got set).
|
ConfigDef.Type |
typeOf(java.lang.String key) |
java.util.Set<java.lang.String> |
unused() |
java.util.Map<java.lang.String,?> |
values() |
java.util.Map<java.lang.String,java.lang.Object> |
valuesWithPrefixAllOrNothing(java.lang.String prefix)
If at least one key with
prefix exists, all prefixed values will be parsed and put into map. |
java.util.Map<java.lang.String,java.lang.Object> |
valuesWithPrefixOverride(java.lang.String prefix)
Put all keys that do not start with
prefix and their parsed values in the result map and then
put all the remaining keys with the prefix stripped and their parsed values in the result map. |
public static final java.lang.String CONFIG_PROVIDERS_CONFIG
public AbstractConfig(ConfigDef definition, java.util.Map<?,?> originals, java.util.Map<java.lang.String,?> configProviderProps, boolean doLog)
ConfigProvider
that will be used to resolve variables in configuration property
values.
The originals is a name-value pair configuration properties and optional config provider configs. The
value of the configuration can be a variable as defined below or the actual value. This constructor will
first instantiate the ConfigProviders using the config provider configs, then it will find all the
variables in the values of the originals configurations, attempt to resolve the variables using the named
ConfigProviders, and then parse and validate the configurations.
ConfigProvider configs can be passed either as configs in the originals map or in the separate
configProviderProps map. If config providers properties are passed in the configProviderProps any config
provider properties in originals map will be ignored. If ConfigProvider properties are not provided, the
constructor will skip the variable substitution step and will simply validate and parse the supplied
configuration.
The "config.providers
" configuration property and all configuration properties that begin with the
"config.providers.
" prefix are reserved. The "config.providers
" configuration property
specifies the names of the config providers, and properties that begin with the "config.providers..
"
prefix correspond to the properties for that named provider. For example, the "config.providers..class
"
property specifies the name of the ConfigProvider
implementation class that should be used for
the provider.
The keys for ConfigProvider configs in both originals and configProviderProps will start with the above
mentioned "config.providers.
" prefix.
Variables have the form "${providerName:[path:]key}", where "providerName" is the name of a ConfigProvider,
"path" is an optional string, and "key" is a required string. This variable is resolved by passing the "key"
and optional "path" to a ConfigProvider with the specified name, and the result from the ConfigProvider is
then used in place of the variable. Variables that cannot be resolved by the AbstractConfig constructor will
be left unchanged in the configuration.definition
- the definition of the configurations; may not be nulloriginals
- the configuration properties plus any optional config provider properties;configProviderProps
- the map of properties of config providers which will be instantiated by
the constructor to resolve any variables in originals
; may be null or emptydoLog
- whether the configurations should be loggedpublic AbstractConfig(ConfigDef definition, java.util.Map<?,?> originals)
ConfigProvider
that will be used to resolve variables in configuration property values.definition
- the definition of the configurations; may not be nulloriginals
- the configuration properties plus any optional config provider properties; may not be nullpublic AbstractConfig(ConfigDef definition, java.util.Map<?,?> originals, boolean doLog)
ConfigProvider
that will be used to resolve variables in configuration property values.definition
- the definition of the configurations; may not be nulloriginals
- the configuration properties plus any optional config provider properties; may not be nulldoLog
- whether the configurations should be loggedprotected java.util.Map<java.lang.String,java.lang.Object> postProcessParsedConfig(java.util.Map<java.lang.String,java.lang.Object> parsedValues)
parsedValues
- unmodifiable map of current configurationprotected java.lang.Object get(java.lang.String key)
public void ignore(java.lang.String key)
public java.lang.Short getShort(java.lang.String key)
public java.lang.Integer getInt(java.lang.String key)
public java.lang.Long getLong(java.lang.String key)
public java.lang.Double getDouble(java.lang.String key)
public java.util.List<java.lang.String> getList(java.lang.String key)
public java.lang.Boolean getBoolean(java.lang.String key)
public java.lang.String getString(java.lang.String key)
public ConfigDef.Type typeOf(java.lang.String key)
public org.apache.kafka.common.config.types.Password getPassword(java.lang.String key)
public java.lang.Class<?> getClass(java.lang.String key)
public java.util.Set<java.lang.String> unused()
public java.util.Map<java.lang.String,java.lang.Object> originals()
public java.util.Map<java.lang.String,java.lang.String> originalsStrings()
java.lang.ClassCastException
- if any of the values are not stringspublic java.util.Map<java.lang.String,java.lang.Object> originalsWithPrefix(java.lang.String prefix)
prefix
- the prefix to use as a filterpublic java.util.Map<java.lang.String,java.lang.Object> originalsWithPrefix(java.lang.String prefix, boolean strip)
prefix
- the prefix to use as a filterstrip
- strip the prefix before adding to the output if set truepublic java.util.Map<java.lang.String,java.lang.Object> valuesWithPrefixOverride(java.lang.String prefix)
prefix
and their parsed values in the result map and then
put all the remaining keys with the prefix stripped and their parsed values in the result map.
This is useful if one wants to allow prefixed configs to override default ones.
Two forms of prefixes are supported:
public java.util.Map<java.lang.String,java.lang.Object> valuesWithPrefixAllOrNothing(java.lang.String prefix)
prefix
exists, all prefixed values will be parsed and put into map.
If no value with prefix
exists all unprefixed values will be returned.
This is useful if one wants to allow prefixed configs to override default ones, but wants to use either
only prefixed configs or only regular configs, but not mix them.public java.util.Map<java.lang.String,?> values()
public void logUnused()
public <T> T getConfiguredInstance(java.lang.String key, java.lang.Class<T> t)
key
- The configuration key for the classt
- The interface the class should implementpublic <T> java.util.List<T> getConfiguredInstances(java.lang.String key, java.lang.Class<T> t)
key
- The configuration key for the classt
- The interface the class should implementpublic <T> java.util.List<T> getConfiguredInstances(java.lang.String key, java.lang.Class<T> t, java.util.Map<java.lang.String,java.lang.Object> configOverrides)
key
- The configuration key for the classt
- The interface the class should implementconfigOverrides
- Configuration overrides to use.public <T> java.util.List<T> getConfiguredInstances(java.util.List<java.lang.String> classNames, java.lang.Class<T> t, java.util.Map<java.lang.String,java.lang.Object> configOverrides)
classNames
- The list of class names of the instances to createt
- The interface the class should implementconfigOverrides
- Configuration overrides to use.public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object