You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by ch...@lhsystems.com on 2008/01/23 12:18:48 UTC

commons-configuration reload() how to do it?

Hello,

how is it possible to reload a configuration file without using a
ReloadingStrategy (or, to be more precise: FileChangedReloadingStrategy
or ManagedReloadingStrategy)?

I found out the time consuming way that calling
XMLConfiguration.reload() does nothing because it seems like that as
default ReloadingStrategy the InvariantReloadingStrategy is used, which
prevents reloading.

So how can i reload if i don't want to do it automatically and don't
want to trigger it via JMX?

thanks in advance and regards,
christian Migowski!



P.S. reproducing this issue is easy:
//first create a xml file (yourfile.xml):

<?xml version="1.0" encoding="UTF-8"?>
<x><mycontent>hi there</mycontent></x>


code:
XMLConfiguration config = new XMLConfiguration("yourfile.xml");
System.out.println("mycontent: "+config.getString("mycontent"));
//now change your file
Thread.sleep(10000);
config.reload();
//and see, the changed file content isn't reloaded
System.out.println("mycontent: "+config.getString("mycontent"));
 


Sitz der Gesellschaft / Corporate Headquarters:
Lufthansa Systems Infratec GmbH, Kelsterbach
Registereintragung / Registration:
Amtsgericht Darmstadt 83851


Vorsitzender des Aufsichtsrats /
Chairman of the Supervisory Board:
Dr. Gunter Kuechler


Geschaeftsfuehrung / Management:
Dr. Hannes Pfister

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


AW: commons-configuration reload() how to do it?

Posted by ch...@lhsystems.com.
Hi Oliver,

thanks for your advice! 

> Your observation that reload() only performs a reload if the 
> reloading 
> strategy considers this necessary (which is never for the default 
> reloading strategy) is correct.
...
> Maybe an overloaded reload() method with a boolean force flag 
> would make 
> sense to make this more convenient?

Yes. For me it seems most logical to hide the current reload method
(rename it to something like reload_internal() and make it private) and
create a reload method which actually reloads.
In the current implementation, the reload() method is useless (from a
users point of view): either it does not reload or the config will be
automatically reloaded when a property is accessed - no need to call
reload().

I understand the rationale behind the reload approach in
commons-configuration, but i think it is a common use case to load
config, work with it and at some point of time explicitly reload it. If
you don't agree, a hint in the documentation (explicitly calling reload
does nothing for you) would help other users for sure.

thanks again,
best regards,

christian!


----
 


Sitz der Gesellschaft / Corporate Headquarters:
Lufthansa Systems Infratec GmbH, Kelsterbach
Registereintragung / Registration:
Amtsgericht Darmstadt 83851


Vorsitzender des Aufsichtsrats /
Chairman of the Supervisory Board:
Dr. Gunter Kuechler


Geschaeftsfuehrung / Management:
Dr. Hannes Pfister

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


Re: commons-configuration reload() how to do it?

Posted by Oliver Heger <ol...@oliver-heger.de>.
christian.migowski@lhsystems.com schrieb:
> Hello,
> 
> how is it possible to reload a configuration file without using a
> ReloadingStrategy (or, to be more precise: FileChangedReloadingStrategy
> or ManagedReloadingStrategy)?
> 
> I found out the time consuming way that calling
> XMLConfiguration.reload() does nothing because it seems like that as
> default ReloadingStrategy the InvariantReloadingStrategy is used, which
> prevents reloading.
> 
> So how can i reload if i don't want to do it automatically and don't
> want to trigger it via JMX?
> 
> thanks in advance and regards,
> christian Migowski!

Your observation that reload() only performs a reload if the reloading 
strategy considers this necessary (which is never for the default 
reloading strategy) is correct.

However a manual reload is quite easy: Just do

config.clear();
config.load();

(provided that a valid URL, file, or file name is set).

Maybe an overloaded reload() method with a boolean force flag would make 
sense to make this more convenient?

Oliver

> 
> 
> 
> P.S. reproducing this issue is easy:
> //first create a xml file (yourfile.xml):
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <x><mycontent>hi there</mycontent></x>
> 
> 
> code:
> XMLConfiguration config = new XMLConfiguration("yourfile.xml");
> System.out.println("mycontent: "+config.getString("mycontent"));
> //now change your file
> Thread.sleep(10000);
> config.reload();
> //and see, the changed file content isn't reloaded
> System.out.println("mycontent: "+config.getString("mycontent"));
>  
> 
> 
> Sitz der Gesellschaft / Corporate Headquarters:
> Lufthansa Systems Infratec GmbH, Kelsterbach
> Registereintragung / Registration:
> Amtsgericht Darmstadt 83851
> 
> 
> Vorsitzender des Aufsichtsrats /
> Chairman of the Supervisory Board:
> Dr. Gunter Kuechler
> 
> 
> Geschaeftsfuehrung / Management:
> Dr. Hannes Pfister
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
> 


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