public static interface Config.Builder
Config Builder.
A factory for a Config object.
The application can set the following characteristics:
overrides - instance of override source;sources - instances of configuration source;mappers - ordered list of mapper functions.
It is also possible to disable loading of
ConfigMapperProviders as a service.parsers - ordered list of configuration content parsers.
It is also possible to disable loading of
ConfigParsers as a service.token reference resolving - a resolving of reference tokens in a key can be disabledfilters - ordered list of configuration value filters.
It is also possible to disable loading of
ConfigFilters as a service.caching - can be elementary configuration value processed by filter cached?
In case of ConfigMapperProviders, if there is no one that could be used to map appropriate type,
the mapping attempt throws a ConfigMappingException.
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 as Config.create() uses.
It builds composite config source from following sources, checked 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 formatEnvironment variables;System propertiesapplication.yaml - configuration file in YAML formatapplication.conf - configuration file in HOCON formatapplication.json - configuration file in JSON formatapplication.properties - configuration file in Java Properties formatConfigParser available
that supports appropriate media type.
Available parser means that the parser:
ServiceLoader;Config.create(),
ConfigSource,
ConfigParser,
ConfigFilter| Modifier and Type | Method and Description |
|---|---|
Config.Builder |
addFilter(ConfigFilter configFilter)
Registers a
ConfigFilter instance that will be used by Config 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(Class<T> type,
Function<Config,T> mapper)
Registers mapping function for specified
type. |
Config.Builder |
addMapper(ConfigMapperProvider configMapperProvider)
|
<T> Config.Builder |
addMapper(GenericType<T> type,
Function<Config,T> mapper)
Register a mapping function for specified
GenericType. |
Config.Builder |
addParser(ConfigParser configParser)
Registers a
ConfigParser instance that can be used by registered ConfigSources to
parse configuration content. |
<T> Config.Builder |
addStringMapper(Class<T> type,
Function<String,T> mapper)
|
Config |
build()
Builds new instance of
Config. |
Config.Builder |
changesExecutor(Executor changesExecutor)
Specifies "observe-on"
Executor to be used by Config.changes() to deliver new Config instance. |
Config.Builder |
changesMaxBuffer(int changesMaxBuffer)
Specifies maximum capacity for each subscriber's buffer to be used by by
Config.changes()
to deliver new Config instance. |
Config.Builder |
disableCaching()
Disables caching of elementary configuration values on
Config side. |
Config.Builder |
disableEnvironmentVariablesSource()
Disables use of
environment variables config source. |
Config.Builder |
disableFilterServices()
Disables automatic registration of filters loaded as a
service. |
Config.Builder |
disableKeyResolving()
Disables an usage of resolving key tokens.
|
Config.Builder |
disableMapperServices()
Disables automatic registration of mappers via
ConfigMapperProvider SPI
loaded as a service. |
Config.Builder |
disableParserServices()
Disables automatic registration of parsers loaded as a
service. |
Config.Builder |
disableSystemPropertiesSource()
Disables use of
system 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.
|
Config.Builder |
sources(List<Supplier<ConfigSource>> configSources)
Sets ordered list of
ConfigSource instance to be used as single source of configuration
to be wrapped into Config API. |
default Config.Builder |
sources(Supplier<ConfigSource> configSource)
Sets a
ConfigSource instance to be used as a source of configuration to be wrapped into Config API. |
default Config.Builder |
sources(Supplier<ConfigSource> configSource,
Supplier<ConfigSource> configSource2)
Sets an ordered pair of
ConfigSource instances to be used as single source of configuration
to be wrapped into Config API. |
default Config.Builder |
sources(Supplier<ConfigSource> configSource,
Supplier<ConfigSource> configSource2,
Supplier<ConfigSource> configSource3)
Sets an ordered trio of
ConfigSource instances to be used as single source of configuration
to be wrapped into Config API. |
Config.Builder sources(List<Supplier<ConfigSource>> configSources)
ConfigSource instance to be used as single source of configuration
to be wrapped into Config 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 by
Fallback MergingStrategy.
It is possible to use 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 sourcedisableEnvironmentVariablesSource()system properties config source
Can disabled by disableSystemPropertiesSource()configSources - ordered list of configuration sourcesdisableEnvironmentVariablesSource(),
disableSystemPropertiesSource(),
ConfigSources.create(Supplier...),
ConfigSources.CompositeBuilder,
ConfigSources.MergingStrategydefault Config.Builder sources(Supplier<ConfigSource> configSource)
ConfigSource instance to be used as a source of configuration to be wrapped into Config API.
Target source is composed from configSource and following sources (unless they are disabled) in order:
environment variables config sourcedisableEnvironmentVariablesSource()system properties config source
Can disabled by disableSystemPropertiesSource()configSource - the only config sourceConfig.create(Supplier...),
sources(List),
disableEnvironmentVariablesSource(),
disableSystemPropertiesSource()default Config.Builder sources(Supplier<ConfigSource> configSource, Supplier<ConfigSource> configSource2)
ConfigSource instances to be used as single source of configuration
to be wrapped into Config API.
Target source is composed from configSource and following sources (unless they are disabled) in order:
environment variables config sourcedisableEnvironmentVariablesSource()system properties config source
Can disabled by disableSystemPropertiesSource()configSource - the first config sourceconfigSource2 - the second config sourceConfig.create(Supplier...),
sources(List),
disableEnvironmentVariablesSource(),
disableSystemPropertiesSource()default Config.Builder sources(Supplier<ConfigSource> configSource, Supplier<ConfigSource> configSource2, Supplier<ConfigSource> configSource3)
ConfigSource instances to be used as single source of configuration
to be wrapped into Config API.
Target source is composed from config sources parameters and following sources (unless they are disabled) in order:
environment variables config sourcedisableEnvironmentVariablesSource()system properties config source
Can disabled by disableSystemPropertiesSource()configSource - the first config sourceconfigSource2 - the second config sourceconfigSource3 - the third config sourceConfig.create(Supplier...),
sources(List),
disableEnvironmentVariablesSource(),
disableSystemPropertiesSource()Config.Builder overrides(Supplier<OverrideSource> overridingSource)
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 and pod: qwerty. The
overrides are able to redefine values using wildcards (or without them). For example test.*.logging.level =
FINE overrides logging.level for all pods in test environment.
Override definitions are applied before any filter.
overridingSource - a source with overriding key patterns and assigned valuesConfig.Builder disableKeyResolving()
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.
Config.Builder disableValueResolving()
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.
Config.Builder disableEnvironmentVariablesSource()
environment variables config source.ConfigSources.environmentVariables()Config.Builder disableSystemPropertiesSource()
system properties config source.ConfigSources.systemProperties()<T> Config.Builder addMapper(Class<T> type, Function<Config,T> mapper)
type.
The last registration of same type overwrites previous one.
Programmatically registered mappers have priority over other options.
As another option, mappers are loaded automatically as a service
via ConfigMapperProvider SPI unless it is disabled.
And the last option, built-in mappers are registered.
T - type the mapper is registered fortype - class of type the mapper is registered formapper - mapping functionaddStringMapper(Class, Function),
addMapper(ConfigMapperProvider),
disableMapperServices()<T> Config.Builder addMapper(GenericType<T> type, Function<Config,T> mapper)
GenericType.
This is useful for mappers that support specificly typed generics, such as Map<String, Integer>
or Set<Foo<Bar>>.
To support mappers that can map any type (e.g. all cases of Map<String, V>),
use addMapper(ConfigMapperProvider) as it gives you full control over which types are supported, through
ConfigMapperProvider.mapper(GenericType).T - type of the resulttype - generic type to register a mapper formapper - mapping function<T> Config.Builder addStringMapper(Class<T> type, Function<String,T> mapper)
Function from String for specified type.
The last registration of same type overwrites previous one.
Programmatically registered mappers have priority over other options.
As another option, mappers are loaded automatically as a service
via ConfigMapperProvider SPI, if not disabled.
And the last option, built-in mappers are registered.
T - type the mapper is registered fortype - class of type the mapper is registered formapper - mapper instanceaddMapper(ConfigMapperProvider),
ConfigMappers,
disableMapperServices()Config.Builder addMapper(ConfigMapperProvider configMapperProvider)
ConfigMapperProvider with a map of String to specified type.
The last registration of same type overwrites previous one.
Programmatically registered mappers have priority over other options.
As another option, mappers are loaded automatically as a service
via ConfigMapperProvider SPI, if not disabled.
And the last option, built-in mappers are registered.
configMapperProvider - mapper provider instanceaddStringMapper(Class, Function),
ConfigMappers,
disableMapperServices()Config.Builder disableMapperServices()
ConfigMapperProvider SPI
loaded as a service.
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.
ConfigMapperProviderConfig.Builder addParser(ConfigParser configParser)
ConfigParser instance that can be used by registered ConfigSources to
parse configuration content.
Parsers are tried to be used by ConfigContext.findParser(String)
in same order as was registered by the addParser(ConfigParser) method.
Programmatically registered parsers have priority over other options.
As another option, parsers are loaded automatically as a service, if not
disabled.
configParser - parser instancedisableParserServices()Config.Builder disableParserServices()
service.
Order of configuration parsers loaded as a service is defined by Priority annotation.
Automatic registration of parsers as a service is enabled by default.
ConfigParserConfig.Builder addFilter(ConfigFilter configFilter)
ConfigFilter instance that will be used by Config 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) or addFilter(Supplier) method.
ConfigFilter is actually a BiFunction<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 a
service, unless
disabled.configFilter - filter instanceaddFilter(Function),
addFilter(Supplier)Config.Builder addFilter(Function<Config,ConfigFilter> configFilterProvider)
ConfigFilter provider as a Function<Config, ConfigFilter>. An
obtained filter will be used by Config 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) or addFilter(Supplier) method.
Registered provider's Function.apply(Object) method is called every time the new Config is created. Eg. when
this builder's build() method creates the Config or when the new change event
is fired with new Config instance with its own filter instance is created.
configFilterProvider - a config filter provider as a function of Config to ConfigFilteraddFilter(ConfigFilter),
addFilter(Supplier)Config.Builder addFilter(Supplier<Function<Config,ConfigFilter>> configFilterSupplier)
ConfigFilter provider as a Supplier<Function<Config, ConfigFilter>>. An obtained filter will be used by Config 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) or addFilter(Supplier) method.
Registered provider's Function.apply(Object) method is called every time the new Config is created. Eg. when
this builder's build() method creates the Config or when the new change event
is fired with new Config instance with its own filter instance is created.
configFilterSupplier - a config filter provider as a supplier of a function of Config to ConfigFilteraddFilter(ConfigFilter),
addFilter(Function)Config.Builder disableFilterServices()
service.
Order of configuration filters loaded as a service is defined by Priority annotation.
Automatic registration of filters as a service is enabled by default.
ConfigFilterConfig.Builder disableCaching()
Config side.
Caching is about ConfigFilters. 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.
addFilter(ConfigFilter)Config.Builder changesExecutor(Executor changesExecutor)
Executor to be used by Config.changes() to deliver new Config instance.
Executor is also used to process reloading of config from appropriate source.
By default dedicated thread pool that creates new threads as needed, but will reuse previously constructed threads when they are available is used.
changesExecutor - the executor to use for async delivery of Config.changes() eventschangesMaxBuffer(int),
Config.changes(),
Config.onChange(Function),
Source.changes()Config.Builder changesMaxBuffer(int changesMaxBuffer)
Config.changes()
to deliver new Config instance.
By default Flow.defaultBufferSize() is used.
Note: Not consumed events will be dropped off.
changesMaxBuffer - the maximum capacity for each subscriber's buffer of Config.changes() events.changesExecutor(Executor),
Config.changes(),
Config.onChange(Function)Config.Builder mappersFrom(Config config)
config - config to extract mappers fromCopyright © 2018–2019 Oracle and/or its affiliates. All rights reserved. Use is subject to license terms.