Configuration Flavors

74 views
Skip to first unread message

Anatole Tresch

unread,
Oct 20, 2013, 12:33:37 AM10/20/13
to java-...@googlegroups.com
Configuration Flavors
This discussion is about configuration flavors, meaning the type of configuration that should be possible. Most of configuration libraries on the market on a low level are using Strings as main representation type of configuration. Though for many use cases this is completely sufficient, I think configuration should support basically also other types:
  • All basic data types such as Boolean, Character, Byte, Short, Long, Float, Double, BigDecimal, BigInteger.
  • Collections and arrays.
  • But also binary types may be supported, e.g. for reading jars, wars or ears for configuring a deployment.
As a consequence we might define a ConfigEntry similar like

public interface ConfigEntry<T>{
  CLass<T> getEntryType();
  T getValue();
  String getKey();
  String getOrigin();
  // to be discussed later/separatelly:
  //   - scope
  //   - attributes
}

Note that a ConfigEntry models the generic container for a configuration entry, not how the API for access may look like.

nicolas de loof

unread,
Oct 20, 2013, 2:08:29 AM10/20/13
to java-...@googlegroups.com
I don't actually understand a use case to configure binary types.
For all other data types, can be converted from a String representation - typically can use JSON syntax for structured data.

Anatole Tresch

unread,
Oct 20, 2013, 4:10:54 AM10/20/13
to java-...@googlegroups.com
JSON is only one way to structure data.

nicolas de loof

unread,
Oct 20, 2013, 4:59:14 AM10/20/13
to java-...@googlegroups.com
sure, just a sample. Can be xml, yaml, or whatever the JVM can convert to structured data a standard way. JAXB and (future) JSONB can help here

Juven Xu

unread,
Oct 26, 2013, 9:37:11 AM10/26/13
to nicolas de loof, java-...@googlegroups.com
I am also not getting the use case for binary, others are good.

Sent from Mailbox for iPad


--
You received this message because you are subscribed to the Google Groups "java-config" group.
To unsubscribe from this group and stop receiving emails from it, send an email to java-config...@googlegroups.com.
Visit this group at http://groups.google.com/group/java-config.
For more options, visit https://groups.google.com/groups/opt_out.

nicolas de loof

unread,
Oct 26, 2013, 11:04:46 AM10/26/13
to Juven Xu, java-...@googlegroups.com
I especially can't image how you expect such a binary entry to be manageable, if it's not human readable. 
Defining a configuration item as a URL to "some managed resource" is ok, but as a binary stream ? How do you expect ops to set and check value is well set ?


2013/10/26 Juven Xu <juve...@gmail.com>

Anatole Tresch

unread,
Oct 28, 2013, 3:47:35 PM10/28/13
to java-...@googlegroups.com, Juven Xu
Just to clarify: the config entry is a String. The value accessed can be an InputStream, e.g. using an adapter that reads the URL...

Anatole Tresch

unread,
Oct 28, 2013, 4:11:39 PM10/28/13
to java-...@googlegroups.com
To more clearer, I would suggest the code as follows:

String myURLValue = config.getProperty("myURL");   // "http://bar.foo/someFoo.css"
URL myURL = config.getProperty("myURL", ConfigAdapters.getURLAdapter());  // new URL("http://bar.foo/someFoo.css")
InputStream is = config.getProperty("myURL", ConfigAdapters.getURLInputStreamAdapter();  
     // new URL("http://bar.foo/someFoo.css").openStream(), or buffered using a SoftReference and a internal cache...

On the signature of Configuration it would be:

public String getProperty(String key);
public String getProperty(String key, String defaultValue);
public Integer getIntProperty(String key);
public Integer getIntProperty(String key, Integer defaultValue);
...
public <T> T getProperty(String key, PropertyAdapter<T> adapter);
public <T> T getProperty(String key, PropertyAdapter<T> adapter,  T defaultValue);

whereas

@FunctionalInterface
public interface PropertyAdapter{
   T adapt(String value);
}



2013/10/28 Anatole Tresch <atst...@gmail.com>



--
Anatole Tresch
Java Lead Engineer, JSR Spec Lead
Glärnischweg 10
CH - 8620 Wetzikon

Switzerland, Europe Zurich, GMT+1
Twitter:  @atsticks
Google: atsticks
Mobile  +41-76 344 62 79

Juven Xu

unread,
Oct 29, 2013, 4:12:56 AM10/29/13
to Anatole Tresch, java-...@googlegroups.com
This is really an nice extension point, users can adapt to whatever object they want.

Although I don’t see many use cases where it’s very necessary, but since adapting to Integer does not diff much from adapting to URL, I say +1.

Thanks,
Juven
Reply all
Reply to author
Forward
0 new messages