Monday, March 3, 2014

OSGi Bundles

A bundle is a group of Java classes and a manifest file packaged in JAR format.  The MANIFAST.MF file is a text file that describe the bundle such as the version, the external packages that the bundle depends on, the package that the bundle exposed for other bundle to use and the activator class that will work with OSGi framework's life-cycle layer to manage the bundle.  OSGi run time assigns a class loader to each bundle.

A bundle has 6 states in its life cycle:
(1) Install - the bundle is validated
(2) Resolved - the bundle dependencies are resolved
(3) Starting - the bundle is in transition to the active state
(4) Active - the bundle is loaded and running
(5) Stopping - the bundle is being stopped
(6) Uninstall - the bundle is removed from the registry

Events are generated when a bundle moves from state to state.  Events can be caught by other bundles so that they can react (e.g. stop when the dependent bundle is stopped).

The strength of OSGi bundle is that it can be updated (replaced with a new version) dynamically without the need to stop the other bundles that depends on it.

No comments: