2.8 The OSGi Framework
The modularity mechanisms described previously are largely implemented by the OSGi Framework. As such, an OSGi application is a collection of one or more bundles executing in an OSGi framework. The framework takes care of all the dependency resolution, class loading, service registrations, and event management.
The framework is reified in a running system as the System Bundle. Representing the OSGi framework as a bundle allows us to view the entire platform consistently as a collection of collaborating bundles. While the System Bundle is clearly special, it contains a manifest, exports packages, provides and consumes services, and broadcasts and listens to events like any other bundle.
The System Bundle differs from other bundles in that its lifecycle cannot be managed. It is started automatically when the framework is started and continues in the active state until the framework is stopped. Stopping the System Bundle causes the framework to shut down. Similarly, the System Bundle cannot be uninstalled while running, since doing so would cause the framework to terminate.
The other bundles in an OSGi system are installed into the framework and started as needed. The set of installed bundles in a framework is persisted from run to run—when the framework is shut down and relaunched, the same set of bundles is present and started in the new framework. As such, bundles need to be installed and started only once.
Interestingly, the framework specification does not say how the framework itself is started or how the initial set of bundles is installed. In general it is envisioned that there is an external management agent installing and uninstalling, and starting and stopping, bundles. This may be a central service provider, systems integrator, provisioning agent, or the end user. This approach is powerful, as it makes the framework equally applicable in a wide range of scenarios.
The framework also supplies some rudimentary data management facilities. Each bundle is given its own data area to use as required. The data written in this area is persisted for as long as the bundle is installed in the framework.