commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ralph Goers <ralph.go...@dslextreme.com>
Subject Re: configuration --- get the properties object loaded after the delayed refresh
Date Thu, 08 Sep 2011 06:18:01 GMT
Without knowing why you would want to do this I can't really comment.  Commons Configuration
will cache the data so the typical usage is to get the property every time it is needed. After
all, if you aren't re-reading the properties why would you care that a value has changed?

Ralph

On Sep 7, 2011, at 6:12 PM, Srinivas wrote:

> Ralph,
> 
> Even I saw that and the FCStrategy issue where  vfs is taken instead of file when I use
the Url concept. Then I changed to setFileName. I also used configurationutil.locate which
actually gave file notfound if I remember. After struggling for 2 weeks I am confused the
use of this commons configuration tool. My aim is to change a value in property file and get
this reflect application wide without restarting JBOSS/app server. I am writing some simple
junit before deploying to server and that itself is not working. I was expecting a simple
framework without me doing the polling etc.
> 
> 
> Regards
> Sj
> 
> On Sep 7, 2011, at 6:29 PM, Ralph Goers <ralph.goers@dslextreme.com> wrote:
> 
> Even the listener is triggered by something retrieving a property. There is no thread
doing polling.
> 
> However, if you are using this with JBoss 5+ I'm not sure the code below will work. I've
had developers reporting that JBoss is returning vfsfile as the protocol when the name is
turned into a URL and then ConfigurationUtil.fileFromURL fails.  They have reported that using
VFSFileChangedReloadingStrategy works fine with JBoss, although it isn't clear to me why since
it doesn't explicitly support the vfsfile protocol.
> 
> Ralph
> 
> On Sep 7, 2011, at 12:07 PM, Srinivas Jonnalagadda wrote:
> 
> Oliver,
> 
> Thanks so i misunderstood the reload startegies. But what about the listeners. Can we
trigger signal to reload. I wanted to use ConfigurationChangedListener. But that still doesnt
solve the purpose right. For more clarity i am pasting the unit test i wrote:
> 
> Regards,
> srinivas jonnalagadda
> 
> @Test
> public  void  testGetBuiltPropertyFileName() throws Exception {
> PropertiesConfiguration config = new PropertiesConfiguration(); 
> Properties props = null;
> config.setFileName(TEST_FILE);    
> config.load(); 
> FileChangedReloadingStrategy strategy = new FileChangedReloadingStrategy(); 
> strategy.setRefreshDelay(500); 
> config.setReloadingStrategy(strategy);       
> assertEquals(config.getString("JEDI_ENVIRONMENT"),"TEST");
> props = ConfigurationConverter.getProperties(config);
> assertEquals(props.getProperty("JEDI_ENVIRONMENT"),"TEST");
> Thread.sleep(200000); 
> assertEquals(config.getString("JEDI_ENVIRONMENT"),"TEST");
> System.out.println("Test");
> assertEquals(props.getProperty("JEDI_ENVIRONMENT"),"TEST");
> }
> 
> From: Oliver Heger <oliver.heger@oliver-heger.de>
> To: Commons Users List <user@commons.apache.org>
> Sent: Wednesday, September 7, 2011 1:05 PM
> Subject: Re: configuration --- get the properties object loaded after the delayed refresh
> 
> 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
> 
> 
> ---------------------------------------------------------------------
> 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