I made a change in the blogger configuration to ease the later work when blogging. It is possible that older entries are not correctly formatted.

Monday 3 May 2010

OSGi

OSGi (used to be "Open Services Gateway initiative") is a standard to define a software platform infrastructure for java. The goal is to have the infrastructure to deploy modularised applications and services with a comnponent model (called Bundles or services). The components can be managed using a service registry. They can be loaded, started and stopped.

The OSGi standard uses metadata found in the Jar file Manifests, in order to load the bundles. In particular, the manifests specifies the classes exported and imported by the bundle. In that way, it is possible to use, or hide conflicting classes in a bundle and not export it. Other bundles may use the classes exported by other bundles.

Bundles

Bundles are jar files with a corresponding entries in the manifest. The following example shows the manifest of a bundle requiring the package org.eclipse.ui.

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: My Yellow World Example
Bundle-SymbolicName: de.desprofundis.example; singleton:=true
Bundle-Version: 1.0.0
Bundle-Activator: de.desprofundis.example.Activator
Require-Bundle: org.eclipse.ui,
  org.eclipse.core.runtime
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.6

Note the "Require-Bundle", entry which lists the packages which are required by this bundle. The OSGi container is responsible for checking whether the dependencies are satisfied. Another important information is also here the Bundle-Activator, which is the class in charge of the activation of the bundle (as well as its shutting down when needed.

Services

In addition to the dependency management and version hiding, the OSGi framework provides also a registry for services. Moreover, services can be injected in to some other bundle. A tutorial by Lars Vogel presents their use succintly.