You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by Martin Testrot <ma...@d-velop.de> on 2008/04/25 16:02:49 UTC

Configuration Admin + SCR

Hi,

 

I would like to implement a management bundle which displays the
properties defined by other bundles/SCR components.

 

To try this approach I wrote a simple bundle with one component and a
simple property as follows:

 

/*

* @scr.component

*

* @scr.service

*/

public class ComponentWithConf implements EmptyService{

 

            /** scr.property value="defaultvalue"*/

            private static final String MYPROP = "myprop";

 

            ...

}

 

The Management Bundle looks like this:

 

/*

* @scr.component

*/

public class ManagementComponent {

 

            /**

            * @scr.reference

            */

            private ConfigurationAdmin mConfigurationAdmin;

 

            proteced void activate (ComponentContext pContext){

                        Configuration[] lConfigurations =
mConfigurationAdmin.listConfigurations(null);

                        if (lConfigurations.length() == 0)
System.out.println ("No conf found!");

            }

}

 

The problem is, that I don't see any configurations from my
ManagementComponent. The above activate - method always prints "No conf
found!" on the console.

 

Am I missing something? Is this a bug?

 

Thanks for help,

 

Martin

 

P.S.: I'm using

org.apache.felix.configadmin 1.0.1

org.apache.felix.scr 1.0.0

maven-bundle-plugin 1.2.0

maven-scr-plugin 1.0.3


AW: Configuration Admin + SCR

Posted by Martin Testrot <ma...@d-velop.de>.
Hallo Felix,

thanks for your help. This explains the behaviour I observed.

Greetings,
Martin

-----Ursprüngliche Nachricht-----
Von: Felix Meschberger [mailto:fmeschbe@gmail.com] 
Gesendet: Freitag, 25. April 2008 19:52
An: users@felix.apache.org
Betreff: Re: Configuration Admin + SCR


Hi,

Your code looks perfectly right to me. The problem is, that you assume,
that the SCR is creating Configuration instances. This is not the case.

What happens here is, that when ComponentWithConf is activated, a
ManagedService is registered on behalf of the ComponentWithConf. If the
Configuration Admin Service is active and has a configuration, it is
sent to the ComponentWithConf. Otherwise no configuration is sent. What
the ComponentWithConf will receive in its activate method is actually
the default configuration properties as per the descriptor file created
from the @scr.* tags.

When the ManagementComponent is started, it just also asks the
ConfigurationAdmin for configurations. There are none at the moment, so
there is nothing to print.

Only if you have a management agent actually creating a Configuration
object through the ConfigurationAdmin, will the ManagementComponent see
the configuration and the ComponentWithConf reveive the configuration.

FYI: You might want to have a look at the Management Console we use over
in the Apache Sling project. This provides you with pretty much
something, you might be interested in. (And you might also be interested
that there are in fact plans to move this over here to the Felix
project).

Regards
Felix

Am Freitag, den 25.04.2008, 16:02 +0200 schrieb Martin Testrot:
> Hi,
> 
>  
> 
> I would like to implement a management bundle which displays the
> properties defined by other bundles/SCR components.
> 
>  
> 
> To try this approach I wrote a simple bundle with one component and a
> simple property as follows:
> 
>  
> 
> /*
> 
> * @scr.component
> 
> *
> 
> * @scr.service
> 
> */
> 
> public class ComponentWithConf implements EmptyService{
> 
>  
> 
>             /** scr.property value="defaultvalue"*/
> 
>             private static final String MYPROP = "myprop";
> 
>  
> 
>             ...
> 
> }
> 
>  
> 
> The Management Bundle looks like this:
> 
>  
> 
> /*
> 
> * @scr.component
> 
> */
> 
> public class ManagementComponent {
> 
>  
> 
>             /**
> 
>             * @scr.reference
> 
>             */
> 
>             private ConfigurationAdmin mConfigurationAdmin;
> 
>  
> 
>             proteced void activate (ComponentContext pContext){
> 
>                         Configuration[] lConfigurations =
> mConfigurationAdmin.listConfigurations(null);
> 
>                         if (lConfigurations.length() == 0)
> System.out.println ("No conf found!");
> 
>             }
> 
> }
> 
>  
> 
> The problem is, that I don't see any configurations from my
> ManagementComponent. The above activate - method always prints "No conf
> found!" on the console.
> 
>  
> 
> Am I missing something? Is this a bug?
> 
>  
> 
> Thanks for help,
> 
>  
> 
> Martin
> 
>  
> 
> P.S.: I'm using
> 
> org.apache.felix.configadmin 1.0.1
> 
> org.apache.felix.scr 1.0.0
> 
> maven-bundle-plugin 1.2.0
> 
> maven-scr-plugin 1.0.3
> 


---------------------------------------------------------------------
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: Configuration Admin + SCR

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

Your code looks perfectly right to me. The problem is, that you assume,
that the SCR is creating Configuration instances. This is not the case.

What happens here is, that when ComponentWithConf is activated, a
ManagedService is registered on behalf of the ComponentWithConf. If the
Configuration Admin Service is active and has a configuration, it is
sent to the ComponentWithConf. Otherwise no configuration is sent. What
the ComponentWithConf will receive in its activate method is actually
the default configuration properties as per the descriptor file created
from the @scr.* tags.

When the ManagementComponent is started, it just also asks the
ConfigurationAdmin for configurations. There are none at the moment, so
there is nothing to print.

Only if you have a management agent actually creating a Configuration
object through the ConfigurationAdmin, will the ManagementComponent see
the configuration and the ComponentWithConf reveive the configuration.

FYI: You might want to have a look at the Management Console we use over
in the Apache Sling project. This provides you with pretty much
something, you might be interested in. (And you might also be interested
that there are in fact plans to move this over here to the Felix
project).

Regards
Felix

Am Freitag, den 25.04.2008, 16:02 +0200 schrieb Martin Testrot:
> Hi,
> 
>  
> 
> I would like to implement a management bundle which displays the
> properties defined by other bundles/SCR components.
> 
>  
> 
> To try this approach I wrote a simple bundle with one component and a
> simple property as follows:
> 
>  
> 
> /*
> 
> * @scr.component
> 
> *
> 
> * @scr.service
> 
> */
> 
> public class ComponentWithConf implements EmptyService{
> 
>  
> 
>             /** scr.property value="defaultvalue"*/
> 
>             private static final String MYPROP = "myprop";
> 
>  
> 
>             ...
> 
> }
> 
>  
> 
> The Management Bundle looks like this:
> 
>  
> 
> /*
> 
> * @scr.component
> 
> */
> 
> public class ManagementComponent {
> 
>  
> 
>             /**
> 
>             * @scr.reference
> 
>             */
> 
>             private ConfigurationAdmin mConfigurationAdmin;
> 
>  
> 
>             proteced void activate (ComponentContext pContext){
> 
>                         Configuration[] lConfigurations =
> mConfigurationAdmin.listConfigurations(null);
> 
>                         if (lConfigurations.length() == 0)
> System.out.println ("No conf found!");
> 
>             }
> 
> }
> 
>  
> 
> The problem is, that I don't see any configurations from my
> ManagementComponent. The above activate - method always prints "No conf
> found!" on the console.
> 
>  
> 
> Am I missing something? Is this a bug?
> 
>  
> 
> Thanks for help,
> 
>  
> 
> Martin
> 
>  
> 
> P.S.: I'm using
> 
> org.apache.felix.configadmin 1.0.1
> 
> org.apache.felix.scr 1.0.0
> 
> maven-bundle-plugin 1.2.0
> 
> maven-scr-plugin 1.0.3
> 


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