You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by lbu <lb...@gmail.com> on 2015/04/17 17:40:52 UTC

Declarative Services with Karaf

All,

I'm learning Declarative Services so I'm "upgrading" an application based on
Karaf and Blueprint to DS and I'm having troubles understanding how to
achieve the same or similar behavior:

I have a bundle which contains a service that is supposed to be instantiated
multiple time with setup and with blueprint I do so by hot-deploying a
number of blueprint file in xml, what I'd like to do with DS is creating a
service for each configuration in ${karaf.home}/etc that matched a "prefix"
like my.service-instance1, my.service-instance2, etc. I had a look at DS
Component Factory but I do not know if it is the right option.

Do you think that my expected behavior can be implemented with DS ?  

Best regards,
Luca




--
View this message in context: http://karaf.922171.n3.nabble.com/Declarative-Services-with-Karaf-tp4039768.html
Sent from the Karaf - User mailing list archive at Nabble.com.

Re: Declarative Services with Karaf

Posted by lbu <lb...@gmail.com>.
It was much simpler than I thought, thank you guys



--
View this message in context: http://karaf.922171.n3.nabble.com/Declarative-Services-with-Karaf-tp4039768p4039814.html
Sent from the Karaf - User mailing list archive at Nabble.com.

Re: Declarative Services with Karaf

Posted by David Jencks <da...@yahoo.com>.
You can definitely do this with config admin.  Config admin and ComponentFactory don't mix very well.  There is an obsolete abuse of component factory in felix DS, I think from before the interactions between DS and CA were specced, that lets you use a factory component with factory configurations.  Don't use it :-)

Otherwise, how would a factory component help?

thanks
david jencks

On Apr 17, 2015, at 12:32 PM, Milen Dyankov <mi...@gmail.com> wrote:

> If I understand your question correctly, you can do this with ConfigAdmin. 
> You can use either ComponentFactory or use "simple" component and provide the factory PID in the MetaType (http://www.aqute.biz/Bnd/MetaType). 
> In both cases you can have multiple instances of the same service by creating multiple configuration files of named "<factoryPID>-anything_you_like.cfg". I'm not sure if the naming pattern is something you can configure in FileInstall or not.
> 
> Best,
> Milen     
> 
> On Fri, Apr 17, 2015 at 5:40 PM, lbu <lb...@gmail.com> wrote:
> All,
> 
> I'm learning Declarative Services so I'm "upgrading" an application based on
> Karaf and Blueprint to DS and I'm having troubles understanding how to
> achieve the same or similar behavior:
> 
> I have a bundle which contains a service that is supposed to be instantiated
> multiple time with setup and with blueprint I do so by hot-deploying a
> number of blueprint file in xml, what I'd like to do with DS is creating a
> service for each configuration in ${karaf.home}/etc that matched a "prefix"
> like my.service-instance1, my.service-instance2, etc. I had a look at DS
> Component Factory but I do not know if it is the right option.
> 
> Do you think that my expected behavior can be implemented with DS ?
> 
> Best regards,
> Luca
> 
> 
> 
> 
> --
> View this message in context: http://karaf.922171.n3.nabble.com/Declarative-Services-with-Karaf-tp4039768.html
> Sent from the Karaf - User mailing list archive at Nabble.com.
> 
> 
> 
> -- 
> http://about.me/milen


Re: Declarative Services with Karaf

Posted by Milen Dyankov <mi...@gmail.com>.
If I understand your question correctly, you can do this with ConfigAdmin.
You can use either ComponentFactory or use "simple" component and provide
the factory PID in the MetaType (http://www.aqute.biz/Bnd/MetaType).
In both cases you can have multiple instances of the same service by
creating multiple configuration files of named
"<factoryPID>-anything_you_like.cfg". I'm not sure if the naming pattern is
something you can configure in FileInstall or not.

Best,
Milen

On Fri, Apr 17, 2015 at 5:40 PM, lbu <lb...@gmail.com> wrote:

> All,
>
> I'm learning Declarative Services so I'm "upgrading" an application based
> on
> Karaf and Blueprint to DS and I'm having troubles understanding how to
> achieve the same or similar behavior:
>
> I have a bundle which contains a service that is supposed to be
> instantiated
> multiple time with setup and with blueprint I do so by hot-deploying a
> number of blueprint file in xml, what I'd like to do with DS is creating a
> service for each configuration in ${karaf.home}/etc that matched a "prefix"
> like my.service-instance1, my.service-instance2, etc. I had a look at DS
> Component Factory but I do not know if it is the right option.
>
> Do you think that my expected behavior can be implemented with DS ?
>
> Best regards,
> Luca
>
>
>
>
> --
> View this message in context:
> http://karaf.922171.n3.nabble.com/Declarative-Services-with-Karaf-tp4039768.html
> Sent from the Karaf - User mailing list archive at Nabble.com.
>



-- 
http://about.me/milen

Re: Declarative Services with Karaf

Posted by David Jencks <da...@yahoo.com>.
Definitely.

I'm not sure it's explained very well anywhere, but what you probably want is factory configurations, not factory components (which are nearly useless as described by the spec).  I strongly recommend setting up metatype to document what the configuration your DS component expects should look like.  In the metatype designate, specify factory-pid rather than pid.  Then create multiple configurations using this factory pid.  Each one will result in a separate instance of your DS component, using the properties you specified in the factory configuration.  The metatype is not essential but IMO really helps document what you are doing.  I don't know what support karaf has for metatype.

I'm not sure how to create the factory configurations in karaf, I use a very different (proprietary) framework for managing configurations.  Your description of what you are doing sounds vaguely familiar so it might be the correct way.

If you use felix ds trunk and bnd master you can use some really nifty new ds 1.3/metatype 1.3 features where the configuration is delivered to your DS component as an annotation  instance, and you can annotation the annotation to generate the metatype.

Factory components mean that you need to create each instance of your DS component in code by calling componentInstance.newInstance(props).  This is not very declarative any longer.  The spec lifecycle for these things makes them almost useless.  In fellx ds trunk you can specify per-component a flag that makes the iifecycle act just like a component created from a CA Configuration.  However, you almost certainly just want plain DS components with factory configurations.

I very very strongly recommend setting the configuration-policy to REQUIRE.  Factory configurations with OPTIONAL (the default) act really strangely and in my experience create problems that no one can figure out the cause of.

hope this helps….. I follow the felix lists a little more than this one in case you get stuck and I don't seem to be replying.

david jencks

On Apr 17, 2015, at 11:40 AM, lbu <lb...@gmail.com> wrote:

> All,
> 
> I'm learning Declarative Services so I'm "upgrading" an application based on
> Karaf and Blueprint to DS and I'm having troubles understanding how to
> achieve the same or similar behavior:
> 
> I have a bundle which contains a service that is supposed to be instantiated
> multiple time with setup and with blueprint I do so by hot-deploying a
> number of blueprint file in xml, what I'd like to do with DS is creating a
> service for each configuration in ${karaf.home}/etc that matched a "prefix"
> like my.service-instance1, my.service-instance2, etc. I had a look at DS
> Component Factory but I do not know if it is the right option.
> 
> Do you think that my expected behavior can be implemented with DS ?  
> 
> Best regards,
> Luca
> 
> 
> 
> 
> --
> View this message in context: http://karaf.922171.n3.nabble.com/Declarative-Services-with-Karaf-tp4039768.html
> Sent from the Karaf - User mailing list archive at Nabble.com.