Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Equinox » DS & lazy loading of services
DS & lazy loading of services [message #503506] Mon, 14 December 2009 14:38 Go to next message
Helmut J. Haigermoser is currently offline Helmut J. Haigermoser
Messages: 6
Registered: July 2009
Junior Member
Ciao @ll Smile
Congratulations on the DS implementation within Eclipse, I find it easy to use and a big helper to avoid some standard code for every service! Smile

Here comes my question: Is it possible to have a service that gets started at the time the first client tries to use it?
Like, let's say I have a DS x.gui.Service providing a service for x.console.IService, and I want x.gui.Service to be first instantiated at the time a client actually needs to use the IService (BundleContext.getServiceReference("x.console.IService")), not at plug-in startup time? Right now I only see two flags, "start right away" (guess this forces a plug-in to load at startup) and "start once it's plug-in gets started", guess I want an additional "start once the service is needed"; kind of a dynamic/lazy approach...

Thanks for your time, I have a hunch that this already works and I just need to learn how Smile
Ciao, hh
Re: DS & lazy loading of services [message #503629 is a reply to message #503506] Mon, 14 December 2009 22:40 Go to previous messageGo to next message
Ali Naddaf is currently offline Ali Naddaf
Messages: 85
Registered: July 2009
Member
Hi Helmut.

If I am not mistaking, you are looking for the delayed components
(section 112.5.4 of the R4.2, for example). You can make a component
that provides a service either immediate or delayed. By default, DS
services are delayed unless you mark them as immediate in their xml
descriptor (if a component doesn't provide any services, then it is
enabled as soon as started).

If you were asking about something else, sorry for missing your question.

Ali.

Helmut J. Haigermoser wrote:
> Ciao @ll :)
> Congratulations on the DS implementation within Eclipse, I find it easy
> to use and a big helper to avoid some standard code for every service! :)
>
> Here comes my question: Is it possible to have a service that gets
> started at the time the first client tries to use it?
> Like, let's say I have a DS x.gui.Service providing a service for
> x.console.IService, and I want x.gui.Service to be first instantiated at
> the time a client actually needs to use the IService
> (BundleContext.getServiceReference("x.console.IService")), not at
> plug-in startup time? Right now I only see two flags, "start right away"
> (guess this forces a plug-in to load at startup) and "start once it's
> plug-in gets started", guess I want an additional "start once the
> service is needed"; kind of a dynamic/lazy approach...
>
> Thanks for your time, I have a hunch that this already works and I just
> need to learn how :) Ciao, hh
>
Re: DS & lazy loading of services [message #503659 is a reply to message #503629] Tue, 15 December 2009 09:15 Go to previous messageGo to next message
Helmut J. Haigermoser is currently offline Helmut J. Haigermoser
Messages: 6
Registered: July 2009
Junior Member
Ciao Ali Smile
I think that might be what I need, but this seems not to work within Eclipse.
Guess the question is whether or not Eclipse implements this part of the osgi spec, and if yes, how client code must look like to use it?
In my example I was trying to do just that, but my service is not instantiated when clients try to access it... Sad
TIA, Ciao, hh
P.S.: More info:
My service component lists these properties:
enabled="false" immediate="false" (enabled seems to mean "This service is enabled when started", immediate seems to mean "This service is immediately activated")
I set both values to false because I don't want the service to activate right away, maybe even starting the associated plug-in. Neither do I want the service to become available when the plug-in gets started.

Using these settings BundleContext.getServiceReference("x.console.IService") does not seem to cause my service impl to get instantated...
Re: DS & lazy loading of services [message #504139 is a reply to message #503659] Thu, 17 December 2009 12:13 Go to previous messageGo to next message
Helmut J. Haigermoser is currently offline Helmut J. Haigermoser
Messages: 6
Registered: July 2009
Junior Member
Re-hi everybody Smile
Hm, I'm still unableto use DS the way I want to Confused

Right now I'm ready to use an extension point, that way I know that I can decide when the extension is loaded (and the associated plug-in is started by that), but since extension points feel a bit more heavyweight I was really hoping to get this as a DS, can you guys again confirm the following is not possible:

plugin A defines a DS, interface "Interface"
plugin B defines an implementation for that interface: "Impl"

in plugin A I want to use the service, but with plugin B not having been started yet. I want the class "Impl" to be instantiated the moment I write "getService("Interface"), and plugin B should be started to make this happen if needed. If plugin B was already started, fine, but it should not be a prerequisite...

Sounds like a pretty standard use case, and seems to be covered by the osgi's "dynamic" specification of DS, so I'm wondering if I'm just doing this wrong, or setting the wrong property?

TIA,
Ciao, hh
Re: DS & lazy loading of services [message #504511 is a reply to message #504139] Mon, 21 December 2009 05:55 Go to previous messageGo to next message
Alain  is currently offline Alain
Messages: 115
Registered: July 2009
Senior Member
Hello,

You can use DS on your plugin B, so your service will be registered
without the need to start. And on your plugin A, use
bind(ServiceReference) which allow to bind your service without starting
it, then use locatService(String, ServiceReference) to get your service
instance (and activate it if needed)

Hope it help

Alain

On 12/17/09 7:13 PM, Helmut J. Haigermoser wrote:
> Re-hi everybody :)
> Hm, I'm still unableto use DS the way I want to :?
> Right now I'm ready to use an extension point, that way I know that I
> can decide when the extension is loaded (and the associated plug-in is
> started by that), but since extension points feel a bit more heavyweight
> I was really hoping to get this as a DS, can you guys again confirm the
> following is not possible:
>
> plugin A defines a DS, interface "Interface"
> plugin B defines an implementation for that interface: "Impl"
>
> in plugin A I want to use the service, but with plugin B not having been
> started yet. I want the class "Impl" to be instantiated the moment I
> write "getService("Interface"), and plugin B should be started to make
> this happen if needed. If plugin B was already started, fine, but it
> should not be a prerequisite...
>
> Sounds like a pretty standard use case, and seems to be covered by the
> osgi's "dynamic" specification of DS, so I'm wondering if I'm just doing
> this wrong, or setting the wrong property?
>
> TIA,
> Ciao, hh
Re: DS & lazy loading of services [message #504871 is a reply to message #504511] Wed, 23 December 2009 09:20 Go to previous message
Helmut J. Haigermoser is currently offline Helmut J. Haigermoser
Messages: 6
Registered: July 2009
Junior Member
Hey @ll Smile
Not sure why this would make a difference, but using a property in my service and looking up the service with a filter did the trick, the service now gets implemented (along with the plug-in B getting started) at first use, which is exactly what I needed.

Thanks for your help though! Smile
Ciao, hh
Previous Topic:- P2 - No action found for: org.eclipse.equinox.p2.touchpoint.eclipse.addRepository.
Next Topic:Changes about eclipse preference can't be saved
Goto Forum:
  


Current Time: Sat Oct 25 09:33:13 GMT 2014

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

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