Reputation: 7106
The OSGi enterprise specification defines two ways of tracking: by service or by bundle.
What are the differences between these two ways? In which cases, one way should be used over another?
Thanks
Upvotes: 0
Views: 503
Reputation: 662
To put it very simply: The bundle is the jar. You can track whether it is installed, successfully started, not yet started etc.
A bundle can publish zero or more services. A service in OSGi terms is the live java object which provides you methods for doing something. Even if the bundle is there, its services could have disappeared (e.g. because the bundle is stopped; or is installed but not yet started). Even if the bundle is in the ACTIVE state, it could still be waiting for some condition in order to provide its services - it depends fully on the bundle decision when it registers and unregisters its services.
In the most typical case your code works with services - e.g. you get the LogService and call its log() method. So in 99% of the cases you should be interested in the ServiceListener (or, even better, use the ServiceTracker instead, it does the same, but takes care of some typical synchronization pitfalls for you).
Hope this helps :)
Upvotes: 0
Reputation: 2182
Depends on what you are willing to track.
The BundleTracker tracks bundles, see:
And the ServiceTracker tracks service instances, see:
So obviously if you are interested in what happens with bundles, you use the BundleTracker. And if you are interested in service instances, you use the ServiceTracker.
Upvotes: 4