felix-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alex Sviridov <ooo_satu...@mail.ru>
Subject OSGI: DS+CDI and component factories issues
Date Tue, 14 Jul 2015 04:48:36 GMT
I use apache felix +weld+pax. To work with DS I use annotations (@Service,@Component).  
What I need is to get new instance of declarative service every time when some consumer needs
this service + using CDI. 
And as I understand I can do it only using component factory. (Maybe scope=prototype can also
help - I couldn't find the answer and how to do it).

 I've read a lot of articles and I can't find the answer to 2 my questions.

1)If we use factories, why in service consumer we call factory (http://www.rpgnextgen.com/wiki/doku.php?id=component_factory
) and after that we get reference to service. I mean

    // get factory
    ComponentFactory factory = (ComponentFactory) context.getService(serviceReferences[0]);
    // get instance
    ComponentInstance instance = factory.newInstance(null);

2) Is there no way to set factory with certain interface and in service consumer call service
when osgi inside calls the factory?

    If in service consumer we call factory then why we mark service as component when de facto
factory is component?

The problem is that without factory I do @Inject @OsgiService (javase) or@OSGiService (javaee)
and I can use different filters and code is very clear. Using component factory I (as I understand)
loose this ability.

Please, help me.

-- 
Alex Sviridov
Mime
View raw message