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.