You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by David Leangen <os...@leangen.net> on 2015/09/17 11:29:30 UTC

[SCR] Obtaining component configuration

Hi!

Using Felix SCR...

I am trying to obtain a component’s properties object by:

  ConfigurationAdmin cm = {obtain the cm}
  Configuration componentConfig = cm.getConfiguration( componentPid );
  componentConfig.getProperties();

I can confirm that I am getting the correct Configuration object (when I add a property and update, it updates the component), however, I am getting a null result when I try to obtain the properties before doing an update, and an “incomplete” properties object after the update (containing only the service.pid property).

Am I misunderstanding what should happen? Or is my understanding correct, but I am for some reason not getting the correct result?


Thanks!
=David


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: [SCR] Obtaining component configuration

Posted by David Leangen <os...@leangen.net>.
Hi Felix,

Thanks for the reply. More info below.

>> So then, what is the right way to obtain the existing properties of a component (other than the ones I just set)? I was not successful when digging around the spec to find the answer.
> 
> But, as BJ on bndtools notes, if you are just a DS component, you should not be fiddling with ConfigAdmin and just have an activate method which gets the configuration injected — either as part of the ComponentContext or the Map<String, Object> argument to the activate method. This way you also guarantee that you get the default values for your properties declared in the descriptor which don’t exist in the configuration.

Right!

What I apparently did not explain well was that I am trying to do this from a separate management service (in a separate bundle). The management service needs to get the target component’s current properties, then update them based on what the existing (and desired) properties are.

Since I have been unsuccessful at obtaining the existing properties, I am currently unable to do this.


Cheers,
=David




Re: [SCR] Obtaining component configuration

Posted by Felix Meschberger <fm...@adobe.com>.
Hi David

> Am 18.09.2015 um 08:34 schrieb David Leangen <os...@leangen.net>:
> 
> 
> Hi Felix,
> 
> Thank you very much for this!
> 
> [  I regret that in my attempt to try to figure this out quickly I just double-posted on bndtools… Bad me! :-(  ]
> 
> So, you are confirming:
> * The first time getProperties() is called, it returns null (i.e. this is expected behaviour)

Yes

> * After update, getProperties() will only return the properties just set (i.e. this is expected behaviour)

update(Dictionary) replaces all existing properties with your new sets of properties. So existing old properties are lost unless you had them in Dictionary.

> 
> So then, what is the right way to obtain the existing properties of a component (other than the ones I just set)? I was not successful when digging around the spec to find the answer.

But, as BJ on bndtools notes, if you are just a DS component, you should not be fiddling with ConfigAdmin and just have an activate method which gets the configuration injected — either as part of the ComponentContext or the Map<String, Object> argument to the activate method. This way you also guarantee that you get the default values for your properties declared in the descriptor which don’t exist in the configuration.

Regards
Felix

> 
> 
> Best,
> =David
> 
> 
> 
> 
>> On Sep 18, 2015, at 3:26 PM, Felix Meschberger <fm...@adobe.com> wrote:
>> 
>> Hi David
>> 
>>> Am 17.09.2015 um 11:29 schrieb David Leangen <os...@leangen.net>:
>>> 
>>> 
>>> Hi!
>>> 
>>> Using Felix SCR…
>> 
>> I think this is related to Felix Configuration Admin, though
>> 
>>> 
>>> I am trying to obtain a component’s properties object by:
>>> 
>>> ConfigurationAdmin cm = {obtain the cm}
>>> Configuration componentConfig = cm.getConfiguration( componentPid );
>>> componentConfig.getProperties();
>>> 
>>> I can confirm that I am getting the correct Configuration object (when I add a property and update, it updates the component), however, I am getting a null result when I try to obtain the properties before doing an update, and an “incomplete” properties object after the update (containing only the service.pid property).
>> 
>> When calling getConfiguration for the first time for a given componentPid the configuration is newly created and there are no properties. Which is why you getProperties() returns null.
>> 
>> You have to first call update(Dictionary) to set the initial configuration. After that getProperties() will return a Dictionary with the values just set.
>> 
>> Calling update() (the no arg variant) just causes the configuration to be reloaded from persistence. Yet, for a new configuration which has never been updated with update(Dictionary) this is essentially a no-op.
>> 
>> Mind you though: Calling getConfiguration(String) (the single argument variant) binds the configuration to your calling bundle context. You might want to consider using the getConfiguration(String pid, String bundleLocation) variant to create a new configuration.
>> 
>> Regards
>> Felix
>> 
>>> 
>>> Am I misunderstanding what should happen? Or is my understanding correct, but I am for some reason not getting the correct result?
>>> 
>>> 
>>> Thanks!
>>> =David
>>> 
>>> 
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>>> For additional commands, e-mail: users-help@felix.apache.org
>>> 
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>> For additional commands, e-mail: users-help@felix.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
> 


Re: [SCR] Obtaining component configuration

Posted by David Leangen <os...@leangen.net>.
Hi Felix,

Thank you very much for this!

[  I regret that in my attempt to try to figure this out quickly I just double-posted on bndtools… Bad me! :-(  ]

So, you are confirming:
 * The first time getProperties() is called, it returns null (i.e. this is expected behaviour)
 * After update, getProperties() will only return the properties just set (i.e. this is expected behaviour)

So then, what is the right way to obtain the existing properties of a component (other than the ones I just set)? I was not successful when digging around the spec to find the answer.


Best,
=David




> On Sep 18, 2015, at 3:26 PM, Felix Meschberger <fm...@adobe.com> wrote:
> 
> Hi David
> 
>> Am 17.09.2015 um 11:29 schrieb David Leangen <os...@leangen.net>:
>> 
>> 
>> Hi!
>> 
>> Using Felix SCR…
> 
> I think this is related to Felix Configuration Admin, though
> 
>> 
>> I am trying to obtain a component’s properties object by:
>> 
>> ConfigurationAdmin cm = {obtain the cm}
>> Configuration componentConfig = cm.getConfiguration( componentPid );
>> componentConfig.getProperties();
>> 
>> I can confirm that I am getting the correct Configuration object (when I add a property and update, it updates the component), however, I am getting a null result when I try to obtain the properties before doing an update, and an “incomplete” properties object after the update (containing only the service.pid property).
> 
> When calling getConfiguration for the first time for a given componentPid the configuration is newly created and there are no properties. Which is why you getProperties() returns null.
> 
> You have to first call update(Dictionary) to set the initial configuration. After that getProperties() will return a Dictionary with the values just set.
> 
> Calling update() (the no arg variant) just causes the configuration to be reloaded from persistence. Yet, for a new configuration which has never been updated with update(Dictionary) this is essentially a no-op.
> 
> Mind you though: Calling getConfiguration(String) (the single argument variant) binds the configuration to your calling bundle context. You might want to consider using the getConfiguration(String pid, String bundleLocation) variant to create a new configuration.
> 
> Regards
> Felix
> 
>> 
>> Am I misunderstanding what should happen? Or is my understanding correct, but I am for some reason not getting the correct result?
>> 
>> 
>> Thanks!
>> =David
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>> For additional commands, e-mail: users-help@felix.apache.org
>> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: [SCR] Obtaining component configuration

Posted by Felix Meschberger <fm...@adobe.com>.
Hi David

> Am 17.09.2015 um 11:29 schrieb David Leangen <os...@leangen.net>:
> 
> 
> Hi!
> 
> Using Felix SCR…

I think this is related to Felix Configuration Admin, though

> 
> I am trying to obtain a component’s properties object by:
> 
>  ConfigurationAdmin cm = {obtain the cm}
>  Configuration componentConfig = cm.getConfiguration( componentPid );
>  componentConfig.getProperties();
> 
> I can confirm that I am getting the correct Configuration object (when I add a property and update, it updates the component), however, I am getting a null result when I try to obtain the properties before doing an update, and an “incomplete” properties object after the update (containing only the service.pid property).

When calling getConfiguration for the first time for a given componentPid the configuration is newly created and there are no properties. Which is why you getProperties() returns null.

You have to first call update(Dictionary) to set the initial configuration. After that getProperties() will return a Dictionary with the values just set.

Calling update() (the no arg variant) just causes the configuration to be reloaded from persistence. Yet, for a new configuration which has never been updated with update(Dictionary) this is essentially a no-op.

Mind you though: Calling getConfiguration(String) (the single argument variant) binds the configuration to your calling bundle context. You might want to consider using the getConfiguration(String pid, String bundleLocation) variant to create a new configuration.

Regards
Felix

> 
> Am I misunderstanding what should happen? Or is my understanding correct, but I am for some reason not getting the correct result?
> 
> 
> Thanks!
> =David
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>