Hi, Am Montag, den 09.06.2008, 13:55 -0700 schrieb jaredmac: > I'm using Felix/SCR for a GUI application. GUI clients want to know what > services have registered with a certain interface. However, I get > non-deterministic behavior when GUI clients make this query (which occurs > right after bundles have been started): i.e., sometimes, there will be 2 > services registered, other times 3 or 4. With some debugging, I can see that > ServiceEvents are being fired asynchronously as these services are > registered, and that occurs at the same time that the clients make their > query on a separate thread, leading to the non-determinism.
Well, this non-determinstism is by design. OSGi frameworks are dynamic where everything can come and go virtually at any time. This is very important and powerful. The drawback - if you will - of this is, that you have to be aware of this situation, which may be very uncommon at first sight. If you get used to it, it is like heaven ;-) Now, for your situation, the problem is, that as a service consumer you cannot tell, at which time "all" services are registered, because there is no notion of "all" services. > > I get the impression reading the forum that my GUI clients should instead be > coded to react to/listen for new services coming on-line, rather than making > a query up-front... Yes. This is a good thing and probably the only thing you can do. > but I was hoping to insulate my GUI code from this, > because the GUI, as it currently stands, should be static once everything is > initialized. Using SCR you can in fact isolate your clients from OSGi specific code: In that you declare a binding method (don't forget the unbind method !) the SCR will call the component whenever a new service arives (and goes away). So the component -- presumably the client ? -- will always be up to date and have the current list of services available. > > So what I'd like is the following: > > 1. Bundles installed, started > 2. Services registered > 3. Clients ask for list of services, get deterministic answer Clients always get a deterministic answer: The services registered at the time of the call. The non-determinism comes from the fact, that the services are registered asynchronously, which is by design and good. Hope this helps. Regards Felix --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

