Interface Config.Builder
-
- Enclosing interface:
- Config
public static interface Config.Builder
Config
Builder.A factory for a
Config
object.The application can set the following characteristics:
overrides
- instance ofoverride source
;sources
- instances ofconfiguration source
;mappers
- ordered list of mapper functions. It is also possible todisable
loading ofConfigMapperProvider
s as aservice
.parsers
- ordered list ofconfiguration content parsers
. It is also possible todisable
loading ofConfigParser
s as aservice
.token reference resolving
- a resolving of reference tokens in a key can bedisabled
filters
- ordered list ofconfiguration value filters
. It is also possible todisable
loading ofConfigFilter
s as aservice
.caching
- can be elementary configuration value processed by filter cached?
In case of
ConfigMapperProvider
s, if there is no one that could be used to map appropriatetype
, the mapping attempt throws aConfigMappingException
.A more sophisticated approach can be achieved using the "config beans" module, that provides reflection access and mapping for static factory methods, constructors, builder patterns and more.
If a
ConfigSource
is not specified, following default config source is used. Same asConfig.create()
uses. It builds composite config source from following sources, checked in order:- Tries to load configuration from meta one of following meta configuration files on classpath, in order:
meta-config.yaml
- meta configuration file in YAML formatmeta-config.conf
- meta configuration file in HOCON formatmeta-config.json
- meta configuration file in JSON formatmeta-config.properties
- meta configuration file in Java Properties format
- Otherwise, configuration consists of:
Environment variables
;- or else
System properties
- one of following files on classpath, checked in order:
application.yaml
- configuration file in YAML formatapplication.conf
- configuration file in HOCON formatapplication.json
- configuration file in JSON formatapplication.properties
- configuration file in Java Properties format
ConfigParser
available that supports appropriatemedia type
. Available parser means that the parser:- is loaded as a service using
ServiceLoader
; - or if it does not exist, a config core built-in parser is used, if exists.
- See Also:
Config.create()
,ConfigSource
,ConfigParser
,ConfigFilter
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description Config.Builder
addFilter(ConfigFilter configFilter)
Registers aConfigFilter
instance that will be used byConfig
to filter elementary value before it is returned to a user.Config.Builder
addFilter(Function<Config,ConfigFilter> configFilterProvider)
Config.Builder
addFilter(Supplier<Function<Config,ConfigFilter>> configFilterSupplier)
<T> Config.Builder
addMapper(GenericType<T> type, Function<Config,T> mapper)
Register a mapping function for specifiedGenericType
.Config.Builder
addMapper(ConfigMapperProvider configMapperProvider)
<T> Config.Builder
addMapper(Class<T> type, Function<Config,T> mapper)
Registers mapping function for specifiedtype
.Config.Builder
addParser(ConfigParser configParser)
Registers aConfigParser
instance that can be used by registeredConfigSource
s to parseconfiguration content
.<T> Config.Builder
addStringMapper(Class<T> type, Function<String,T> mapper)
Config
build()
Builds new instance ofConfig
.Config.Builder
changesExecutor(Executor changesExecutor)
Specifies "observe-on"Executor
to be used byConfig.changes()
to deliver new Config instance.Config.Builder
changesMaxBuffer(int changesMaxBuffer)
Specifies maximum capacity for each subscriber's buffer to be used by byConfig.changes()
to deliver new Config instance.Config.Builder
disableCaching()
Disables caching of elementary configuration values onConfig
side.Config.Builder
disableEnvironmentVariablesSource()
Disables use ofenvironment variables config source
.Config.Builder
disableFilterServices()
Disables automatic registration of filters loaded as aservice
.Config.Builder
disableKeyResolving()
Disables an usage of resolving key tokens.Config.Builder
disableMapperServices()
Disables automatic registration of mappers viaConfigMapperProvider
SPI loaded as aservice
.Config.Builder
disableParserServices()
Disables automatic registration of parsers loaded as aservice
.Config.Builder
disableSystemPropertiesSource()
Disables use ofsystem properties config source
.Config.Builder
disableValueResolving()
Disables an usage of resolving value tokens.Config.Builder
mappersFrom(Config config)
Add mappers from another config instance.Config.Builder
overrides(Supplier<OverrideSource> overridingSource)
Sets source of a override source.default Config.Builder
sources(Supplier<ConfigSource> configSource)
Sets aConfigSource
instance to be used as a source of configuration to be wrapped intoConfig
API.default Config.Builder
sources(Supplier<ConfigSource> configSource, Supplier<ConfigSource> configSource2)
Sets an ordered pair ofConfigSource
instances to be used as single source of configuration to be wrapped intoConfig
API.default Config.Builder
sources(Supplier<ConfigSource> configSource, Supplier<ConfigSource> configSource2, Supplier<ConfigSource> configSource3)
Sets an ordered trio ofConfigSource
instances to be used as single source of configuration to be wrapped intoConfig
API.Config.Builder
sources(List<Supplier<ConfigSource>> configSources)
Sets ordered list ofConfigSource
instance to be used as single source of configuration to be wrapped intoConfig
API.
-
-
-
Method Detail
-
sources
Config.Builder sources(List<Supplier<ConfigSource>> configSources)
Sets ordered list ofConfigSource
instance to be used as single source of configuration to be wrapped intoConfig
API.Configuration sources found earlier in the list are considered to have a higher priority than the latter ones. I.e., when resolving a value of a key, the sources are consulted in the order they have been provided and as soon as the value is found in a configuration source, the value immediately is returned without consulting any of the remaining configuration sources in the prioritized collection.
This is default implementation of
ConfigSources.create(Supplier...)
Composite ConfigSource} provided byFallback MergingStrategy
. It is possible touse custom implementation of merging strategy
.builder.source(ConfigSources.create(source1, source2, source3) .mergingStrategy(new MyMergingStrategy));
Target source is composed from following sources, in order:environment variables config source
Can disabled bydisableEnvironmentVariablesSource()
system properties config source
Can disabled bydisableSystemPropertiesSource()
- Source(s) specified by user in the method.
- Parameters:
configSources
- ordered list of configuration sources- Returns:
- an updated builder instance
- See Also:
disableEnvironmentVariablesSource()
,disableSystemPropertiesSource()
,ConfigSources.create(Supplier...)
,ConfigSources.CompositeBuilder
,ConfigSources.MergingStrategy
-
sources
default Config.Builder sources(Supplier<ConfigSource> configSource)
Sets aConfigSource
instance to be used as a source of configuration to be wrapped intoConfig
API.Target source is composed from
configSource
and following sources (unless they are disabled) in order:environment variables config source
Can disabled bydisableEnvironmentVariablesSource()
system properties config source
Can disabled bydisableSystemPropertiesSource()
- Source(s) specified by user in the method.
- Parameters:
configSource
- the only config source- Returns:
- an updated builder instance
- See Also:
Config.create(Supplier...)
,sources(List)
,disableEnvironmentVariablesSource()
,disableSystemPropertiesSource()
-
sources
default Config.Builder sources(Supplier<ConfigSource> configSource, Supplier<ConfigSource> configSource2)
Sets an ordered pair ofConfigSource
instances to be used as single source of configuration to be wrapped intoConfig
API.Target source is composed from
configSource
and following sources (unless they are disabled) in order:environment variables config source
Can disabled bydisableEnvironmentVariablesSource()
system properties config source
Can disabled bydisableSystemPropertiesSource()
- Source(s) specified by user in the method.
- Parameters:
configSource
- the first config sourceconfigSource2
- the second config source- Returns:
- an updated builder instance
- See Also:
Config.create(Supplier...)
,sources(List)
,disableEnvironmentVariablesSource()
,disableSystemPropertiesSource()
-
sources
default Config.Builder sources(Supplier<ConfigSource> configSource, Supplier<ConfigSource> configSource2, Supplier<ConfigSource> configSource3)
Sets an ordered trio ofConfigSource
instances to be used as single source of configuration to be wrapped intoConfig
API.Target source is composed from config sources parameters and following sources (unless they are disabled) in order:
environment variables config source
Can disabled bydisableEnvironmentVariablesSource()
system properties config source
Can disabled bydisableSystemPropertiesSource()
- Source(s) specified by user in the method.
- Parameters:
configSource
- the first config sourceconfigSource2
- the second config sourceconfigSource3
- the third config source- Returns:
- an updated builder instance
- See Also:
Config.create(Supplier...)
,sources(List)
,disableEnvironmentVariablesSource()
,disableSystemPropertiesSource()
-
overrides
Config.Builder overrides(Supplier<OverrideSource> overridingSource)
Sets source of a override source.The feature allows user to override existing values with other ones, specified by wildcards. Default values might be defined with key token references (i.e.
$env.$pod.logging.level: INFO
) that might be overridden by a config source with a higher priority to identify the current environment (i.e.env: test
andpod: qwerty
. The overrides are able to redefine values using wildcards (or without them). For exampletest.*.logging.level = FINE
overrideslogging.level
for all pods in test environment.Override definitions are applied before any
filter
.- Parameters:
overridingSource
- a source with overriding key patterns and assigned values- Returns:
- an updated builder instance
-
disableKeyResolving
Config.Builder disableKeyResolving()
Disables an usage of resolving key tokens.A key can contain tokens starting with
$
(i.e. $host.$port), that are resolved by default and tokens are replaced with a value of the key with the token as a key.- Returns:
- an updated builder instance
-
disableValueResolving
Config.Builder disableValueResolving()
Disables an usage of resolving value tokens.A value can contain tokens enclosed in
${}
(i.e. ${name}), that are resolved by default and tokens are replaced with a value of the key with the token as a key.- Returns:
- an updated builder instance
-
disableEnvironmentVariablesSource
Config.Builder disableEnvironmentVariablesSource()
Disables use ofenvironment variables config source
.- Returns:
- an updated builder instance
- See Also:
ConfigSources.environmentVariables()
-
disableSystemPropertiesSource
Config.Builder disableSystemPropertiesSource()
Disables use ofsystem properties config source
.- Returns:
- an updated builder instance
- See Also:
ConfigSources.systemProperties()
-
addMapper
<T> Config.Builder addMapper(Class<T> type, Function<Config,T> mapper)
Registers mapping function for specifiedtype
. The last registration of sametype
overwrites previous one. Programmatically registered mappers have priority over other options.As another option, mappers are loaded automatically as a
service
viaConfigMapperProvider
SPI unless it isdisabled
.And the last option,
built-in mappers
are registered.- Type Parameters:
T
- type themapper
is registered for- Parameters:
type
- class of type themapper
is registered formapper
- mapping function- Returns:
- an updated builder instance
- See Also:
addStringMapper(Class, Function)
,addMapper(ConfigMapperProvider)
,disableMapperServices()
-
addMapper
<T> Config.Builder addMapper(GenericType<T> type, Function<Config,T> mapper)
Register a mapping function for specifiedGenericType
. This is useful for mappers that support specificly typed generics, such asMap<String, Integer>
orSet<Foo<Bar>>
. To support mappers that can map any type (e.g. all cases ofMap<String, V>
), useaddMapper(ConfigMapperProvider)
as it gives you full control over which types are supported, throughConfigMapperProvider.mapper(GenericType)
.- Type Parameters:
T
- type of the result- Parameters:
type
- generic type to register a mapper formapper
- mapping function- Returns:
- updated builder instance
-
addStringMapper
<T> Config.Builder addStringMapper(Class<T> type, Function<String,T> mapper)
Registers simpleFunction
fromString
for specifiedtype
. The last registration of sametype
overwrites previous one. Programmatically registered mappers have priority over other options.As another option, mappers are loaded automatically as a
service
viaConfigMapperProvider
SPI, if notdisabled
.And the last option,
built-in mappers
are registered.- Type Parameters:
T
- type themapper
is registered for- Parameters:
type
- class of type themapper
is registered formapper
- mapper instance- Returns:
- an updated builder instance
- See Also:
addMapper(ConfigMapperProvider)
,ConfigMappers
,disableMapperServices()
-
addMapper
Config.Builder addMapper(ConfigMapperProvider configMapperProvider)
Registers aConfigMapperProvider
with a map ofString
to specifiedtype
. The last registration of sametype
overwrites previous one. Programmatically registered mappers have priority over other options.As another option, mappers are loaded automatically as a
service
viaConfigMapperProvider
SPI, if notdisabled
.And the last option,
built-in mappers
are registered.- Parameters:
configMapperProvider
- mapper provider instance- Returns:
- modified builder instance
- See Also:
addStringMapper(Class, Function)
,ConfigMappers
,disableMapperServices()
-
disableMapperServices
Config.Builder disableMapperServices()
Disables automatic registration of mappers viaConfigMapperProvider
SPI loaded as aservice
.Order of configuration mapper providers loaded as a service is defined by
Priority
annotation.Automatic registration of mappers as a service is enabled by default.
- Returns:
- an updated builder instance
- See Also:
ConfigMapperProvider
-
addParser
Config.Builder addParser(ConfigParser configParser)
Registers aConfigParser
instance that can be used by registeredConfigSource
s to parseconfiguration content
. Parsers are tried to be used byConfigContext.findParser(String)
in same order as was registered by theaddParser(ConfigParser)
method. Programmatically registered parsers have priority over other options.As another option, parsers are loaded automatically as a
service
, if notdisabled
.- Parameters:
configParser
- parser instance- Returns:
- an updated builder instance
- See Also:
disableParserServices()
-
disableParserServices
Config.Builder disableParserServices()
Disables automatic registration of parsers loaded as aservice
.Order of configuration parsers loaded as a service is defined by
Priority
annotation.Automatic registration of parsers as a service is enabled by default.
- Returns:
- an updated builder instance
- See Also:
ConfigParser
-
addFilter
Config.Builder addFilter(ConfigFilter configFilter)
Registers aConfigFilter
instance that will be used byConfig
to filter elementary value before it is returned to a user.Filters are applied in same order as was registered by the
addFilter(ConfigFilter)
,addFilter(Function)
oraddFilter(Supplier)
method.ConfigFilter
is actually aBiFunction
<String
,String
,String
> where the first input parameter is the config key, the second is the original value and the result is the new value. So the filter can be added as simply as:Config.builder() .addFilter((key, originalValue) -> originalValue.toUpperCase()) .build();
The config system will automatically load filters defined as aservice
, unlessdisabled
.- Parameters:
configFilter
- filter instance- Returns:
- an updated builder instance
- See Also:
addFilter(Function)
,addFilter(Supplier)
-
addFilter
Config.Builder addFilter(Function<Config,ConfigFilter> configFilterProvider)
Registers aConfigFilter
provider as aFunction
<Config
,ConfigFilter
>. An obtained filter will be used byConfig
to filter elementary value before it is returned to a user.Filters are applied in same order as was registered by the
addFilter(ConfigFilter)
,addFilter(Function)
oraddFilter(Supplier)
method.Registered provider's
Function.apply(Object)
method is called every time the new Config is created. Eg. when this builder'sbuild()
method creates theConfig
or when the newchange event
is fired with new Config instance with its own filter instance is created.- Parameters:
configFilterProvider
- a config filter provider as a function ofConfig
toConfigFilter
- Returns:
- an updated builder instance
- See Also:
addFilter(ConfigFilter)
,addFilter(Supplier)
-
addFilter
Config.Builder addFilter(Supplier<Function<Config,ConfigFilter>> configFilterSupplier)
Registers aConfigFilter
provider as aSupplier
<Function
<Config
,ConfigFilter
>>. An obtained filter will be used byConfig
to filter elementary value before it is returned to a user.Filters are applied in same order as was registered by the
addFilter(ConfigFilter)
,addFilter(Function)
oraddFilter(Supplier)
method.Registered provider's
Function.apply(Object)
method is called every time the new Config is created. Eg. when this builder'sbuild()
method creates theConfig
or when the newchange event
is fired with new Config instance with its own filter instance is created.- Parameters:
configFilterSupplier
- a config filter provider as a supplier of a function ofConfig
toConfigFilter
- Returns:
- an updated builder instance
- See Also:
addFilter(ConfigFilter)
,addFilter(Function)
-
disableFilterServices
Config.Builder disableFilterServices()
Disables automatic registration of filters loaded as aservice
.Order of configuration filters loaded as a service is defined by
Priority
annotation.Automatic registration of filters as a service is enabled by default.
- Returns:
- an updated builder instance
- See Also:
ConfigFilter
-
disableCaching
Config.Builder disableCaching()
Disables caching of elementary configuration values onConfig
side.Caching is about
ConfigFilter
s. With disabled caching, registered filters are applied always you access elementary configuration value. With enabled caching, registered filters are applied just once per unique config node (key). Repeated access of already filtered key directly returns already cached value.Caching is enabled by default.
- Returns:
- an updated builder instance
- See Also:
addFilter(ConfigFilter)
-
changesExecutor
Config.Builder changesExecutor(Executor changesExecutor)
Specifies "observe-on"Executor
to be used byConfig.changes()
to deliver new Config instance. Executor is also used to process reloading of config from appropriatesource
.By default dedicated thread pool that creates new threads as needed, but will reuse previously constructed threads when they are available is used.
- Parameters:
changesExecutor
- the executor to use for async delivery ofConfig.changes()
events- Returns:
- an updated builder instance
- See Also:
changesMaxBuffer(int)
,Config.changes()
,Config.onChange(Function)
,Source.changes()
-
changesMaxBuffer
Config.Builder changesMaxBuffer(int changesMaxBuffer)
Specifies maximum capacity for each subscriber's buffer to be used by byConfig.changes()
to deliver new Config instance.By default
Flow.defaultBufferSize()
is used.Note: Not consumed events will be dropped off.
- Parameters:
changesMaxBuffer
- the maximum capacity for each subscriber's buffer ofConfig.changes()
events.- Returns:
- an updated builder instance
- See Also:
changesExecutor(Executor)
,Config.changes()
,Config.onChange(Function)
-
mappersFrom
Config.Builder mappersFrom(Config config)
Add mappers from another config instance. This may be useful if we need the same conversion behavior.- Parameters:
config
- config to extract mappers from- Returns:
- updated builder instance
-
-