getting started with osgi, i wonder what's the conceptual diffence between bundles and components. And when to use which of them. Any pointers are welcome.
EDIT:
Components and Bundles provide different interfaces and therefore they are probably not interchangeable
Best Answer
A component is:
In short:
A bundle can have only one activator (needing a
BundleContext
), and can have as many active components as you want.That means you may end up trying to fit in one activator several loosely-related concerns into a single class.
That is why it may be easier to manage those components by Declarative Services, through the SCR (the "Service Component Runtime" which is an "extender bundle" implementing the new and improved OSGi R4.2 DS - Declarative Service - specification).
This is especially true since OSGi 4.2 because it is now much easier to write DS components as POJOs: the
activate
anddeactivate
methods are no longer required to take aComponentContext
parameter. See also Lazy Declarative Service.Note:
It can help to replace those terms in the context of OSGi and look at "how we got there" (excellent blog post by Neil Bartlett)
Here are some relevant extracts, where the "modules" end up being the OSGi Bundles (managing Components which declare Services):
Module Separation
Module Access level
Granularity of Exports and Imports
Package Wiring
Versions
Packaging Modules and Metadata
Late Binding