public interface Config
Modifier and Type | Method and Description |
---|---|
void |
addConfigFilter(ConfigFilter configFilter)
Add a
ConfigFilter to the ConfigResolver. |
void |
addConfigSources(List<ConfigSource> configSourcesToAdd)
This method can be used for programmatically adding
ConfigSource s. |
String |
filterConfigValue(String key,
String value,
boolean forLog)
Filter the configured value.
|
List<ConfigFilter> |
getConfigFilters() |
ConfigSource[] |
getConfigSources() |
ConfigResolver.UntypedResolver<String> |
resolve(String name)
The entry point to the builder-based optionally typed configuration resolution mechanism.
|
ConfigSnapshot |
snapshotFor(ConfigResolver.TypedResolver<?>... typedResolvers)
This method can be used to access multiple
ConfigResolver.TypedResolver which must be consistent. |
ConfigResolver.UntypedResolver<String> resolve(String name)
ConfigResolver.UntypedResolver.as(Class)
.name
- The property key to resolveConfigSnapshot snapshotFor(ConfigResolver.TypedResolver<?>... typedResolvers)
This method can be used to access multiple
ConfigResolver.TypedResolver
which must be consistent.
The returned ConfigSnapshot
is an immutable object which contains all the
resolved values at the time of calling this method.
An example would be to access some 'myapp.host'
and 'myapp.port'
:
The underlying values are 'oldserver'
and '8080'
.
// get the current host value TypedResolver<String> hostCfg config.resolve("myapp.host") .cacheFor(TimeUnit.MINUTES, 60); // and right inbetween the underlying values get changed to 'newserver' and port 8082 // get the current port for the host TypedResolver<Integer> portCfg config.resolve("myapp.port") .cacheFor(TimeUnit.MINUTES, 60);In ths above code we would get the combination of
'oldserver'
but with the new port 8081
.
And this will obviously blow up because that host+port combination doesn't exist.
To consistently access n different config values we can start a ConfigSnapshot
for those values.
ConfigSnapshot cfgSnap = config.createSnapshot(hostCfg, portCfg); String host = cfgSnap.getValue(hostCfg); Integer port = cfgSnap.getValue(portCfg);Note that there is no close on the snapshot. They should be used as local variables inside a method. Values will not be reloaded for an open
ConfigSnapshot
.typedResolvers
- the list of ConfigResolver.TypedResolver
to be accessed in an atomic wayConfigSnapshot
which holds the resolved values of all the .ConfigSource[] getConfigSources()
void addConfigSources(List<ConfigSource> configSourcesToAdd)
ConfigSource
s.
It is not needed for normal 'usage' by end users, but only for Extension Developers!configSourcesToAdd
- the ConfigSources to addList<ConfigFilter> getConfigFilters()
ConfigFilter
s for the current application.void addConfigFilter(ConfigFilter configFilter)
ConfigFilter
to the ConfigResolver. This will only affect the current WebApp (or more precisely the
current ClassLoader and it's children).configFilter
- String filterConfigValue(String key, String value, boolean forLog)
key
- the key of the config propertyvalue
- to be filteredforLog
- whether the value is intended to be presented to some humans somehow.
If filtered for logging, then secrets might get starred out '*****'.Copyright © 2020 The Apache Software Foundation. All rights reserved.