Why should I prefer OSGi Services over exported packages?

Posted by Jens on Stack Overflow See other posts from Stack Overflow or by Jens
Published on 2010-05-05T20:05:53Z Indexed on 2010/05/05 20:08 UTC
Read the original article Hit count: 150

Filed under:
|
|

Hi,

I am trying to get my head around OSGi Services. The main question I keep asking myself is: What's the benefit of using services instead of working with bundles and their exported packages?

As far as I know it seems the concept of Late Binding has something to do with it. Bundle dependencies are wired together at bundle start, so they are pretty fixed I guess. But with services it seems to be almost the same. A bundle starts and registers services or binds to services. Of course services can come and go whenever they want and you have to keep track of these chances. But the core idea doesn't seem that different to me.

Another aspect to this seems to be that services are more flexible. There could be many implementations for one specific Interface. On the other hand there can be a lot of different implementations for a specific exported package too.

In another text I read that the disadvantage of using exported packages is that they make the application more fragile than services. The author wrote that if you remove one bundle from the dependency graph other dependencies would no longer be met, thus possibly causing a domino effect on the whole graph. But couldn't the same happen if a service would go offline? To me it looks like service dependencies are no better than bundle dependencies.

So far I could not find a blog post, book or presentation that could clearly describe why services are better than just exposing functionality by exporting and importing packages.

To sum my questions up:

What are the key benefits of using OSGi Services that make them superior to exporting and importing packages?

© Stack Overflow or respective owner

Related posts about osgi

Related posts about Services