You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by Mohica Jasha <mo...@gmail.com> on 2012/02/02 16:42:03 UTC
configurationAdmin & update handler
Hi,
I have the following configuration dependency and its corresponding update
handler method:
@ConfigurationDependency(pid = "mypid", propagate = true)
void updated(Dictionary<String, ?> properties) throws
ConfigurationException {
....
}
If I change the configuration of mypid either by editing the etc/mypid.cfg
or by editing the configurion through the felix-webconsole everything works
fine and the above "updated" method will be called EXACTLY ONCE to handle
the new configuration.
Let's say the content of etc/mypid.cfg is the following:
oldParam = oldValue
THE PART THAT I DON'T GET:
I have implemented a webinterface for my service within the same bundle,
the webinterface through the following operations tries to update the
configuration of mypid:
Configuration config = configurationAdmin.getConfiguration("mypid", null);
Dictionary properties = new Hashtable<String, String>();
properties.put("felix.fileinstall.filename",
"file:/Users/mohica/apps/apache-karaf-2.2.5/etc/mypid.cfg");
properties.put("newParam", "newValue");
config.update(properties);
Now the problem is that the "updated" method will be called TWICE:
First with the following properties:
{service.pid=mypid, newparam=newValue,
felix.fileinstall.filename=file:/Users/mohica/apps/apache-karaf-2.2.5/etc/mypid.cfg}
and the second time with the following properties:
{service.pid=mypid, newparam=newValue,
felix.fileinstall.filename=file:/Users/mohica/apps/apache-karaf-2.2.5/etc/mypid.cfg,
oldparam=oldValue}
Why is it called twice? Am I doing anything wrong?
Mohica
Re: configurationAdmin & update handler
Posted by Pierre De Rop <pi...@gmail.com>.
Hi Mohica,
I think I have reproduced the issue you describe, and after having checked,
the root cause of the problem is probably the following:
By default, fileinstall listens to configuration updates, using the
ConfigAdmin interface "org.osgi.service.cm.ConfigurationListener" interface.
So, when you programatically change the configuration pid from your web
interface, using org.osgi.service.cm.Configuration.update() method, then
fileinstall is notified, and then writes back the configuration update in
your "etc/mypid.cfg" file. This behavior has the side effect of re-updating
the configuration pid, that's why your pojo's "updated" callback is invoked
twice.
Now, if you set the following fileinstall system propery in your felix
config.properties, the the problem disappears:
felix.fileinstall.disableConfigSave=false
You can have a look at the fileinstall online documentation, about this
property:
https://cwiki.apache.org/FELIX/apache-felix-file-install.html
kind regards;
/Pierre
On Thu, Feb 2, 2012 at 4:42 PM, Mohica Jasha <mo...@gmail.com> wrote:
> Hi,
>
> I have the following configuration dependency and its corresponding update
> handler method:
>
> @ConfigurationDependency(pid = "mypid", propagate = true)
> void updated(Dictionary<String, ?> properties) throws
> ConfigurationException {
> ....
> }
>
> If I change the configuration of mypid either by editing the etc/mypid.cfg
> or by editing the configurion through the felix-webconsole everything works
> fine and the above "updated" method will be called EXACTLY ONCE to handle
> the new configuration.
>
> Let's say the content of etc/mypid.cfg is the following:
> oldParam = oldValue
>
> THE PART THAT I DON'T GET:
> I have implemented a webinterface for my service within the same bundle,
> the webinterface through the following operations tries to update the
> configuration of mypid:
>
> Configuration config = configurationAdmin.getConfiguration("mypid", null);
> Dictionary properties = new Hashtable<String, String>();
> properties.put("felix.fileinstall.filename",
> "file:/Users/mohica/apps/apache-karaf-2.2.5/etc/mypid.cfg");
> properties.put("newParam", "newValue");
> config.update(properties);
>
> Now the problem is that the "updated" method will be called TWICE:
>
> First with the following properties:
> {service.pid=mypid, newparam=newValue,
>
> felix.fileinstall.filename=file:/Users/mohica/apps/apache-karaf-2.2.5/etc/mypid.cfg}
>
> and the second time with the following properties:
> {service.pid=mypid, newparam=newValue,
>
> felix.fileinstall.filename=file:/Users/mohica/apps/apache-karaf-2.2.5/etc/mypid.cfg,
> oldparam=oldValue}
>
>
> Why is it called twice? Am I doing anything wrong?
>
> Mohica
>