You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by Pochat Jerome <jp...@axway.com> on 2010/02/24 10:46:01 UTC

SCR and ConfigurationAdmin issue?

Hi

Using latest SCR and ConfigurationAdmin together, I have some troubles with service registration. When component does not provide any service, all seem to work properly. But when component provides a service, the ManagedService doesn't seems to be registered so component is not called when associated configuration is updated. Is it a known issue?

Here is code snippet is case I'm doing something wrong:

package x.y.z;
public interface Test { ... }

package x.y.z.impl;
public class TestImpl implements Test {
   protected void activate(ComponentContext context) { ... }
   protected void deactivate(ComponentContext context) { ... }
}

<component name="x.y.z.Test">
  <implementation class="x.y.z.impl.TestImpl" />
  <service>
    <provide interface="x.y.z.Test" />
  </service>
</component>



I also tried to declared both Test and ManagedService as provided interface:

<component name="x.y.z.Test">
  <implementation class="x.y.z.impl.TestImpl" />
  <service>
    <provide interface="x.y.z.Test" />
    <provide interface="org.osgi.service.cm.ManagedService" />
  </service>
</component>

It seems to work but it generates warn message during Configuration.update() "Service null is not a ManagedService". Does any body can explain this? Doesn't ManagedService interface supposed to be registered implicitly by SCR?

Thanks in advance

Re: RE : SCR and ConfigurationAdmin issue?

Posted by Felix Meschberger <fm...@gmail.com>.
Hi,

On 25.02.2010 10:31, Pochat Jerome wrote:
> Here is code that update component configuration:
> 
>     Configuration configuration = configurationAdmin.getConfiguration("x.y.z.Test");
>     Dictionary<String, Object> props = configuration.getProperties();
>     if (props == null)
>         props = new Hashtable<String, Object>();
>     props.put("foo", "bar");
>     configuration.update(props);
> 
> I was expecting to received updated configuration in component through "activate" method, but it's not invoked (until registering ManagedService interface as described in second part of my initial message).
> 
> Is this right way to update component configuration? What's wrong?

What should happen here is that any existing instance of the
"x.y.z.Test" is deactivated, a new instance is created and then
activated with the updated properties.

But, this happens asynchronously. That is after the return of the update
method, the task to update the component is just scheduled and it may
take a few ms to actually deactivate the component and create/activate a
new instance.

Regards
Felix

> 
> 
> -------- Message d'origine--------
> De: Felix Meschberger [mailto:fmeschbe@gmail.com]
> Date: mer. 24/02/2010 22:27
> À: users@felix.apache.org
> Objet : Re: SCR and ConfigurationAdmin issue?
>  
> Hi,
> 
> On 24.02.2010 09:46, Pochat Jerome wrote:
>> Hi
>>
>> Using latest SCR and ConfigurationAdmin together, I have some troubles with service registration. When component does not provide any service, all seem to work properly. But when component provides a service, the ManagedService doesn't seems to be registered so component is not called when associated configuration is updated. Is it a known issue?
> 
> This works as designed. SCR merges the configuration for the component
> with the Configuration Admin configuration and provides the result
> through the ComponentContext with the getProperties() method.
> 
> You will have to implement and activate method taking the
> ComponentContext or (as of DS 1.1) a Map representing the configuration.
> 
> The component should not implement and register a ManagedService (and
> not a ManagedServiceFactory) because getting the configuration is
> handled by the SCR.
> 
> Earlier releases of Felix SCR registered ManagedService services on
> behalf of the components, but this is not done any longer. Instead the
> ConfigurationAdminService is asked directly for properties.
> 
>>
>> Here is code snippet is case I'm doing something wrong:
>>
>> package x.y.z;
>> public interface Test { ... }
>>
>> package x.y.z.impl;
>> public class TestImpl implements Test {
>>    protected void activate(ComponentContext context) { ... }
>>    protected void deactivate(ComponentContext context) { ... }
>> }
>>
>> <component name="x.y.z.Test">
>>   <implementation class="x.y.z.impl.TestImpl" />
>>   <service>
>>     <provide interface="x.y.z.Test" />
>>   </service>
>> </component>
>>
> 
> In this example, the properties are provided through the
> ComponentContext. Check it out, it works ;-)
> 
>>
>>
>> I also tried to declared both Test and ManagedService as provided interface:
>>
>> <component name="x.y.z.Test">
>>   <implementation class="x.y.z.impl.TestImpl" />
>>   <service>
>>     <provide interface="x.y.z.Test" />
>>     <provide interface="org.osgi.service.cm.ManagedService" />
>>   </service>
>> </component>
>>
>> It seems to work but it generates warn message during Configuration.update() "Service null is not a ManagedService". Does any body can explain this? Doesn't ManagedService interface supposed to be registered implicitly by SCR?
> 
> You should not register a ManagedService for the PID of your component.
> 
> The message you see is probably related to the fact, that you instruct
> SCR to register the component as a ManagedService but the TestImpl class
> does not implement the ManagedService interface.
> 
> Regards
> Felix
> 
>>
>> Thanks in advance
>>
> 
> ---------------------------------------------------------------------
> 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 and ConfigurationAdmin issue?

Posted by Pochat Jerome <jp...@axway.com>.
Here is code that update component configuration:

    Configuration configuration = configurationAdmin.getConfiguration("x.y.z.Test");
    Dictionary<String, Object> props = configuration.getProperties();
    if (props == null)
        props = new Hashtable<String, Object>();
    props.put("foo", "bar");
    configuration.update(props);

I was expecting to received updated configuration in component through "activate" method, but it's not invoked (until registering ManagedService interface as described in second part of my initial message).

Is this right way to update component configuration? What's wrong?


-------- Message d'origine--------
De: Felix Meschberger [mailto:fmeschbe@gmail.com]
Date: mer. 24/02/2010 22:27
À: users@felix.apache.org
Objet : Re: SCR and ConfigurationAdmin issue?
 
Hi,

On 24.02.2010 09:46, Pochat Jerome wrote:
> Hi
> 
> Using latest SCR and ConfigurationAdmin together, I have some troubles with service registration. When component does not provide any service, all seem to work properly. But when component provides a service, the ManagedService doesn't seems to be registered so component is not called when associated configuration is updated. Is it a known issue?

This works as designed. SCR merges the configuration for the component
with the Configuration Admin configuration and provides the result
through the ComponentContext with the getProperties() method.

You will have to implement and activate method taking the
ComponentContext or (as of DS 1.1) a Map representing the configuration.

The component should not implement and register a ManagedService (and
not a ManagedServiceFactory) because getting the configuration is
handled by the SCR.

Earlier releases of Felix SCR registered ManagedService services on
behalf of the components, but this is not done any longer. Instead the
ConfigurationAdminService is asked directly for properties.

> 
> Here is code snippet is case I'm doing something wrong:
> 
> package x.y.z;
> public interface Test { ... }
> 
> package x.y.z.impl;
> public class TestImpl implements Test {
>    protected void activate(ComponentContext context) { ... }
>    protected void deactivate(ComponentContext context) { ... }
> }
> 
> <component name="x.y.z.Test">
>   <implementation class="x.y.z.impl.TestImpl" />
>   <service>
>     <provide interface="x.y.z.Test" />
>   </service>
> </component>
> 

In this example, the properties are provided through the
ComponentContext. Check it out, it works ;-)

> 
> 
> I also tried to declared both Test and ManagedService as provided interface:
> 
> <component name="x.y.z.Test">
>   <implementation class="x.y.z.impl.TestImpl" />
>   <service>
>     <provide interface="x.y.z.Test" />
>     <provide interface="org.osgi.service.cm.ManagedService" />
>   </service>
> </component>
> 
> It seems to work but it generates warn message during Configuration.update() "Service null is not a ManagedService". Does any body can explain this? Doesn't ManagedService interface supposed to be registered implicitly by SCR?

You should not register a ManagedService for the PID of your component.

The message you see is probably related to the fact, that you instruct
SCR to register the component as a ManagedService but the TestImpl class
does not implement the ManagedService interface.

Regards
Felix

> 
> Thanks in advance
> 

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



Re: SCR and ConfigurationAdmin issue?

Posted by Felix Meschberger <fm...@gmail.com>.
Hi,

On 24.02.2010 09:46, Pochat Jerome wrote:
> Hi
> 
> Using latest SCR and ConfigurationAdmin together, I have some troubles with service registration. When component does not provide any service, all seem to work properly. But when component provides a service, the ManagedService doesn't seems to be registered so component is not called when associated configuration is updated. Is it a known issue?

This works as designed. SCR merges the configuration for the component
with the Configuration Admin configuration and provides the result
through the ComponentContext with the getProperties() method.

You will have to implement and activate method taking the
ComponentContext or (as of DS 1.1) a Map representing the configuration.

The component should not implement and register a ManagedService (and
not a ManagedServiceFactory) because getting the configuration is
handled by the SCR.

Earlier releases of Felix SCR registered ManagedService services on
behalf of the components, but this is not done any longer. Instead the
ConfigurationAdminService is asked directly for properties.

> 
> Here is code snippet is case I'm doing something wrong:
> 
> package x.y.z;
> public interface Test { ... }
> 
> package x.y.z.impl;
> public class TestImpl implements Test {
>    protected void activate(ComponentContext context) { ... }
>    protected void deactivate(ComponentContext context) { ... }
> }
> 
> <component name="x.y.z.Test">
>   <implementation class="x.y.z.impl.TestImpl" />
>   <service>
>     <provide interface="x.y.z.Test" />
>   </service>
> </component>
> 

In this example, the properties are provided through the
ComponentContext. Check it out, it works ;-)

> 
> 
> I also tried to declared both Test and ManagedService as provided interface:
> 
> <component name="x.y.z.Test">
>   <implementation class="x.y.z.impl.TestImpl" />
>   <service>
>     <provide interface="x.y.z.Test" />
>     <provide interface="org.osgi.service.cm.ManagedService" />
>   </service>
> </component>
> 
> It seems to work but it generates warn message during Configuration.update() "Service null is not a ManagedService". Does any body can explain this? Doesn't ManagedService interface supposed to be registered implicitly by SCR?

You should not register a ManagedService for the PID of your component.

The message you see is probably related to the fact, that you instruct
SCR to register the component as a ManagedService but the TestImpl class
does not implement the ManagedService interface.

Regards
Felix

> 
> Thanks in advance
> 

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