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:[email protected]]
Date: mer. 24/02/2010 22:27
À: [email protected]
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: [email protected]
For additional commands, e-mail: [email protected]


Reply via email to