You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Brent Verner <br...@rcfile.org> on 2004/05/18 10:25:03 UTC

[configuration] request for comments on refactoring

Hi all.

  I've been itching to use commons-configuration as the backend
for my own config system, but I've found myself refactoring the heck
out of commons-configuration along the way :-)

  So here goes what I'd think like to see commons-configuration look
like at the end of it all.  I'd appreciate any comments and/or
suggestions on the idea of refactoring commons-configuration and
on the specific ideas sketched below.

  As you'll see further down, my vision of using commons-configuration
would become as simple as:

  #
  # begin contents of "/path/to/a/file.properties"
  #
  include.some.file: file:relativeFile.properties
  include.some.jdbc: jdbc:...
  include.some.jndi: jndi:...
  include.another.file: file:/absolute/path/to/file.xml
  #
  # end example properties file
  #

  CURL curl = new CURL("file:/path/to/a/file.properties");

    //
    // no includes handled... configuration will have only
    // the four keys above.
    //
  Configuration singleSourceConfiguration = curl.load();

    //
    // or to load configurations with "include"d files.
    //
  CompositeConfiguration multipleSourceConfiguration = new CompositeConfiguration();
  curl.load(multipleSourceConfiguration);


  [p.s., I'm aware CURL is probably a bad name to use, but that's
         what it ended up being, and its way too late for me to be
         re-editing this mail ;-)  Maybe ConfigurationURL, 
         ConfigurationSource or ConfigurationLoader might work.]


org.apache.commons.configuration
  Configuration
  CompositeConfiguration 
  ConfigurationComparator
  ConfigurationUtils
  StrictConfigurationComparator
  CURL - entry point for loading configurations.  basically,
         a CURL is a primitive URL-like object takes a 
         Configuration URL, i.e.,
            file:/path/to/file.${EXTENSION}
            res:/path/to/file.${EXTENSION}
            jdbc:${JDBC_URL} [1]
            jndi:${JNDI_URL} [1]
          and instantiates w "handler" to actually manage the
          requested configuration.  I _think_ I'd like for
  UndefinedHandlerException - thrown when CURL handler is not found
  ??? [other bits from commons-configuration that should be here]

    [1] I've not looked far enough into jdbc and jndi configuration
        providers to know what the CURL would need to contain...


org.apache.commons.configuration.event
  ConfigurationChangedListener - receives notification when a
      Configuration has changed
  ConfigurationChangedEvent - sent by a ConfigurationProvider
      when its Configuration (or storage) has been modified.
      In my config system, I have a FileModificationMonitor
      subsystem (probaby to be renamed to ResourceModificationMonitor
      and contributed to a suitable jakarta project) that checks
      files for modification and sends a FileModifiedEvent to
      a listener.


org.apache.commons.configuration.provider
  ConfigurationProvider - interface used by Handler to manage
                          underlying Configuration, delegated
                          to by Handlers. defined load(..),
                          store(...) and other relevant
                          methods.
  ... [current Configuration providers, updated to adhere to 
       new ConfigurationProvider]


org.apache.commons.configuration.handler
  Handler - interface for CURL "protocol" handlers, basically
            defining load(...) and store(...) methods which 
            would delegate to an appropriate ConfigurationProvider

org.apache.commons.configuration.handler.jndi
  Handler - handler for "jndi:" CURL - jndi-backed configuration
org.apache.commons.configuration.handler.jdbc
  Handler - handler for "jdbc:" CURL - database-backed configuration
org.apache.commons.configuration.handler.res
  Handler - handler for "res:" CURL - Classloader.getResourceAsStream()
org.apache.commons.configuration.handler.file
  Handler - handler for "file:" CURL - any local file-based 
            configuration.  Would have logic to select a 
            ConfigurationProvider implementation based on CURL 
            attribute such as file extension.
org.apache.commons.configuration.handler.http
  Handler - handler for "http:" CURL - an http:// hosted configuration
            similar logic to choose ConfigurationProvider based
            on CURL attributes.



  The reason I think Handlers and ConfigurationProviders should
be separate is to allow the Handler to choose the ConfigurationProvider
based on CURL attributes (most notably file extension...)

  I've made an initial pass at implementing most of such a system 
from the existing commons-configuration bits, and would be most 
happy to put the stuff into CVS (somewhere?) if anyone is interested 
in helping out.

  I'm still a bit blurry on how best to handle the "include"
feature, but ISTM it might be best to handle the inclusion
of additional configurations in the CompositeConfiguration
class, and get rid of the BasePath[Loader|Configuration]
bits altogether.  Comments/Suggestions especially appreciated
here :-)

  There are a ton of other (important, even) details that I've
probably glossed over, but I hope the above paints a sane
enough picture to spark discussion.

  BTW, is there any reason that PropertiesConfiguration should
not be made to be compliant with java.util.Properties files?
I'm aware of the current duplicate-keys-create-lists behaviour, 
but IMO, it would be best to have the _same_ semantics as the
java.util.Properties files.  There is no reason we couldn't have
the current custom-parsed properties file provider along
side a standard Properties file provider.

  <wipes brow> phew...

thanks.
  brent

-- 
"Develop your talent, man, and leave the world something. Records are 
really gifts from people. To think that an artist would love you enough
to share his music with anyone is a beautiful thing."  -- Duane Allman

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


Re: [configuration] request for comments on refactoring

Posted by Emmanuel Bourg <eb...@micropole-univers.com>.
Brent Verner wrote:

>   BTW, is there any reason that PropertiesConfiguration should
> not be made to be compliant with java.util.Properties files?
> I'm aware of the current duplicate-keys-create-lists behaviour, 
> but IMO, it would be best to have the _same_ semantics as the
> java.util.Properties files.  There is no reason we couldn't have
> the current custom-parsed properties file provider along
> side a standard Properties file provider.

Interesting point, we use the .properties extension for 
PropertiesConfiguration but the extended syntax makes it incompatible 
with the good old java.util.Properties. Should we encourage the use of a 
different extension for extended properties to make it clear it's a 
different format ?

Emmanuel Bourg


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


RE: [configuration] request for comments on refactoring

Posted by Eric Pugh <ep...@upstate.com>.
I think that these ideas actually make a lot of sense..   How many times has
a ConfigurationChangedEvent been something you wanted?   I have a stack of
places where I manually nuke my configuration and reload it b/c I can't
listen for events of any type..

Let's keep this thread moving, but let's not lose focus on getting 1.0 out
the door.   1.0 will pretty much be Configuration as it stands.  These
refactorings sound like 2.0, and as soon as 1.0 is out, we should dive it..
Maybe make a branch for the 2.0 stuff for now?

Emmanuel I belive has volunteered to take a stab a release managering the
1.0, which means we should have something soon!

Eric

> -----Original Message-----
> From: Brent Verner [mailto:brent@rcfile.org]
> Sent: Tuesday, May 18, 2004 1:42 PM
> To: Jakarta Commons Developers List
> Subject: Re: [configuration] request for comments on refactoring
>
>
> [2004-05-18 12:35] Emmanuel Bourg said:
> | Brent Verner wrote:
> |
> | >org.apache.commons.configuration.event
> | >  ConfigurationChangedListener - receives notification when a
> | >      Configuration has changed
> | >  ConfigurationChangedEvent - sent by a ConfigurationProvider
> | >      when its Configuration (or storage) has been modified.
> | >      In my config system, I have a FileModificationMonitor
> | >      subsystem (probaby to be renamed to ResourceModificationMonitor
> | >      and contributed to a suitable jakarta project) that checks
> | >      files for modification and sends a FileModifiedEvent to
> | >      a listener.
>
> RE: naming of non-std properties file:
>   Yes.  The .properties name implies adherence to the format
> used by the j.u.Properties class.  Maybe .xprop(ertie)s would
> be best for the custom-parsed properties files.
>
> | There is a patch in Bugzilla to add support for reloadable
> | configurations (see
> | http://nagoya.apache.org/bugzilla/show_bug.cgi?id=25661) but no
> work has
> | been done on notification yet. How far should we go for notifications ?
> | Should we just tell the configuration has changed, or should we
> | enumerate the modified keys ? Maybe there is a way to leverage the
> | [event] component here.
>
> Good to see the reloadable configuration is on the horizon.
>
>   heh.  I started started with a PersistentConfiguration class, too
> :-), but I drifted away as I refactored further...  the CURL class
> (and the delegated Handler and ConfigurationProvider classes) made it
> look rather redundant in my approach considering that the
> configuration having a (symbolic) location implied some external
> storage.
>
>   I wasn't aware of the sandbox-event bits.  I may have found a home
> (or a replacement) for my FileModificationMonitor :-)
>
>   I've not found need to know about individual modified keys, but
> then my whole configuration system has always been file-based
> (and only modified via the actual file, not the application code).
> In my view of things, the ConfigurationChangedEvent could be
> made smart enough to accomodate either behaviour, and allow the
> Listener(s) to respond as needed.  Having said that our event
> classes might (need to) be too specific to use much of what is
> in what I'd assume to be the generic code in sandbox-event.
>
>   One thing I have learned the hard way :-\, is that a transactional
> reload() method is required to prevent breakage when the modified
> config file is unparseable (i.e., a busted xml document).  Instead
> of changing any of the active configuration when an attempt is made
> to reload an unparseable configuration file, I've found it best
> to fire the ConfigurationChangedEvent with a payload that lets
> the app react to the failed reload (most often logging a message,
> but in some cases I've actually had it send an email...)
>
>   Thanks for your comments.  I'll be more than glad to help in
> getting the reload bits done if you need it in hopes that it will
> make it easier to merge my config system into commons-config.
>
> cheers.
>   brent
>
> --
> "Develop your talent, man, and leave the world something. Records are
> really gifts from people. To think that an artist would love you enough
> to share his music with anyone is a beautiful thing."  -- Duane Allman
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org


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


Re: [configuration] request for comments on refactoring

Posted by Brent Verner <br...@rcfile.org>.
[2004-05-18 12:35] Emmanuel Bourg said:
| Brent Verner wrote:
| 
| >org.apache.commons.configuration.event
| >  ConfigurationChangedListener - receives notification when a
| >      Configuration has changed
| >  ConfigurationChangedEvent - sent by a ConfigurationProvider
| >      when its Configuration (or storage) has been modified.
| >      In my config system, I have a FileModificationMonitor
| >      subsystem (probaby to be renamed to ResourceModificationMonitor
| >      and contributed to a suitable jakarta project) that checks
| >      files for modification and sends a FileModifiedEvent to
| >      a listener.

RE: naming of non-std properties file:
  Yes.  The .properties name implies adherence to the format 
used by the j.u.Properties class.  Maybe .xprop(ertie)s would
be best for the custom-parsed properties files.

| There is a patch in Bugzilla to add support for reloadable 
| configurations (see 
| http://nagoya.apache.org/bugzilla/show_bug.cgi?id=25661) but no work has 
| been done on notification yet. How far should we go for notifications ? 
| Should we just tell the configuration has changed, or should we 
| enumerate the modified keys ? Maybe there is a way to leverage the 
| [event] component here.

Good to see the reloadable configuration is on the horizon.

  heh.  I started started with a PersistentConfiguration class, too
:-), but I drifted away as I refactored further...  the CURL class 
(and the delegated Handler and ConfigurationProvider classes) made it
look rather redundant in my approach considering that the 
configuration having a (symbolic) location implied some external
storage.

  I wasn't aware of the sandbox-event bits.  I may have found a home
(or a replacement) for my FileModificationMonitor :-)

  I've not found need to know about individual modified keys, but
then my whole configuration system has always been file-based
(and only modified via the actual file, not the application code).
In my view of things, the ConfigurationChangedEvent could be
made smart enough to accomodate either behaviour, and allow the
Listener(s) to respond as needed.  Having said that our event
classes might (need to) be too specific to use much of what is
in what I'd assume to be the generic code in sandbox-event.

  One thing I have learned the hard way :-\, is that a transactional
reload() method is required to prevent breakage when the modified
config file is unparseable (i.e., a busted xml document).  Instead 
of changing any of the active configuration when an attempt is made
to reload an unparseable configuration file, I've found it best
to fire the ConfigurationChangedEvent with a payload that lets
the app react to the failed reload (most often logging a message,
but in some cases I've actually had it send an email...)

  Thanks for your comments.  I'll be more than glad to help in 
getting the reload bits done if you need it in hopes that it will
make it easier to merge my config system into commons-config.

cheers.
  brent

-- 
"Develop your talent, man, and leave the world something. Records are 
really gifts from people. To think that an artist would love you enough
to share his music with anyone is a beautiful thing."  -- Duane Allman

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


Re: [configuration] request for comments on refactoring

Posted by Emmanuel Bourg <eb...@micropole-univers.com>.
Brent Verner wrote:

> org.apache.commons.configuration.event
>   ConfigurationChangedListener - receives notification when a
>       Configuration has changed
>   ConfigurationChangedEvent - sent by a ConfigurationProvider
>       when its Configuration (or storage) has been modified.
>       In my config system, I have a FileModificationMonitor
>       subsystem (probaby to be renamed to ResourceModificationMonitor
>       and contributed to a suitable jakarta project) that checks
>       files for modification and sends a FileModifiedEvent to
>       a listener.

There is a patch in Bugzilla to add support for reloadable 
configurations (see 
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=25661) but no work has 
been done on notification yet. How far should we go for notifications ? 
Should we just tell the configuration has changed, or should we 
enumerate the modified keys ? Maybe there is a way to leverage the 
[event] component here.

Emmanuel Bourg



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


Re: [configuration] request for comments on refactoring

Posted by Brent Verner <br...@rcfile.org>.
[2004-05-19 11:30] Emmanuel Bourg said:
| Brent Verner wrote:
| 
| >After looking at [vfs], I'm not sure which parts of it would be

| Yes the idea is to use [vfs] to retrieve the configuration file, not to 
| parse it.

right on.  forthcoming implementation will use vfs as the default
when no other specific handler is available.

  brent


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


Re: [configuration] request for comments on refactoring

Posted by Emmanuel Bourg <eb...@micropole-univers.com>.
Brent Verner wrote:

> After looking at [vfs], I'm not sure which parts of it would be
> used to implement the key/value nature of a Configuration; maybe
> only the setAttribute/getAttribute bits?
> 
> In any case, I'm gonna finish my originally planned refactoring 
> and then we can discuss what else should be refactored before
> calling this round of refactoring complete.  We can always decide
> to refactor the ConfigurationProvider impls to use [vfs] at a later
> date if there appears to be a positive return on the effort.

Yes the idea is to use [vfs] to retrieve the configuration file, not to 
parse it.

Emmanuel Bourg


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


Re: [configuration] request for comments on refactoring

Posted by Brent Verner <br...@rcfile.org>.
[2004-05-18 17:23] Emmanuel Bourg said:
| Brent Verner wrote:
| 
| >  CURL - entry point for loading configurations.  basically,
| >         a CURL is a primitive URL-like object takes a 
| >         Configuration URL, i.e.,
| >            file:/path/to/file.${EXTENSION}
| >            res:/path/to/file.${EXTENSION}
| >            jdbc:${JDBC_URL} [1]
| >            jndi:${JNDI_URL} [1]
| >          and instantiates w "handler" to actually manage the
| >          requested configuration.  I _think_ I'd like for
| >  UndefinedHandlerException - thrown when CURL handler is not found
| >  ??? [other bits from commons-configuration that should be here]
| 
| And what about delegating the configuration access job to [vfs] instead 
| ? [configuration] + [vfs] looks like a powerful combination.

After looking at [vfs], I'm not sure which parts of it would be
used to implement the key/value nature of a Configuration; maybe
only the setAttribute/getAttribute bits?

In any case, I'm gonna finish my originally planned refactoring 
and then we can discuss what else should be refactored before
calling this round of refactoring complete.  We can always decide
to refactor the ConfigurationProvider impls to use [vfs] at a later
date if there appears to be a positive return on the effort.

  b

-- 
"Develop your talent, man, and leave the world something. Records are 
really gifts from people. To think that an artist would love you enough
to share his music with anyone is a beautiful thing."  -- Duane Allman

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


Re: [configuration] request for comments on refactoring

Posted by Emmanuel Bourg <eb...@micropole-univers.com>.
Brent Verner wrote:

>   CURL - entry point for loading configurations.  basically,
>          a CURL is a primitive URL-like object takes a 
>          Configuration URL, i.e.,
>             file:/path/to/file.${EXTENSION}
>             res:/path/to/file.${EXTENSION}
>             jdbc:${JDBC_URL} [1]
>             jndi:${JNDI_URL} [1]
>           and instantiates w "handler" to actually manage the
>           requested configuration.  I _think_ I'd like for
>   UndefinedHandlerException - thrown when CURL handler is not found
>   ??? [other bits from commons-configuration that should be here]

And what about delegating the configuration access job to [vfs] instead 
? [configuration] + [vfs] looks like a powerful combination.

Emmanuel Bourg


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