You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by "Kevin A. Burton" <bu...@newsmonster.org> on 2005/02/28 01:30:12 UTC

Runtime properties... easy VM configuration with system props... (contrib?)

I was wondering what people would think of this.

At work (and in various places) I've needed simple cross-application 
configuration.

For example I'll need to configure the FeedParser, Lucene, etc when it 
starts up.

Lucene is a good example.  Right now some of the runtime configurations 
are done with system properties:

  public static final int DEFAULT_MAX_FIELD_LENGTH =
    Integer.parseInt(System.getProperty("org.apache.lucene.maxFieldLength",
      "10000"));

Which is a *bit* confusing because this doesn't even correspond to a 
classname or field name.

So what I did was create a concept known as a "runtime property" which 
isn't a constant in the purest sense:

  public static int DEFAULT_MAX_FIELD_LENGTH = 10000;

So now I have a runtime property of DEFAULT_MAX_FIELD_LENGTH with a 
default value of 10000.

The trick si that its non-final.  This means I can change it at anytime 
in my application

So what I do now is that I just define a system property for this variable:

org.apache.lucene.index.IndexWriter.DEFAULT_MAX_FIELD_LENGTH=50000

Then on VM startup I call:

 - Load my properties file into system properties
  - Call RuntimeProperties.init()

Which looks at *all* system properties and determines which ones can be 
reflected into classes and then into fields. If its able to reflect them 
into classes and fields then we attempt to parse and set the value.  All 
of this of course is done via reflection.

Now of course reflection is a *bit* slow but this is only done once and 
takes about 2 seconds.  Certainly worth it.

Right now I have a fairly functional working prototype.  It also 
supports the List interface so you can define lists and they are updated 
in Java.

There's some more work I want to handle including saving and loading 
properties into .ser files via serialization.  This way the developer 
could set a value via XMLRPC or some other UI and then save the values 
so that they'll be restored between VM lifecycle.

I haven't seen any other projects out there like this. 

-- 

Use Rojo (RSS/Atom aggregator).  Visit http://rojo.com. Ask me for an 
invite!  Also see irc.freenode.net #rojo if you want to chat.

Rojo is Hiring! - http://www.rojonetworks.com/JobsAtRojo.html

If you're interested in RSS, Weblogs, Social Networking, etc... then you 
should work for Rojo!  If you recommend someone and we hire them you'll 
get a free iPod!
    
Kevin A. Burton, Location - San Francisco, CA
       AIM/YIM - sfburtonator,  Web - http://peerfear.org/
GPG fingerprint: 5FB2 F3E2 760E 70A8 6174 D393 E84D 8D04 99F1 4412


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org