Package io.debezium.config
Interface Configuration
-
- All Known Subinterfaces:
JdbcConfiguration
@Immutable public interface Configuration
An immutable representation of a Debezium configuration. AConfigurationinstance can be obtainedfrom Propertiesor loaded from afile,stream,reader,URL, orclasspath resource. They can also be built by firstcreating a builderand then using that builder to populate andreturnthe immutable Configuration instance.A Configuration object is basically a decorator around a
Propertiesobject. It has methods to get and convert individual property values to numeric, boolean and String types, optionally using a default value if the given property value does not exist. However, it isimmutable, so it does not have any methods to set property values, allowing it to be passed around and reused without concern that other components might change the underlying property values.- Author:
- Randall Hauch
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classConfiguration.BuilderA builder of Configuration objects.static interfaceConfiguration.ConfigBuilder<C extends Configuration,B extends Configuration.ConfigBuilder<C,B>>The basic interface for configuration builders.
-
Field Summary
Fields Modifier and Type Field Description static org.slf4j.LoggerCONFIGURATION_LOGGERstatic PatternPASSWORD_PATTERN
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default Map<String,String>asMap()Get a copy of these configuration properties as a Properties object.default Map<String,String>asMap(Field.Set fields)Get a copy of these configuration properties with defaults as a Map.default PropertiesasProperties()Get a copy of these configuration properties as a Properties object.default PropertiesasProperties(Field.Set fields)Get a copy of these configuration properties as a Properties object.static Configuration.Buildercopy(Configuration config)Create a newconfiguration builderthat starts with a copy of the supplied configuration.static Configuration.Buildercreate()Create a newconfiguration builder.default Configuration.Builderedit()Obtain an editor for a copy of this configuration.static Configurationempty()Obtain an empty configuration.default Configurationfilter(Predicate<? super String> matcher)Return a newConfigurationthat contains only the subset of keys that satisfy the given predicate.default <T> voidforEach(BiConsumer<String,String> function)Call the supplied function for each of the fields.default <T> voidforEachMatchingFieldName(String regex, int groupNumber, BiFunction<String,String,T> groupExtractor, BiConsumer<String,T> function)For all fields whose names match the given regular expression, extract a value from the specified group in the regular expression and call the supplied function.default voidforEachMatchingFieldName(String regex, BiConsumer<String,String> function)Apply the given function to all fields whose names match the given regular expression.default <T> voidforEachMatchingFieldName(Pattern regex, int groupNumber, BiFunction<String,String,T> groupExtractor, BiConsumer<String,T> function)For all fields whose names match the given regular expression, extract a value from the specified group in the regular expression and call the supplied function.default voidforEachMatchingFieldName(Pattern regex, BiConsumer<String,String> function)Apply the given function to all fields whose names match the given regular expression.default <T> voidforEachMatchingFieldNameWithBoolean(String regex, int groupNumber, BiConsumer<String,Boolean> function)For all fields whose names match the given regular expression, extract a boolean value from the first group in the regular expression and call the supplied function.default <T> voidforEachMatchingFieldNameWithBoolean(String regex, BiConsumer<String,Boolean> function)For all fields whose names match the given regular expression, extract a boolean value from the first group in the regular expression and call the supplied function.default <T> voidforEachMatchingFieldNameWithBoolean(Pattern regex, int groupNumber, BiConsumer<String,Boolean> function)For all fields whose names match the given regular expression, extract a boolean value from the first group in the regular expression and call the supplied function.default <T> voidforEachMatchingFieldNameWithInteger(String regex, int groupNumber, BiConsumer<String,Integer> function)For all fields whose names match the given regular expression, extract an integer from the first group in the regular expression and call the supplied function.default <T> voidforEachMatchingFieldNameWithInteger(String regex, BiConsumer<String,Integer> function)For all fields whose names match the given regular expression, extract an integer from the first group in the regular expression and call the supplied function.default <T> voidforEachMatchingFieldNameWithInteger(Pattern regex, int groupNumber, BiConsumer<String,Integer> function)For all fields whose names match the given regular expression, extract an integer from the first group in the regular expression and call the supplied function.default <T> voidforEachMatchingFieldNameWithString(String regex, int groupNumber, BiConsumer<String,String> function)For all fields whose names match the given regular expression, extract a string value from the first group in the regular expression and call the supplied function.default <T> voidforEachMatchingFieldNameWithString(String regex, BiConsumer<String,String> function)For all fields whose names match the given regular expression, extract a string value from the first group in the regular expression and call the supplied function.default <T> voidforEachMatchingFieldNameWithString(Pattern regex, int groupNumber, BiConsumer<String,String> function)For all fields whose names match the given regular expression, extract a string value from the first group in the regular expression and call the supplied function.static Configurationfrom(Map<String,?> properties)Obtain a configuration instance by copying the supplied map of string keys and object values.static <T> Configurationfrom(Map<String,T> properties, Function<T,String> conversion)Obtain a configuration instance by copying the supplied map of string keys and object values.static Configurationfrom(Properties properties)Obtain a configuration instance by copying the supplied Properties object.static ConfigurationfromSystemProperties(String prefix)Create a Configuration object that is populated by system properties, perwithSystemProperties(String).default booleangetBoolean(Field field)Get the boolean value associated with the given field when that field has a default value.default booleangetBoolean(Field field, boolean defaultValue)Get the boolean value associated with the given field, returning the field's default value if there is no such key-value pair.default BooleangetBoolean(Field field, BooleanSupplier defaultValueSupplier)Get the boolean value associated with the given key, using the given supplier to obtain a default value if there is no such key-value pair.default BooleangetBoolean(String key)Get the boolean value associated with the given key.default booleangetBoolean(String key, boolean defaultValue)Get the boolean value associated with the given key, returning the default value if there is no such key-value pair or if the value could not beparsedas a boolean value.default BooleangetBoolean(String key, BooleanSupplier defaultValueSupplier)Get the boolean value associated with the given key, using the given supplier to obtain a default value if there is no such key-value pair.default DurationgetDuration(Field field, TemporalUnit unit)Gets the duration value associated with the given key.default StringgetFallbackStringProperty(Field newProperty, Field oldProperty)Returns the string config value from newProperty config field if it's set or its default value when it's not set/null.If both are null it returns the value of the oldProperty config field, or its default value when it's null.default StringgetFallbackStringPropertyWithWarning(Field newProperty, Field oldProperty)Returns the string config value from newProperty config field with a warning if it's set or its default value when it's not set/null.default <T> TgetInstance(Field field, Class<T> clazz)Get an instance of the class given by the value in the configuration associated with the given field.default <T> TgetInstance(Field field, Class<T> clazz, Configuration configuration)Get an instance of the class given by the value in the configuration associated with the given field.default <T> TgetInstance(Field field, Class<T> type, Supplier<ClassLoader> classloaderSupplier)Get an instance of the class given by the value in the configuration associated with the given field.default <T> TgetInstance(String key, Class<T> type)Get an instance of the class given by the value in the configuration associated with the given key.default <T> TgetInstance(String key, Class<T> clazz, Configuration configuration)Get an instance of the class given by the value in the configuration associated with the given key.default <T> TgetInstance(String key, Class<T> type, Supplier<ClassLoader> classloaderSupplier)Get an instance of the class given by the value in the configuration associated with the given key.default intgetInteger(Field field)Get the integer value associated with the given field, returning the field's default value if there is no such key-value pair.default intgetInteger(Field field, int defaultValue)Get the integer value associated with the given field, returning the field's default value if there is no such key-value pair.default IntegergetInteger(Field field, IntSupplier defaultValueSupplier)Get the integer value associated with the given key, using the given supplier to obtain a default value if there is no such key-value pair.default IntegergetInteger(String key)Get the integer value associated with the given key.default intgetInteger(String key, int defaultValue)Get the integer value associated with the given key, returning the default value if there is no such key-value pair or if the value could not beparsedas an integer.default IntegergetInteger(String key, IntSupplier defaultValueSupplier)Get the integer value associated with the given key, using the given supplier to obtain a default value if there is no such key-value pair.default longgetLong(Field field)Get the long value associated with the given field, returning the field's default value if there is no such key-value pair.default longgetLong(Field field, long defaultValue)Get the long value associated with the given field, returning the field's default value if there is no such key-value pair.default LonggetLong(Field field, LongSupplier defaultValueSupplier)Get the long value associated with the given key, using the given supplier to obtain a default value if there is no such key-value pair.default LonggetLong(String key)Get the long value associated with the given key.default longgetLong(String key, long defaultValue)Get the long value associated with the given key, returning the default value if there is no such key-value pair or if the value could not beparsedas a long.default LonggetLong(String key, LongSupplier defaultValueSupplier)Get the long value associated with the given key, using the given supplier to obtain a default value if there is no such key-value pair.default NumbergetNumber(Field field)Get the numeric value associated with the given field, returning the field's default value if there is no such key-value pair.default NumbergetNumber(String key, Supplier<Number> defaultValueSupplier)Get the integer value associated with the given key, using the given supplier to obtain a default value if there is no such key-value pair.default StringgetString(Field field)Get the string value associated with the given field, returning the field's default value if there is no such key-value pair in this configuration.default StringgetString(Field field, String defaultValue)Get the string value associated with the given field, returning the field's default value if there is no such key-value pair in this configuration.default StringgetString(Field field, Supplier<String> defaultValueSupplier)Get the boolean value associated with the given key, using the given supplier to obtain a default value if there is no such key-value pair.StringgetString(String key)Get the string value associated with the given key.default StringgetString(String key, String defaultValue)Get the string value associated with the given key, returning the default value if there is no such key-value pair.default StringgetString(String key, Supplier<String> defaultValueSupplier)Get the string value associated with the given key, returning the default value if there is no such key-value pair.default List<String>getStrings(Field field, String regex)Get the string value(s) associated with the given key, where the supplied regular expression is used to parse the single string value into multiple values.default List<String>getStrings(String key, String regex)Get the string value(s) associated with the given key, where the supplied regular expression is used to parse the single string value into multiple values.default List<String>getTrimmedStrings(Field field, String regex)Get the string value(s) associated with the given key, where the supplied regular expression is used to parse the single string value into multiple values.default booleanhasKey(String key)Determine whether this configuration contains a key-value pair with the given key and the value is non-nulldefault booleanisEmpty()Determine if this configuration is empty and has no properties.Set<String>keys()Get the set of keys in this configuration.static Configurationload(File file)Obtain a configuration instance by loading the Properties from the supplied file.static Configurationload(InputStream stream)Obtain a configuration instance by loading the Properties from the supplied stream.static Configurationload(Reader reader)Obtain a configuration instance by loading the Properties from the supplied reader.static Configurationload(String path, Class<?> clazz)Obtain a configuration instance by loading the Properties from a file on the file system or classpath given by the supplied path.static Configurationload(String path, ClassLoader classLoader)Obtain a configuration instance by loading the Properties from a file on the file system or classpath given by the supplied path.static Configurationload(String path, ClassLoader classLoader, Consumer<String> logger)Obtain a configuration instance by loading the Properties from a file on the file system or classpath given by the supplied path.static Configurationload(URL url)Obtain a configuration instance by loading the Properties from the supplied URL.default Configurationmap(Function<String,String> mapper)Return a newConfigurationthat contains only the subset of keys that satisfy the given predicate.default Configurationmapped(BiFunction<? super String,? super String,String> mapper)Return a newConfigurationthat contains the mapped values.default Configurationsubset(String prefix, boolean removePrefix)Return a newConfigurationthat contains only the subset of keys that match the given prefix.default Map<String,org.apache.kafka.common.config.ConfigValue>validate(Field.Set fields)Validate the supplied fields in this configuration.default booleanvalidate(Iterable<Field> fields, Field.ValidationOutput problems)Validate the supplied fields in this configuration.default booleanvalidateAndRecord(Iterable<Field> fields, Consumer<String> problems)Validate the supplied fields in this configuration.default ConfigurationwithMasked(String keyRegex)Return a newConfigurationthat contains all of the same fields as this configuration, except with masked values for all keys that match the specified pattern.default ConfigurationwithMasked(Pattern keyRegex)Return a newConfigurationthat contains all of the same fields as this configuration, except with masked values for all keys that match the specified pattern.default ConfigurationwithMaskedPasswords()Return a newConfigurationthat contains all of the same fields as this configuration, except with masked values for all keys that end in "password".default ConfigurationwithReplacedVariables(Function<String,String> valuesByVariableName)Return a newConfigurationthat contains all of the same fields as this configuration, except with all variables in the fields replaced with values from the supplied function.default ConfigurationwithSystemProperties(String prefix)Return a copy of this configuration except where acceptable system properties are used to overwrite properties copied from this configuration.default ConfigurationwithSystemProperties(Function<String,String> propertyNameConverter)Return a copy of this configuration except where acceptable system properties are used to overwrite properties copied from this configuration.
-
-
-
Field Detail
-
CONFIGURATION_LOGGER
static final org.slf4j.Logger CONFIGURATION_LOGGER
-
PASSWORD_PATTERN
static final Pattern PASSWORD_PATTERN
-
-
Method Detail
-
create
static Configuration.Builder create()
Create a newconfiguration builder.- Returns:
- the configuration builder
-
copy
static Configuration.Builder copy(Configuration config)
Create a newconfiguration builderthat starts with a copy of the supplied configuration.- Parameters:
config- the configuration to copy; may be null- Returns:
- the configuration builder
-
fromSystemProperties
static Configuration fromSystemProperties(String prefix)
Create a Configuration object that is populated by system properties, perwithSystemProperties(String).- Parameters:
prefix- the required prefix for the system properties; may not be null but may be empty- Returns:
- the configuration
-
empty
static Configuration empty()
Obtain an empty configuration.- Returns:
- an empty configuration; never null
-
from
static Configuration from(Properties properties)
Obtain a configuration instance by copying the supplied Properties object. The suppliedPropertiesobject is copied so that the resulting Configuration cannot be modified.- Parameters:
properties- the properties; may be null or empty- Returns:
- the configuration; never null
-
from
static Configuration from(Map<String,?> properties)
Obtain a configuration instance by copying the supplied map of string keys and object values. The entries within the map are copied so that the resulting Configuration cannot be modified.- Parameters:
properties- the properties; may be null or empty- Returns:
- the configuration; never null
-
from
static <T> Configuration from(Map<String,T> properties, Function<T,String> conversion)
Obtain a configuration instance by copying the supplied map of string keys and object values. The entries within the map are copied so that the resulting Configuration cannot be modified.- Parameters:
properties- the properties; may be null or emptyconversion- the function that converts the supplied values into strings, or returnsnullif the value is to be excluded- Returns:
- the configuration; never null
-
load
static Configuration load(URL url) throws IOException
Obtain a configuration instance by loading the Properties from the supplied URL.- Parameters:
url- the URL to the stream containing the configuration properties; may not be null- Returns:
- the configuration; never null
- Throws:
IOException- if there is an error reading the stream
-
load
static Configuration load(File file) throws IOException
Obtain a configuration instance by loading the Properties from the supplied file.- Parameters:
file- the file containing the configuration properties; may not be null- Returns:
- the configuration; never null
- Throws:
IOException- if there is an error reading the stream
-
load
static Configuration load(InputStream stream) throws IOException
Obtain a configuration instance by loading the Properties from the supplied stream.- Parameters:
stream- the stream containing the properties; may not be null- Returns:
- the configuration; never null
- Throws:
IOException- if there is an error reading the stream
-
load
static Configuration load(Reader reader) throws IOException
Obtain a configuration instance by loading the Properties from the supplied reader.- Parameters:
reader- the reader containing the properties; may not be null- Returns:
- the configuration; never null
- Throws:
IOException- if there is an error reading the stream
-
load
static Configuration load(String path, Class<?> clazz) throws IOException
Obtain a configuration instance by loading the Properties from a file on the file system or classpath given by the supplied path.- Parameters:
path- the path to the file containing the configuration properties; may not be nullclazz- the class whose classpath is to be used to find the file; may be null- Returns:
- the configuration; never null but possibly empty
- Throws:
IOException- if there is an error reading the stream
-
load
static Configuration load(String path, ClassLoader classLoader) throws IOException
Obtain a configuration instance by loading the Properties from a file on the file system or classpath given by the supplied path.- Parameters:
path- the path to the file containing the configuration properties; may not be nullclassLoader- the class loader to use; may be null- Returns:
- the configuration; never null but possibly empty
- Throws:
IOException- if there is an error reading the stream
-
load
static Configuration load(String path, ClassLoader classLoader, Consumer<String> logger) throws IOException
Obtain a configuration instance by loading the Properties from a file on the file system or classpath given by the supplied path.- Parameters:
path- the path to the file containing the configuration properties; may not be nullclassLoader- the class loader to use; may be nulllogger- the function that will be called with status updates; may be null- Returns:
- the configuration; never null but possibly empty
- Throws:
IOException- if there is an error reading the stream
-
edit
default Configuration.Builder edit()
Obtain an editor for a copy of this configuration.- Returns:
- a builder that is populated with this configuration's key-value pairs; never null
-
hasKey
default boolean hasKey(String key)
Determine whether this configuration contains a key-value pair with the given key and the value is non-null- Parameters:
key- the key- Returns:
- true if the configuration contains the key, or false otherwise
-
keys
Set<String> keys()
Get the set of keys in this configuration.- Returns:
- the set of keys; never null but possibly empty
-
getString
String getString(String key)
Get the string value associated with the given key.- Parameters:
key- the key for the configuration property- Returns:
- the value, or null if the key is null or there is no such key-value pair in the configuration
-
getString
default String getString(String key, String defaultValue)
Get the string value associated with the given key, returning the default value if there is no such key-value pair.- Parameters:
key- the key for the configuration propertydefaultValue- the value that should be returned by default if there is no such key-value pair in the configuration; may be null- Returns:
- the configuration value, or the
defaultValueif there is no such key-value pair in the configuration
-
getString
default String getString(String key, Supplier<String> defaultValueSupplier)
Get the string value associated with the given key, returning the default value if there is no such key-value pair.- Parameters:
key- the key for the configuration propertydefaultValueSupplier- the supplier of value that should be returned by default if there is no such key-value pair in the configuration; may be null and may return null- Returns:
- the configuration value, or the
defaultValueif there is no such key-value pair in the configuration
-
getString
default String getString(Field field)
Get the string value associated with the given field, returning the field's default value if there is no such key-value pair in this configuration.- Parameters:
field- the field; may not be null- Returns:
- the configuration's value for the field, or the field's
default valueif there is no such key-value pair in the configuration
-
getString
default String getString(Field field, String defaultValue)
Get the string value associated with the given field, returning the field's default value if there is no such key-value pair in this configuration.- Parameters:
field- the field; may not be nulldefaultValue- the default value- Returns:
- the configuration's value for the field, or the field's
default valueif there is no such key-value pair in the configuration
-
getStrings
default List<String> getStrings(Field field, String regex)
Get the string value(s) associated with the given key, where the supplied regular expression is used to parse the single string value into multiple values.- Parameters:
field- the field; may not be nullregex- the delimiting regular expression- Returns:
- the list of string values; null only if there is no such key-value pair in the configuration
- See Also:
String.split(String)
-
getStrings
default List<String> getStrings(String key, String regex)
Get the string value(s) associated with the given key, where the supplied regular expression is used to parse the single string value into multiple values.- Parameters:
key- the key for the configuration propertyregex- the delimiting regular expression- Returns:
- the list of string values; null only if there is no such key-value pair in the configuration
- See Also:
String.split(String)
-
getTrimmedStrings
default List<String> getTrimmedStrings(Field field, String regex)
Get the string value(s) associated with the given key, where the supplied regular expression is used to parse the single string value into multiple values. In addition, all values will be trimmed.- Parameters:
field- the field for the configuration propertyregex- the delimiting regular expression- Returns:
- the list of string values; null only if there is no such key-value pair in the configuration
- See Also:
String.split(String)
-
getInteger
default Integer getInteger(String key)
Get the integer value associated with the given key.- Parameters:
key- the key for the configuration property- Returns:
- the integer value, or null if the key is null, there is no such key-value pair in the configuration, or the value could not be parsed as an integer
-
getLong
default Long getLong(String key)
Get the long value associated with the given key.- Parameters:
key- the key for the configuration property- Returns:
- the integer value, or null if the key is null, there is no such key-value pair in the configuration, or the value could not be parsed as an integer
-
getBoolean
default Boolean getBoolean(String key)
Get the boolean value associated with the given key.- Parameters:
key- the key for the configuration property- Returns:
- the boolean value, or null if the key is null, there is no such key-value pair in the configuration, or the value could not be parsed as a boolean value
-
getInteger
default int getInteger(String key, int defaultValue)
Get the integer value associated with the given key, returning the default value if there is no such key-value pair or if the value could not beparsedas an integer.- Parameters:
key- the key for the configuration propertydefaultValue- the default value- Returns:
- the integer value, or null if the key is null, there is no such key-value pair in the configuration, or the value could not be parsed as an integer
-
getLong
default long getLong(String key, long defaultValue)
Get the long value associated with the given key, returning the default value if there is no such key-value pair or if the value could not beparsedas a long.- Parameters:
key- the key for the configuration propertydefaultValue- the default value- Returns:
- the long value, or null if the key is null, there is no such key-value pair in the configuration, or the value could not be parsed as a long
-
getBoolean
default boolean getBoolean(String key, boolean defaultValue)
Get the boolean value associated with the given key, returning the default value if there is no such key-value pair or if the value could not beparsedas a boolean value.- Parameters:
key- the key for the configuration propertydefaultValue- the default value- Returns:
- the boolean value, or null if the key is null, there is no such key-value pair in the configuration, or the value could not be parsed as a boolean value
-
getNumber
default Number getNumber(String key, Supplier<Number> defaultValueSupplier)
Get the integer value associated with the given key, using the given supplier to obtain a default value if there is no such key-value pair.- Parameters:
key- the key for the configuration propertydefaultValueSupplier- the supplier for the default value; may be null- Returns:
- the integer value, or null if the key is null, there is no such key-value pair in the configuration, the
defaultValueSupplierreference is null, or there is a key-value pair in the configuration but the value could not be parsed as an integer
-
getInteger
default Integer getInteger(String key, IntSupplier defaultValueSupplier)
Get the integer value associated with the given key, using the given supplier to obtain a default value if there is no such key-value pair.- Parameters:
key- the key for the configuration propertydefaultValueSupplier- the supplier for the default value; may be null- Returns:
- the integer value, or null if the key is null, there is no such key-value pair in the configuration, the
defaultValueSupplierreference is null, or there is a key-value pair in the configuration but the value could not be parsed as an integer
-
getLong
default Long getLong(String key, LongSupplier defaultValueSupplier)
Get the long value associated with the given key, using the given supplier to obtain a default value if there is no such key-value pair.- Parameters:
key- the key for the configuration propertydefaultValueSupplier- the supplier for the default value; may be null- Returns:
- the long value, or null if the key is null, there is no such key-value pair in the configuration, the
defaultValueSupplierreference is null, or there is a key-value pair in the configuration but the value could not be parsed as a long
-
getBoolean
default Boolean getBoolean(String key, BooleanSupplier defaultValueSupplier)
Get the boolean value associated with the given key, using the given supplier to obtain a default value if there is no such key-value pair.- Parameters:
key- the key for the configuration propertydefaultValueSupplier- the supplier for the default value; may be null- Returns:
- the boolean value, or null if the key is null, there is no such key-value pair in the configuration, the
defaultValueSupplierreference is null, or there is a key-value pair in the configuration but the value could not be parsed as a boolean value
-
getNumber
default Number getNumber(Field field)
Get the numeric value associated with the given field, returning the field's default value if there is no such key-value pair.- Parameters:
field- the field- Returns:
- the integer value, or null if the key is null, there is no such key-value pair in the configuration and there is no default value in the field or the default value could not be parsed as a long, or there is a key-value pair in the configuration but the value could not be parsed as an integer value
- Throws:
NumberFormatException- if there is no name-value pair and the field has no default value
-
getInteger
default int getInteger(Field field)
Get the integer value associated with the given field, returning the field's default value if there is no such key-value pair.- Parameters:
field- the field- Returns:
- the integer value, or null if the key is null, there is no such key-value pair in the configuration and there is no default value in the field or the default value could not be parsed as a long, or there is a key-value pair in the configuration but the value could not be parsed as an integer value
- Throws:
NumberFormatException- if there is no name-value pair and the field has no default value
-
getLong
default long getLong(Field field)
Get the long value associated with the given field, returning the field's default value if there is no such key-value pair.- Parameters:
field- the field- Returns:
- the integer value, or null if the key is null, there is no such key-value pair in the configuration and there is no default value in the field or the default value could not be parsed as a long, or there is a key-value pair in the configuration but the value could not be parsed as a long value
- Throws:
NumberFormatException- if there is no name-value pair and the field has no default value
-
getBoolean
default boolean getBoolean(Field field)
Get the boolean value associated with the given field when that field has a default value. If the configuration does not have a name-value pair with the same name as the field, then the field's default value.- Parameters:
field- the field- Returns:
- the boolean value, or null if the key is null, there is no such key-value pair in the configuration and there is no default value in the field or the default value could not be parsed as a long, or there is a key-value pair in the configuration but the value could not be parsed as a boolean value
- Throws:
NumberFormatException- if there is no name-value pair and the field has no default value
-
getInteger
default int getInteger(Field field, int defaultValue)
Get the integer value associated with the given field, returning the field's default value if there is no such key-value pair.- Parameters:
field- the fielddefaultValue- the default value- Returns:
- the integer value, or null if the key is null, there is no such key-value pair in the configuration and there is no default value in the field or the default value could not be parsed as a long, or there is a key-value pair in the configuration but the value could not be parsed as an integer value
-
getLong
default long getLong(Field field, long defaultValue)
Get the long value associated with the given field, returning the field's default value if there is no such key-value pair.- Parameters:
field- the fielddefaultValue- the default value- Returns:
- the integer value, or null if the key is null, there is no such key-value pair in the configuration and there is no default value in the field or the default value could not be parsed as a long, or there is a key-value pair in the configuration but the value could not be parsed as a long value
-
getBoolean
default boolean getBoolean(Field field, boolean defaultValue)
Get the boolean value associated with the given field, returning the field's default value if there is no such key-value pair.- Parameters:
field- the fielddefaultValue- the default value- Returns:
- the boolean value, or null if the key is null, there is no such key-value pair in the configuration and there is no default value in the field or the default value could not be parsed as a long, or there is a key-value pair in the configuration but the value could not be parsed as a boolean value
-
getInteger
default Integer getInteger(Field field, IntSupplier defaultValueSupplier)
Get the integer value associated with the given key, using the given supplier to obtain a default value if there is no such key-value pair.- Parameters:
field- the fielddefaultValueSupplier- the supplier for the default value; may be null- Returns:
- the integer value, or null if the key is null, there is no such key-value pair in the configuration, the
defaultValueSupplierreference is null, or there is a key-value pair in the configuration but the value could not be parsed as an integer
-
getLong
default Long getLong(Field field, LongSupplier defaultValueSupplier)
Get the long value associated with the given key, using the given supplier to obtain a default value if there is no such key-value pair.- Parameters:
field- the fielddefaultValueSupplier- the supplier for the default value; may be null- Returns:
- the long value, or null if the key is null, there is no such key-value pair in the configuration, the
defaultValueSupplierreference is null, or there is a key-value pair in the configuration but the value could not be parsed as a long
-
getBoolean
default Boolean getBoolean(Field field, BooleanSupplier defaultValueSupplier)
Get the boolean value associated with the given key, using the given supplier to obtain a default value if there is no such key-value pair.- Parameters:
field- the fielddefaultValueSupplier- the supplier for the default value; may be null- Returns:
- the boolean value, or null if the key is null, there is no such key-value pair in the configuration, the
defaultValueSupplierreference is null, or there is a key-value pair in the configuration but the value could not be parsed as a boolean value
-
getString
default String getString(Field field, Supplier<String> defaultValueSupplier)
Get the boolean value associated with the given key, using the given supplier to obtain a default value if there is no such key-value pair.- Parameters:
field- the fielddefaultValueSupplier- the supplier of value that should be returned by default if there is no such key-value pair in the configuration; may be null and may return null- Returns:
- the configuration value, or the
defaultValueif there is no such key-value pair in the configuration
-
getDuration
default Duration getDuration(Field field, TemporalUnit unit)
Gets the duration value associated with the given key.- Parameters:
field- the fieldunit- the temporal unit of the duration value- Returns:
- the duration value associated with the given key
-
getInstance
default <T> T getInstance(String key, Class<T> type)
Get an instance of the class given by the value in the configuration associated with the given key.- Parameters:
key- the key for the configuration propertytype- the Class of which the resulting object is expected to be an instance of; may not be null- Returns:
- the new instance, or null if there is no such key-value pair in the configuration or if there is a key-value configuration but the value could not be converted to an existing class with a zero-argument constructor
-
getInstance
default <T> T getInstance(String key, Class<T> type, Supplier<ClassLoader> classloaderSupplier)
Get an instance of the class given by the value in the configuration associated with the given key.- Parameters:
key- the key for the configuration propertytype- the Class of which the resulting object is expected to be an instance of; may not be nullclassloaderSupplier- the supplier of the ClassLoader to be used to load the resulting class; may be null if this class' ClassLoader should be used- Returns:
- the new instance, or null if there is no such key-value pair in the configuration or if there is a key-value configuration but the value could not be converted to an existing class with a zero-argument constructor
-
getInstance
default <T> T getInstance(String key, Class<T> clazz, Configuration configuration)
Get an instance of the class given by the value in the configuration associated with the given key. The instance is created usingInstance(Configuration)constructor.- Parameters:
key- the key for the configuration propertyclazz- the Class of which the resulting object is expected to be an instance of; may not be nullconfiguration-Configurationobject that is passed as a parameter to the constructor- Returns:
- the new instance, or null if there is no such key-value pair in the configuration or if there is a key-value configuration but the value could not be converted to an existing class with a zero-argument constructor
-
getInstance
default <T> T getInstance(Field field, Class<T> clazz)
Get an instance of the class given by the value in the configuration associated with the given field.- Parameters:
field- the field for the configuration propertyclazz- the Class of which the resulting object is expected to be an instance of; may not be null- Returns:
- the new instance, or null if there is no such key-value pair in the configuration or if there is a key-value configuration but the value could not be converted to an existing class with a zero-argument constructor
-
getInstance
default <T> T getInstance(Field field, Class<T> type, Supplier<ClassLoader> classloaderSupplier)
Get an instance of the class given by the value in the configuration associated with the given field.- Parameters:
field- the field for the configuration propertytype- the Class of which the resulting object is expected to be an instance of; may not be nullclassloaderSupplier- the supplier of the ClassLoader to be used to load the resulting class; may be null if this class' ClassLoader should be used- Returns:
- the new instance, or null if there is no such key-value pair in the configuration or if there is a key-value configuration but the value could not be converted to an existing class with a zero-argument constructor
-
getInstance
default <T> T getInstance(Field field, Class<T> clazz, Configuration configuration)
Get an instance of the class given by the value in the configuration associated with the given field. The instance is created usingInstance(Configuration)constructor.- Parameters:
field- the field for the configuration propertyclazz- the Class of which the resulting object is expected to be an instance of; may not be nullconfiguration- theConfigurationobject that is passed as a parameter to the constructor- Returns:
- the new instance, or null if there is no such key-value pair in the configuration or if there is a key-value configuration but the value could not be converted to an existing class with a zero-argument constructor
-
subset
default Configuration subset(String prefix, boolean removePrefix)
Return a newConfigurationthat contains only the subset of keys that match the given prefix. If desired, the keys in the resulting Configuration will have the prefix (plus any terminating "." character if needed) removed.This method returns this Configuration instance if the supplied
prefixis null or empty.- Parameters:
prefix- the prefixremovePrefix- true if the prefix (and any subsequent "." character) should be removed from the keys in the resulting Configuration, or false if the keys in this Configuration should be used as-is in the resulting Configuration- Returns:
- the subset of this Configuration; never null
-
map
default Configuration map(Function<String,String> mapper)
Return a newConfigurationthat contains only the subset of keys that satisfy the given predicate.- Parameters:
mapper- that function that transforms keys- Returns:
- the subset Configuration; never null
-
filter
default Configuration filter(Predicate<? super String> matcher)
Return a newConfigurationthat contains only the subset of keys that satisfy the given predicate.- Parameters:
matcher- the function that determines whether a key should be included in the subset- Returns:
- the subset Configuration; never null
-
mapped
default Configuration mapped(BiFunction<? super String,? super String,String> mapper)
Return a newConfigurationthat contains the mapped values.- Parameters:
mapper- the function that takes a key and value and returns the new mapped value- Returns:
- the Configuration with mapped values; never null
-
withReplacedVariables
default Configuration withReplacedVariables(Function<String,String> valuesByVariableName)
Return a newConfigurationthat contains all of the same fields as this configuration, except with all variables in the fields replaced with values from the supplied function. Variables found in fields will be left as-is if the supplied function returns no value for the variable name(s).Variables may appear anywhere within a field value, and multiple variables can be used within the same field. Variables take the form:
variable := '${' variableNames [ ':' defaultValue ] '}' variableNames := variableName [ ',' variableNames ] variableName := // any characters except ',' and ':' and '}' defaultValue := // any characters except '}'and examples of variables include:${var1}${var1:defaultValue}${var1,var2}${var1,var2:defaultValue}
- Parameters:
valuesByVariableName- the function that returns a variable value for a variable name; may not be null but may return null if the variable name is not known- Returns:
- the Configuration with masked values for matching keys; never null
-
withMaskedPasswords
default Configuration withMaskedPasswords()
Return a newConfigurationthat contains all of the same fields as this configuration, except with masked values for all keys that end in "password".- Returns:
- the Configuration with masked values for matching keys; never null
-
withMasked
default Configuration withMasked(String keyRegex)
Return a newConfigurationthat contains all of the same fields as this configuration, except with masked values for all keys that match the specified pattern.- Parameters:
keyRegex- the regular expression to match against the keys- Returns:
- the Configuration with masked values for matching keys; never null
-
withMasked
default Configuration withMasked(Pattern keyRegex)
Return a newConfigurationthat contains all of the same fields as this configuration, except with masked values for all keys that match the specified pattern.- Parameters:
keyRegex- the regular expression to match against the keys- Returns:
- the Configuration with masked values for matching keys; never null
-
isEmpty
default boolean isEmpty()
Determine if this configuration is empty and has no properties.- Returns:
trueif empty, orfalseotherwise
-
asProperties
default Properties asProperties()
Get a copy of these configuration properties as a Properties object.- Returns:
- the properties object; never null
-
asProperties
default Properties asProperties(Field.Set fields)
Get a copy of these configuration properties as a Properties object.- Parameters:
fields- the fields defining the defaults; may be null- Returns:
- the properties object; never null
-
asMap
default Map<String,String> asMap()
Get a copy of these configuration properties as a Properties object.- Returns:
- the properties object; never null
-
asMap
default Map<String,String> asMap(Field.Set fields)
Get a copy of these configuration properties with defaults as a Map.- Parameters:
fields- the fields defining the defaults; may be null- Returns:
- the properties object; never null
-
withSystemProperties
default Configuration withSystemProperties(String prefix)
Return a copy of this configuration except where acceptable system properties are used to overwrite properties copied from this configuration. All system properties whose name has the given prefix are added, where the prefix is removed from the system property name, it is converted to lower case, and each underscore character ('_') are replaced with a period ('.').- Parameters:
prefix- the required prefix for the system properties- Returns:
- the resulting properties converted from the system properties; never null, but possibly empty
-
withSystemProperties
default Configuration withSystemProperties(Function<String,String> propertyNameConverter)
Return a copy of this configuration except where acceptable system properties are used to overwrite properties copied from this configuration. Each of the system properties is examined and passed to the supplied function; if the result of the function is a non-null string, then a property with that string as the name and the system property value are added to the returned configuration.- Parameters:
propertyNameConverter- the function that will convert the name of each system property to an applicable property name (or null if the system property name does not apply); may not be null- Returns:
- the resulting properties filtered from the input properties; never null, but possibly empty
-
validate
default boolean validate(Iterable<Field> fields, Field.ValidationOutput problems)
Validate the supplied fields in this configuration. Extra fields not described by the suppliedfieldsparameter are not validated.- Parameters:
fields- the fieldsproblems- the consumer to be called with each problem; never null- Returns:
trueif the value is considered valid, orfalseif it is not valid
-
validateAndRecord
default boolean validateAndRecord(Iterable<Field> fields, Consumer<String> problems)
Validate the supplied fields in this configuration. Extra fields not described by the suppliedfieldsparameter are not validated.- Parameters:
fields- the fieldsproblems- the consumer to be called with each problem; never null- Returns:
trueif the value is considered valid, orfalseif it is not valid
-
validate
default Map<String,org.apache.kafka.common.config.ConfigValue> validate(Field.Set fields)
Validate the supplied fields in this configuration. Extra fields not described by the suppliedfieldsparameter are not validated.- Parameters:
fields- the fields- Returns:
- the
ConfigValuefor each of the fields; never null
-
forEachMatchingFieldName
default void forEachMatchingFieldName(String regex, BiConsumer<String,String> function)
Apply the given function to all fields whose names match the given regular expression.- Parameters:
regex- the regular expression string; may not be nullfunction- the consumer that takes the name and value of matching fields; may not be null
-
forEachMatchingFieldName
default void forEachMatchingFieldName(Pattern regex, BiConsumer<String,String> function)
Apply the given function to all fields whose names match the given regular expression.- Parameters:
regex- the regular expression string; may not be nullfunction- the consumer that takes the name and value of matching fields; may not be null
-
forEachMatchingFieldNameWithInteger
default <T> void forEachMatchingFieldNameWithInteger(String regex, BiConsumer<String,Integer> function)
For all fields whose names match the given regular expression, extract an integer from the first group in the regular expression and call the supplied function.- Parameters:
regex- the regular expression string; may not be nullfunction- the consumer that takes the value of matching field and the integer extracted from the field name; may not be null
-
forEachMatchingFieldNameWithInteger
default <T> void forEachMatchingFieldNameWithInteger(String regex, int groupNumber, BiConsumer<String,Integer> function)
For all fields whose names match the given regular expression, extract an integer from the first group in the regular expression and call the supplied function.- Parameters:
regex- the regular expression string; may not be nullgroupNumber- the number of the regular expression group containing the integer to be extracted; must be positivefunction- the consumer that takes the value of matching field and the integer extracted from the field name; may not be null
-
forEachMatchingFieldNameWithInteger
default <T> void forEachMatchingFieldNameWithInteger(Pattern regex, int groupNumber, BiConsumer<String,Integer> function)
For all fields whose names match the given regular expression, extract an integer from the first group in the regular expression and call the supplied function.- Parameters:
regex- the regular expression string; may not be nullgroupNumber- the number of the regular expression group containing the integer to be extracted; must be positivefunction- the consumer that takes the value of matching field and the integer extracted from the field name; may not be null
-
forEachMatchingFieldNameWithBoolean
default <T> void forEachMatchingFieldNameWithBoolean(String regex, BiConsumer<String,Boolean> function)
For all fields whose names match the given regular expression, extract a boolean value from the first group in the regular expression and call the supplied function.- Parameters:
regex- the regular expression string; may not be nullfunction- the consumer that takes the value of matching field and the boolean extracted from the field name; may not be null
-
forEachMatchingFieldNameWithBoolean
default <T> void forEachMatchingFieldNameWithBoolean(String regex, int groupNumber, BiConsumer<String,Boolean> function)
For all fields whose names match the given regular expression, extract a boolean value from the first group in the regular expression and call the supplied function.- Parameters:
regex- the regular expression string; may not be nullgroupNumber- the number of the regular expression group containing the boolean to be extracted; must be positivefunction- the consumer that takes the value of matching field and the boolean extracted from the field name; may not be null
-
forEachMatchingFieldNameWithBoolean
default <T> void forEachMatchingFieldNameWithBoolean(Pattern regex, int groupNumber, BiConsumer<String,Boolean> function)
For all fields whose names match the given regular expression, extract a boolean value from the first group in the regular expression and call the supplied function.- Parameters:
regex- the regular expression string; may not be nullgroupNumber- the number of the regular expression group containing the boolean to be extracted; must be positivefunction- the consumer that takes the value of matching field and the boolean extracted from the field name; may not be null
-
forEachMatchingFieldNameWithString
default <T> void forEachMatchingFieldNameWithString(String regex, BiConsumer<String,String> function)
For all fields whose names match the given regular expression, extract a string value from the first group in the regular expression and call the supplied function.- Parameters:
regex- the regular expression string; may not be nullfunction- the consumer that takes the value of matching field and the string value extracted from the field name; may not be null
-
forEachMatchingFieldNameWithString
default <T> void forEachMatchingFieldNameWithString(String regex, int groupNumber, BiConsumer<String,String> function)
For all fields whose names match the given regular expression, extract a string value from the first group in the regular expression and call the supplied function.- Parameters:
regex- the regular expression string; may not be nullgroupNumber- the number of the regular expression group containing the string value to be extracted; must be positivefunction- the consumer that takes the value of matching field and the string value extracted from the field name; may not be null
-
forEachMatchingFieldNameWithString
default <T> void forEachMatchingFieldNameWithString(Pattern regex, int groupNumber, BiConsumer<String,String> function)
For all fields whose names match the given regular expression, extract a string value from the first group in the regular expression and call the supplied function.- Parameters:
regex- the regular expression string; may not be nullgroupNumber- the number of the regular expression group containing the string value to be extracted; must be positivefunction- the consumer that takes the value of matching field and the string value extracted from the field name; may not be null
-
forEachMatchingFieldName
default <T> void forEachMatchingFieldName(String regex, int groupNumber, BiFunction<String,String,T> groupExtractor, BiConsumer<String,T> function)
For all fields whose names match the given regular expression, extract a value from the specified group in the regular expression and call the supplied function.- Parameters:
regex- the regular expression string; may not be nullgroupNumber- the number of the regular expression group containing the string value to be extracted; must be positivegroupExtractor- the function that extracts the value from the groupfunction- the consumer that takes the value of matching field and the value extracted from the field name; may not be null
-
forEachMatchingFieldName
default <T> void forEachMatchingFieldName(Pattern regex, int groupNumber, BiFunction<String,String,T> groupExtractor, BiConsumer<String,T> function)
For all fields whose names match the given regular expression, extract a value from the specified group in the regular expression and call the supplied function.- Parameters:
regex- the regular expression string; may not be nullgroupNumber- the number of the regular expression group containing the string value to be extracted; must be positivegroupExtractor- the function that extracts the value from the groupfunction- the consumer that takes the value of matching field and the value extracted from the field name; may not be null
-
forEach
default <T> void forEach(BiConsumer<String,String> function)
Call the supplied function for each of the fields.- Parameters:
function- the consumer that takes the field name and the string value extracted from the field; may not be null
-
getFallbackStringProperty
default String getFallbackStringProperty(Field newProperty, Field oldProperty)
Returns the string config value from newProperty config field if it's set or its default value when it's not set/null.If both are null it returns the value of the oldProperty config field, or its default value when it's null. This fallback only works for newProperty fields that have a null / not-set default value!- Parameters:
newProperty- the new property config fieldoldProperty- the old / fallback property config field- Returns:
- the evaluated value
-
getFallbackStringPropertyWithWarning
default String getFallbackStringPropertyWithWarning(Field newProperty, Field oldProperty)
Returns the string config value from newProperty config field with a warning if it's set or its default value when it's not set/null. If both are null it returns the value of the oldProperty config field with a warning, or its default value when it's null.
-
-