Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Equinox » [OSGi] Unique instance for each service request
[OSGi] Unique instance for each service request [message #117610] Thu, 18 September 2008 12:30 Go to next message
Matthias Treitler is currently offline Matthias TreitlerFriend
Messages: 117
Registered: July 2009
Senior Member
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 13:02 Go to previous message
Simon Archer is currently offline Simon ArcherFriend
Messages: 24
Registered: July 2009
Junior Member
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
>
Previous Topic:[p2]Plugins, updated with old update manager, not loaded properly in 3.4
Next Topic:Re: can the P2 dropins directory be used to try different releases of a plugin/feature ?
Goto Forum:
  


Current Time: Thu Apr 25 23:19:31 GMT 2024

Powered by FUDForum. Page generated in 0.03558 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top