konf
konf copied to clipboard
Ability to get some 'SmartProperty' with extra information
This is a feature which obviously is not a simple one but can be useful. Implementation for all the features can be spread in multiple release. The concept for 'SmartProperty' (named can be different obviously), example:
final SmartProperty<String> myProperty = new SmartProperty<String>("my.super.key");
final String value = myProperty.getValue();
but where it's interesting is for some extra information (meta information) about the property:
Date myProperty.getLoadedTime();
MetaPropertyInformation myProperty.getMetaInformation();
long myProperty.getMetaInformation().getLineNumber();
getLoadedTime() --> return the date/time when the property was loaded from it's config source getMetaInformation() --> return a new object which can provide more details on where that property was setup (file name, URL etc...) and can provide potentially the line number where that property was defined.
the getLoadedTime() method may make more sense to be in the MetaPropertyInformation class.
The other big advantage of the "SmartProperty" class by using "getValue()" instead of potentially caching the value one time, it will automatically return the latest value if the source for the property is one that was setup to be reloaded every X minutes / seconds.
We can and should add this.
Linenumber would be a bit tough, but resource name and scheme should be easy
file:://foo.bar/
, http://localhost:9090/consul/config/
, etc.
Some parsers support line number and the ones that do .. we can expose. For others.. -1?
There is some prior art.
https://github.com/typesafehub/config/blob/b0ae5cac203ab24f8fd4a04b211b92e479e39490/config/src/main/java/com/typesafe/config/ConfigOrigin.java#L30
There is a ConfigValue, ConfigObject which has ConfigOrigin. I will probably go with these names if possible since this seems to be a popular lib. But I see that this is a nice feature.
I will add this to konf core.