user3030761
user3030761

Reputation: 35

OSGi Bundle Installation Bootstrapping

I am reading "OGSi in Action" where in an interesting comment has been made :

"The module layer uses the metadata in bundles to make sure all their dependencies are satisfied before they can be used. This symbiotic relationship creates a chicken-and-egg situation when you want to use your bundles; to use a bundle you have to install it, but to install a bundle you must have a bundle context, which are only given to bundles."

The book goes to great length in explaining bundle dependency resolution , but the "chicken and egg" scenario described above hasnt really been explored further. To install a bundle , BundleContext is needed, which is only provided to bundles. So who created the first "bootstrapping" bundle ? Is this contained in the "shells" that are provided (using packageAdmin?) ? PackageAdmin has Bundle getBundle(Class clazz);

and Bundle can provide the BundleContext, but the bundle has to be installed first ... and so on !! How does this work ?

Upvotes: 0

Views: 106

Answers (2)

BJ Hargrave
BJ Hargrave

Reputation: 9384

See the Framework Launching API which provides the launcher with access to the system bundle's Bundle Context to install the "first" bundles.

Upvotes: 1

Balazs Zsoldos
Balazs Zsoldos

Reputation: 6046

From the javadoc of Bundle.getBundleContext():

If this bundle is not in the STARTING, ACTIVE, or STOPPING states or this bundle is a fragment bundle, then this bundle has no valid BundleContext. This method will return null if this bundle has no valid BundleContext.

I do not know what the writer of the book thought about. If you install a bundle programmatically, you install it via the bundle context of other bundle.

With all my respect, I think this paragraph is wrong. This "chicken and egg" philosophical question could be raised in case of the system bundle. However, I do not think that answering the unnecessary question would give a better understanding for the reader, who wants to get started with OSGi.

Upvotes: 0

Related Questions