[OSGi] Unique instance for each service request [message #117610] |
Thu, 18 September 2008 08:30  |
Eclipse User |
|
|
|
Hello!
I have the following use case: There are two bundles, where one provides
an OSGi service and the other bundle uses this service.
Now my special requirement: Every time the bundle requests this provided
service (registered at the other bundle) an unique instance of this
service object should be created (like the Factory pattern)!
Firstly I thought I can make use of the ServiceFactory interface, but this
one creates only unique instances for each bundle but not for each request
within the same bundle!
What is the best practice in my case?!? Is there no support provided by
OSGi?! Do I have to register my own ServiceFactory implementation that can
create domain "service" object instances?
Best regards,
matthias
|
|
|
Re: [OSGi] Unique instance for each service request [message #117623 is a reply to message #117610] |
Thu, 18 September 2008 09:02  |
Eclipse User |
|
|
|
Matthias
I believe that you are correct about using an OSGi ServiceFactory: it's
one instance per requesting bundle, not per service request.
Registering your own service that provides creation APIs is certainly
one approach.
Another approach worth considering is using a Factory Component as
described by OSGi's Declarative Services. Take a look in section 12.2.4
of the OSGi compendium, it's titled "Factory Component". Using a
Factory Component is interesting in that it allows the requester to ask
for ask many parameterized instances as they wish. I suggest you take a
look.
I hope this helps,
Simon
Matthias Treitler wrote:
> Hello!
> I have the following use case: There are two bundles, where one provides
> an OSGi service and the other bundle uses this service. Now my special
> requirement: Every time the bundle requests this provided service
> (registered at the other bundle) an unique instance of this service
> object should be created (like the Factory pattern)! Firstly I thought I
> can make use of the ServiceFactory interface, but this one creates only
> unique instances for each bundle but not for each request within the
> same bundle!
> What is the best practice in my case?!? Is there no support provided by
> OSGi?! Do I have to register my own ServiceFactory implementation that
> can create domain "service" object instances?
>
> Best regards,
> matthias
>
|
|
|
Powered by
FUDForum. Page generated in 0.05030 seconds