Thanks again David, your (and Neil's) explanation help me to understand this concept much better now.

Interesting, I always thought that when declaring a component as Singleton we would have only one component and one instance of its service. but with the CM combination it can be very flexible...

and now I figured it out that in order to accomplish my task, having the activate method called as soon as the configuration factory pid is registered, what I had to do was: configurationPolicy = ConfigurationPolicy.REQUIRE,
        scope = ServiceScope.SINGLETON, immediate = true.

best regards,

Cristiano

On 27/06/2016 19:55, David Jencks wrote:
I’m not sure I’m receiving all your replies….

Most of the things you can specify for a DS component are completely 
independent, which makes it very powerful, but there are a couple that aren’t 
and that can be confusing.

It’s unusual to need to specify enabled=false. I don’t think I ever have.  It 
might be useful if some other component needs to set up an environment without 
which the disabled component doesn’t make sense.

Configuration policy and scope are independent.  Configuration policy is also 
somewhat confusing since whether you get one instance or many is determined by 
config admin, not DS.

For instance if you are using a factory pid in config admin, you can get as 
many component configurations as you want, one for each configuration.  For 
each of those, the scope determines how many instances the configuration might 
have.  Singleton scope means you get at most one, and all requestors get the 
same service instance.  This is the only scope that is compatible with 
immediate.  Bundle scope means all requestors from the same bundle get the same 
instance, and requestors from different bundles get different instances.  
Prototype scope means if you use the ServiceObjects interface you can get as 
many instances as you want.

There’s also stuff you can now do with multiple pids but maybe the above is 
enough for now….

hope this helps
david jencks

On Jun 27, 2016, at 3:32 PM, Cristiano Gavião <[email protected]> wrote:

Sorry, my mistake...

only now I understood what you have said about enable=true be the default 
value... :-[

On 27/06/2016 19:16, Cristiano Gavião wrote:

On 27/06/2016 18:48, David Jencks wrote:
You’ve specified prototype scope, so there is never going to be “ONE” canonical 
instance.  You need something to request the service from the service reference 
or from the ServiceObjects interface from the service reference.

With the default scope, you aren’t going to get an instance created without a 
user either unless you specify immediate=true as well.
if I understood the spec right, when I use immediate=true then I get a 
Singleton scope, right?

Would a component with scope singleton use ConfigurationPolicy.REQUIRE ?

I generally don’t specify enabled=true since that is the default value.
then you let your components as enabled=false and then will use a master 
component to enable the others ?

david jencks

On Jun 27, 2016, at 2:42 PM, Cristiano Gavião <[email protected]> wrote:

Hello,

I'm facing a situation that I'm not understanding. I'm using 
org.apache.felix.scr 2.0.2.
I've set a component with this annotation:

   @Component(enabled = true, configurationPolicy =
   ConfigurationPolicy.REQUIRE,
            scope = ServiceScope.PROTOTYPE, service =
   FixedControllerService.class,
            configurationPid = {SERVICE_FACTORY_PID_CONTROLLER})

   <scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.3.0";
   name="com.c4biz.feast.ComponentControllerServiceProvider"
   configuration-policy="require" enabled="true" activate="activate"
   deactivate="deactivate" modified="modified"
   configuration-pid="fixed.controller">
      <implementation
class="com.c4biz.feast.ComponentControllerServiceProvider"/>
      <service scope="prototype">
        <provide interface="com.c4biz.feast.FixedControllerService"/>
      </service>
   </scr:component>

In this component class I have a method (activate()) tagged with @Activate 
annotation. And there are any reference bind being used for now.

 From another bundle I'm creating a configuration using factoryPID = 
SERVICE_FACTORY_PID_CONTROLLER.
Interesting is that the service are being created and with in a proper 
autogenerated PID and passed properties. At least I can see it when listing the 
services using gogo console.

also scr:list tells me that the component is enabled and satisfied.

What I'm not understanding is that the activate method is not being called...

could someone explain me what am I missing here?

thanks,

Cristiano
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] 
<mailto:[email protected]>
For additional commands, e-mail: [email protected] 
<mailto:[email protected]>


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to