Hi Oliver,

Oliver Heger wrote:

> Hi,
> 
> one limitation of the 1.x versions of [configuration] is the incomplete
> support for concurrent access to Configuration objects. In version 2.0
> we should try to improve this.
> 
> I have some ideas about this topic - not fully thought out - and would
> like to start a discussion. Here they are (in no specific order):
> 
> - Thread-safety is not always required. Therefore, I would like to take
> an approach similar to the JDK Collections framework: having basic,
> unsynchronized configurations which can be turned into thread-safe ones.

Fair approach.

> - Many Configuration implementations are based on a hash map. Access to
> their content could be made thread-safe by replacing the map by a
> ConcurrentHashMap.

You could use a protected method to instantiate the underlaying HashMap. 
Then you're free in overloaded Configurations.synchronizedConfiguration 
methods to use a derived class or a wrapper. It has also implications on 
subset().

> - For hierarchical configurations situation is more complex. Here we
> will probably need something like a ReadWriteLock to protect their
> content. (There could be different lock implementations including a
> dummy one used by unsynchronized configurations).
> 
> - Reloading is a major problem; at least in the way it is implemented
> now, it is very hard to get synchronization correct and efficient.
> Therefore, I would like to use a different strategy here. One option
> could be to not handle reloading in Configuration objects, but on an
> additional layer which creates such objects.
> 
> - Other properties of configuration objects (e.g. the
> throwExceptionOnMissing flag or the file name) must be taken into
> account, too. In a typical use case those should not be accessed
> frequently, so it is probably not an issue to always synchronize them or
> make them volatile.
> 
> Looking forward to your input

Another option would be immutability (well, apart probably from reloading). 
Personally I have often the use case that I do not want to offer my 
clients/consumers to write into the configuration. One approach can also be 
the JDK approach creating Collections.unmodifiableConfiguration.

However, what also bugs me in the meantime is the current hard relation 
between the configuration object and its format. Why should I care at all in 
what format the configuration had been saved when I access its values?

For some time I am thinking now of something in the line of:

- interface Configuration: Core interfaces, only getters
- interface ReloadableConfiguration extends Configuration, Reloadable
- class BaseConfiguration: In memory, implements all the stuff for 
interpolation and the setters

- interface ConfigurationSource: Core interface to load (and probably save a 
configuration)
- class PropertiesConfigurationSource: Concrete implementation that loads a 
properties file and creates a BaseConfiguration

This approach offers immutability for the Configuration itself and also 
allows Serializability. Format is separated completely from the 
configuration functionality.

I know, this looks more like Configuration 3.0 ... ;-)

- Jörg


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

Reply via email to