You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Moein Enayati <mo...@gmail.com> on 2011/02/15 07:35:45 UTC

[Configuration] Problem in using FileChangedReloadingStrategy events ...

Dear All

I’ve just  have an XMLConfiguration object  initialized like this :


 * *

*            this.xmlConfig = new XMLConfiguration("preferences.xml");*

*            this.xmlConfig.setAutoSave(true);*

*            this.xmlConfig.setReloadingStrategy(new
FileChangedReloadingStrategy());*




and a bean  implements ConfigurationListener  Interface like this :




*public abstract class DefaultBean implements
Serializable,ConfigurationListener {*

*protected PropertyChangeSupport propertyChangeSupport = new
PropertyChangeSupport(this);*

* public abstract String getXmlBeanPropertyAddress();*

* public void configurationChanged(ConfigurationEvent event) {*

*System.out.println(“Event Type Value is 20 ! >> ”+event.getType());*

*}*

*}*


Also I’ve registered my bean and the XMLConfigoration as listeners :




*        this.xmlConfig.addConfigurationListener(myBeanInstance);*

*
myBeanInstance.addPropertyChangeListener(getPropertyChangeListener());*




To test the AutoReloadEvents , simply I used a timer which gets a property
of my XMLConfiguration object each 2 Seconds and it seems working .
*myBeanInstance.
configurationChanged() * is invoked  about two minutes after any change in
the source *preferences.xml*.

*
*

*But there is a small problem! *


The *event.getType()* returns a value of  *20*  which I could not find it in
*XMLConfiguration.EVENT_* constants.

Would you please help me to find the mistake I’ve probably done or is there
any way to have a trace line?



I could find only these EVENT_ constants :



*XMLConfiguration.EVENT_ADD_NODES = 11*

*XMLConfiguration.EVENT_ADD_PROPERTY = 1*

*XMLConfiguration.EVENT_CLEAR = 4*

*XMLConfiguration.EVENT_CLEAR_PROPERTY = 2*

*XMLConfiguration.EVENT_CLEAR_TREE =10*

*XMLConfiguration.EVENT_READ_PROPERTY =5*

*XMLConfiguration.EVENT_SET_PROPERTY =3*

*XMLConfiguration.EVENT_SUBNODE_CHANGED =12*




Thanks / Moein

Re: [Configuration] Problem in using FileChangedReloadingStrategy events ...

Posted by Oliver Heger <ol...@oliver-heger.de>.
Am 15.02.2011 09:37, schrieb Moein Enayati:
> Dear Ralph
>
> Thanks a lot .
> Now I can use these constants to handle my scenario.
>
> *but as a comment *, I can't find any constant named *EVENT_CONFIG_CHANGED*in
> * AbstractFileConfiguration* !
> the hole EVENT-Constants I can find are :
>
> AbstractFileConfiguration.EVENT_ADD_PROPERTY = 1;
> AbstractFileConfiguration.EVENT_CLEAR_PROPERTY = 2;
> AbstractFileConfiguration.EVENT_SET_PROPERTY =3;
> AbstractFileConfiguration.EVENT_CLEAR = 4;
> AbstractFileConfiguration.EVENT_READ_PROPERTY = 5;
> AbstractFileConfiguration.EVENT_RELOAD = 20;
>
>
> *Thanks again / Moein*
>
You are right, there is no generic change event. Rather, there are more 
specific events for different types of changes. A list of all events 
supported by different Configuration implementations can be found in the 
user's guide [1].

Oliver

[1] 
http://commons.apache.org/configuration/userguide/howto_events.html#Configuration_Events

>
>
>
>
> On Tue, Feb 15, 2011 at 11:36 AM, Ralph Goers<ra...@dslextreme.com>wrote:
>
>> Yes, you've stumbled on one of the uglinesses of Commons Configuration.  We
>> should convert these to an Enum in the experimental branch.
>>
>> The particular event you encountered is defined in
>> AbstractFileConfiguration.
>>
>>     /** Constant for the configuration reload event.*/
>>     public static final int EVENT_RELOAD = 20;
>>
>>     /** Constant fro the configuration changed event. */
>>     public static final int EVENT_CONFIG_CHANGED = 21;
>>
>> Ralph
>>
>>
>


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


Re: [Configuration] Problem in using FileChangedReloadingStrategy events ...

Posted by Moein Enayati <mo...@gmail.com>.
Dear Ralph

Thanks a lot .
Now I can use these constants to handle my scenario.

*but as a comment *, I can't find any constant named *EVENT_CONFIG_CHANGED*in
* AbstractFileConfiguration* !
the hole EVENT-Constants I can find are :

AbstractFileConfiguration.EVENT_ADD_PROPERTY = 1;
AbstractFileConfiguration.EVENT_CLEAR_PROPERTY = 2;
AbstractFileConfiguration.EVENT_SET_PROPERTY =3;
AbstractFileConfiguration.EVENT_CLEAR = 4;
AbstractFileConfiguration.EVENT_READ_PROPERTY = 5;
AbstractFileConfiguration.EVENT_RELOAD = 20;


*Thanks again / Moein*





On Tue, Feb 15, 2011 at 11:36 AM, Ralph Goers <ra...@dslextreme.com>wrote:

> Yes, you've stumbled on one of the uglinesses of Commons Configuration.  We
> should convert these to an Enum in the experimental branch.
>
> The particular event you encountered is defined in
> AbstractFileConfiguration.
>
>    /** Constant for the configuration reload event.*/
>    public static final int EVENT_RELOAD = 20;
>
>    /** Constant fro the configuration changed event. */
>    public static final int EVENT_CONFIG_CHANGED = 21;
>
> Ralph
>
>

Re: [Configuration] Problem in using FileChangedReloadingStrategy events ...

Posted by Ralph Goers <ra...@dslextreme.com>.
Yes, you've stumbled on one of the uglinesses of Commons Configuration.  We should convert these to an Enum in the experimental branch.

The particular event you encountered is defined in AbstractFileConfiguration. 

    /** Constant for the configuration reload event.*/
    public static final int EVENT_RELOAD = 20;

    /** Constant fro the configuration changed event. */
    public static final int EVENT_CONFIG_CHANGED = 21;

Ralph


On Feb 14, 2011, at 10:35 PM, Moein Enayati wrote:

> Dear All
> 
> I’ve just  have an XMLConfiguration object  initialized like this :
> 
> 
> * *
> 
> *            this.xmlConfig = new XMLConfiguration("preferences.xml");*
> 
> *            this.xmlConfig.setAutoSave(true);*
> 
> *            this.xmlConfig.setReloadingStrategy(new
> FileChangedReloadingStrategy());*
> 
> 
> 
> 
> and a bean  implements ConfigurationListener  Interface like this :
> 
> 
> 
> 
> *public abstract class DefaultBean implements
> Serializable,ConfigurationListener {*
> 
> *protected PropertyChangeSupport propertyChangeSupport = new
> PropertyChangeSupport(this);*
> 
> * public abstract String getXmlBeanPropertyAddress();*
> 
> * public void configurationChanged(ConfigurationEvent event) {*
> 
> *System.out.println(“Event Type Value is 20 ! >> ”+event.getType());*
> 
> *}*
> 
> *}*
> 
> 
> Also I’ve registered my bean and the XMLConfigoration as listeners :
> 
> 
> 
> 
> *        this.xmlConfig.addConfigurationListener(myBeanInstance);*
> 
> *
> myBeanInstance.addPropertyChangeListener(getPropertyChangeListener());*
> 
> 
> 
> 
> To test the AutoReloadEvents , simply I used a timer which gets a property
> of my XMLConfiguration object each 2 Seconds and it seems working .
> *myBeanInstance.
> configurationChanged() * is invoked  about two minutes after any change in
> the source *preferences.xml*.
> 
> *
> *
> 
> *But there is a small problem! *
> 
> 
> The *event.getType()* returns a value of  *20*  which I could not find it in
> *XMLConfiguration.EVENT_* constants.
> 
> Would you please help me to find the mistake I’ve probably done or is there
> any way to have a trace line?
> 
> 
> 
> I could find only these EVENT_ constants :
> 
> 
> 
> *XMLConfiguration.EVENT_ADD_NODES = 11*
> 
> *XMLConfiguration.EVENT_ADD_PROPERTY = 1*
> 
> *XMLConfiguration.EVENT_CLEAR = 4*
> 
> *XMLConfiguration.EVENT_CLEAR_PROPERTY = 2*
> 
> *XMLConfiguration.EVENT_CLEAR_TREE =10*
> 
> *XMLConfiguration.EVENT_READ_PROPERTY =5*
> 
> *XMLConfiguration.EVENT_SET_PROPERTY =3*
> 
> *XMLConfiguration.EVENT_SUBNODE_CHANGED =12*
> 
> 
> 
> 
> Thanks / Moein


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