commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oliver Heger <oliver.he...@oliver-heger.de>
Subject Re: configuration --- get the properties object loaded after the delayed refresh
Date Wed, 07 Sep 2011 18:05:46 GMT
Am 07.09.2011 19:03, schrieb Srinivas Jonnalagadda:
> Oliver,
>
> Thanks for the reply. I wrote a JUNIT test and Below is the code. My aim was that when
i set the refresh delay to 500 and after the initial test passed i put a thread.sleep for
2 minutes. when  the thread sleeps i am changing the value of the  JEDI_ENVIRONMENT to some
thing else. When the thread wakes up I wanted to see the props refreshed with new values so
that the tes tcase fails which means the program runs as expected. Pls help me.
>
Hi Srinivas,

somehow your code got mangled, so it is hardly readable.

But if I understand correctly, you obtain a Properties object from the 
configuration using something like

Properties props = ConfigurationConverter.getProperties(config);

Then you expect that the properties are automatically refreshed by the 
reloading strategy without any further action from your side, correct?

Well, the reloading strategies do not work that way unfortunately. 
Currently, there is no implementation which actively monitors a 
configuration file. Rather, the reloading strategy is only triggered 
when the configuration object is accessed, e.g. if a property is 
queried. FileChangedReloadingStrategy then checks the timestamp of the 
configuration file. If it has changed, it reloads the configuration. So 
you will only see new values if you query the configuration again.

HTH
Oliver

>
> sincerely,
> Srinivas Jonnalagadda
>   @TestPropertiesConfiguration config =
> Properties props =
> config.setFileName(
> config.load();
> FileChangedReloadingStrategy strategy =
> strategy.setRefreshDelay(500);
> config.setReloadingStrategy(strategy);
> assertEquals(config.getString(
> props = ConfigurationConverter.getProperties(config);
> assertEquals(props.getProperty(
> Thread.sleep(200000);
> assertEquals(config.getString(
> System.
> assertEquals(props.getProperty(
> }
>
>   publicvoidtestGetBuiltPropertyFileName() throwsException {newPropertiesConfiguration();
null;TEST_FILE); newFileChangedReloadingStrategy(); "JEDI_ENVIRONMENT"),"TEST");"JEDI_ENVIRONMENT"),"TEST");"JEDI_ENVIRONMENT"),"TEST");out.println("Test");"JEDI_ENVIRONMENT"),"TEST");
>
> From: Oliver Heger<oliver.heger@oliver-heger.de>
> To: Commons Users List<user@commons.apache.org>
> Sent: Saturday, September 3, 2011 11:05 AM
> Subject: Re: configuration --- get the properties object loaded after the delayed refresh
>
> Hi,
>
> Am 03.09.2011 07:59, schrieb Srinivas Jonnalagadda:
>> Hi,
>>
>> Below is the code for i wrote and seems at the propsConfig object gets refreshd after
the delay but the result object has the old values still. How do i get the new values into
the result object after the refresh. I am trying to create a Configuration listener as well
and that alos seems not to work.  The main objective for me is to get the properties object
loaded with new values without JBOSS server restart. Any help is appreciated.
>>
>>
>> Regards,
>> Srinivas J
>
> your code looks good, therefore I am not sure whether I fully understand
> your problem.
>
> How can you tell that the properties configuration object is refreshed
> correctly when the result object still has the old values? Do you get
> other results if you access the configuration object directly, e.g. by
> calling propsConfig.getString("someKey") ? (If so, this would indicate a
> bug in the ConfigurationConverter.getProperties() implementation.)
>
> Oliver
>
>>
>> Properties result = null;
>> Configuration config = null;
>> URL resourceURL = null;
>> FileChangedReloadingStrategy refreshStrategy = new FileChangedReloadingStrategy();
>> refreshStrategy.setRefreshDelay(refreshDelay);
>>
>> PropertiesConfiguration propsConfig = new PropertiesConfiguration();
>> propsConfig.setFileName(name);
>> propsConfig.load();
>> propsConfig.setReloadingStrategy(refreshStrategy);
>> result = ConfigurationConverter.getProperties(propsConfig);
>
>
> ---------------------------------------------------------------------
> 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


Mime
View raw message