Package org.apache.kafka.common.config
Class AbstractConfig
- java.lang.Object
-
- org.apache.kafka.common.config.AbstractConfig
-
- Direct Known Subclasses:
AdminClientConfig
,ConsumerConfig
,ConverterConfig
,MirrorClientConfig
,ProducerConfig
,StreamsConfig
public class AbstractConfig extends Object
A convenient base class for configurations to extend.This class holds both the original configuration that was provided as well as the parsed
-
-
Field Summary
Fields Modifier and Type Field Description static String
CONFIG_PROVIDERS_CONFIG
-
Constructor Summary
Constructors Constructor Description AbstractConfig(ConfigDef definition, Map<?,?> originals)
Construct a configuration with a ConfigDef and the configuration properties, which can include properties for zero or moreConfigProvider
that will be used to resolve variables in configuration property values.AbstractConfig(ConfigDef definition, Map<?,?> originals, boolean doLog)
Construct a configuration with a ConfigDef and the configuration properties, which can include properties for zero or moreConfigProvider
that will be used to resolve variables in configuration property values.AbstractConfig(ConfigDef definition, Map<?,?> originals, Map<String,?> configProviderProps, boolean doLog)
Construct a configuration with a ConfigDef and the configuration properties, which can include properties for zero or moreConfigProvider
that will be used to resolve variables in configuration property values.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
documentationOf(String key)
boolean
equals(Object o)
protected Object
get(String key)
Boolean
getBoolean(String key)
Class<?>
getClass(String key)
<T> T
getConfiguredInstance(String key, Class<T> t)
Get a configured instance of the give class specified by the given configuration key.<T> T
getConfiguredInstance(String key, Class<T> t, Map<String,Object> configOverrides)
Get a configured instance of the give class specified by the given configuration key.<T> List<T>
getConfiguredInstances(String key, Class<T> t)
Get a list of configured instances of the given class specified by the given configuration key.<T> List<T>
getConfiguredInstances(String key, Class<T> t, Map<String,Object> configOverrides)
Get a list of configured instances of the given class specified by the given configuration key.<T> List<T>
getConfiguredInstances(List<String> classNames, Class<T> t, Map<String,Object> configOverrides)
Get a list of configured instances of the given class specified by the given configuration key.Double
getDouble(String key)
Integer
getInt(String key)
List<String>
getList(String key)
Long
getLong(String key)
org.apache.kafka.common.config.types.Password
getPassword(String key)
Short
getShort(String key)
String
getString(String key)
int
hashCode()
void
ignore(String key)
void
logUnused()
Log warnings for any unused configurationsMap<String,?>
nonInternalValues()
Map<String,Object>
originals()
Map<String,Object>
originals(Map<String,Object> configOverrides)
Map<String,String>
originalsStrings()
Get all the original settings, ensuring that all values are of type String.Map<String,Object>
originalsWithPrefix(String prefix)
Gets all original settings with the given prefix, stripping the prefix before adding it to the output.Map<String,Object>
originalsWithPrefix(String prefix, boolean strip)
Gets all original settings with the given prefix.protected Map<String,Object>
postProcessParsedConfig(Map<String,Object> parsedValues)
Called directly after user configs got parsed (and thus default values got set).ConfigDef.Type
typeOf(String key)
Set<String>
unused()
Map<String,?>
values()
Map<String,Object>
valuesWithPrefixAllOrNothing(String prefix)
If at least one key withprefix
exists, all prefixed values will be parsed and put into map.Map<String,Object>
valuesWithPrefixOverride(String prefix)
Put all keys that do not start withprefix
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.
-
-
-
Field Detail
-
CONFIG_PROVIDERS_CONFIG
public static final String CONFIG_PROVIDERS_CONFIG
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
AbstractConfig
public AbstractConfig(ConfigDef definition, Map<?,?> originals, Map<String,?> configProviderProps, boolean doLog)
Construct a configuration with a ConfigDef and the configuration properties, which can include properties for zero or moreConfigProvider
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 theConfigProvider
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.- Parameters:
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 inoriginals
; may be null or emptydoLog
- whether the configurations should be logged
-
AbstractConfig
public AbstractConfig(ConfigDef definition, Map<?,?> originals)
Construct a configuration with a ConfigDef and the configuration properties, which can include properties for zero or moreConfigProvider
that will be used to resolve variables in configuration property values.- Parameters:
definition
- the definition of the configurations; may not be nulloriginals
- the configuration properties plus any optional config provider properties; may not be null
-
AbstractConfig
public AbstractConfig(ConfigDef definition, Map<?,?> originals, boolean doLog)
Construct a configuration with a ConfigDef and the configuration properties, which can include properties for zero or moreConfigProvider
that will be used to resolve variables in configuration property values.- Parameters:
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 logged
-
-
Method Detail
-
postProcessParsedConfig
protected Map<String,Object> postProcessParsedConfig(Map<String,Object> parsedValues)
Called directly after user configs got parsed (and thus default values got set). This allows to change default values for "secondary defaults" if required.- Parameters:
parsedValues
- unmodifiable map of current configuration- Returns:
- a map of updates that should be applied to the configuration (will be validated to prevent bad updates)
-
ignore
public void ignore(String key)
-
typeOf
public ConfigDef.Type typeOf(String key)
-
getPassword
public org.apache.kafka.common.config.types.Password getPassword(String key)
-
originalsStrings
public Map<String,String> originalsStrings()
Get all the original settings, ensuring that all values are of type String.- Returns:
- the original settings
- Throws:
ClassCastException
- if any of the values are not strings
-
originalsWithPrefix
public Map<String,Object> originalsWithPrefix(String prefix)
Gets all original settings with the given prefix, stripping the prefix before adding it to the output.- Parameters:
prefix
- the prefix to use as a filter- Returns:
- a Map containing the settings with the prefix
-
originalsWithPrefix
public Map<String,Object> originalsWithPrefix(String prefix, boolean strip)
Gets all original settings with the given prefix.- Parameters:
prefix
- the prefix to use as a filterstrip
- strip the prefix before adding to the output if set true- Returns:
- a Map containing the settings with the prefix
-
valuesWithPrefixOverride
public Map<String,Object> valuesWithPrefixOverride(String prefix)
Put all keys that do not start withprefix
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:
- listener.name.{listenerName}.some.prop: If the provided prefix is `listener.name.{listenerName}.`, the key `some.prop` with the value parsed using the definition of `some.prop` is returned.
- listener.name.{listenerName}.{mechanism}.some.prop: If the provided prefix is `listener.name.{listenerName}.`, the key `{mechanism}.some.prop` with the value parsed using the definition of `some.prop` is returned. This is used to provide per-mechanism configs for a broker listener (e.g sasl.jaas.config)
-
valuesWithPrefixAllOrNothing
public Map<String,Object> valuesWithPrefixAllOrNothing(String prefix)
If at least one key withprefix
exists, all prefixed values will be parsed and put into map. If no value withprefix
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.
-
logUnused
public void logUnused()
Log warnings for any unused configurations
-
getConfiguredInstance
public <T> T getConfiguredInstance(String key, Class<T> t)
Get a configured instance of the give class specified by the given configuration key. If the object implements Configurable configure it using the configuration.- Parameters:
key
- The configuration key for the classt
- The interface the class should implement- Returns:
- A configured instance of the class
-
getConfiguredInstance
public <T> T getConfiguredInstance(String key, Class<T> t, Map<String,Object> configOverrides)
Get a configured instance of the give class specified by the given configuration key. If the object implements Configurable configure it using the configuration.- Parameters:
key
- The configuration key for the classt
- The interface the class should implementconfigOverrides
- override origin configs- Returns:
- A configured instance of the class
-
getConfiguredInstances
public <T> List<T> getConfiguredInstances(String key, Class<T> t)
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.- Parameters:
key
- The configuration key for the classt
- The interface the class should implement- Returns:
- The list of configured instances
-
getConfiguredInstances
public <T> List<T> getConfiguredInstances(String key, Class<T> t, Map<String,Object> configOverrides)
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.- Parameters:
key
- The configuration key for the classt
- The interface the class should implementconfigOverrides
- Configuration overrides to use.- Returns:
- The list of configured instances
-
getConfiguredInstances
public <T> List<T> getConfiguredInstances(List<String> classNames, Class<T> t, Map<String,Object> configOverrides)
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.- Parameters:
classNames
- The list of class names of the instances to createt
- The interface the class should implementconfigOverrides
- Configuration overrides to use.- Returns:
- The list of configured instances
-
-