river-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dennis Reedy <dennis.re...@gmail.com>
Subject Re: Removing the need for config files
Date Wed, 11 Jan 2012 13:28:19 GMT

On Jan 11, 2012, at 309AM, Greg Trasuk wrote:

> On Wed, 2012-01-11 at 01:01, Peter Firmstone wrote:
>> You could try Dennis Reedy's Groovy Configuration Provider, that'll give 
>> you Pojo's with Java like syntax.  We still need to add an ant task to 
>> generate the groovy javadoc too.
>> It would be nice to see that system used by default.
> Just curious...What is the advantage of Groovy's syntax over
> ConfigurationFile?

You get to use *real* code in your configuration. From my experience people are usually very
confused with configuration file syntax, and why it is java-like but you cannot use any logic.
Just to show a simple example for reggie (I hope you'll be able to get the gist of it), figuring
out the correct unicast discovery host based on a system property would be as follows (note
the initialUnicastDiscoveryProperty is declared just as a property as well):

class ReggieConfig {
    int initialUnicastDiscoveryPort = 10500

    String[] getInitialMemberGroups() {
        def groups = [System.getProperty(Constants.GROUPS_PROPERTY_NAME,
        return groups as String[]

    String getUnicastDiscoveryHost() {
        String host = java.net.InetAddress.getLocalHost().getHostAddress()
        String value = System.getProperty("java.rmi.server.hostname")
        if(value != null) {
            host = java.net.InetAddress.getByName(value).getHostAddress()
        return host


Inheritance is supported as well, etc.. etc ...

I also use a DynamicConfiguration (extends AbstractConfiguration) class as well. Its use is
shown here:

DynamicConfiguration config = new DynamicConfiguration();
config.setEntry("org.rioproject.watch", "collectionSize", collectionSize);
Watch watch = construct2("watch", config);

Lastly, I recall Calum Shaw-Mackay was doing work with the Glyph project that was using annotations
to wire up configs with annotations.

> Also, I just had an interesting thought: What if a service deployer (as
> in "ServiceStarter is a service deployer") were to scan the service
> class for JSR330 @Inject annotations and plug in values taken from the
> config file?

Sure, that would be nice (just be careful not to fill up the perm-gen space when looking for
annotations though). I'm wondering though how you would map the component and name to the
property or method to be set. 

View raw message