Introduction to OSGi services

OSGi services de-couple bundles that consume features or capabilities (consumer bundles) from bundles that provides those features or capabilities (provider bundles).

In an OSGi environment, bundles only expose the packages they want to expose to other bundles and bundles must declare what packages they import.

Consumer bundles can listen for services being registered of unregistered, or they can look up services as they need them. In InfoSphere® MDM, the Lookup method is often used to locate and invoke services when they are required.

Provider bundles register services into a service registry. A single bundle can provide many service. Multiple bundles can register and provide the same service, in which case, service implimentations can be decorated with properties to enable a consuming bundle to distinguish between different implementations of the same service.

OSGi services can come online when the providing bundles are loaded or started and go offline when the providing bundles are unloaded or stopped – all without affecting the consuming bundles. In InfoSphere MDM, OSGi services are used extensively. At its most basic an OSGi service consists of the following components:
service interface
Services are identified and located by their interfaces; in this context, interface means a Java™ interface or an abstract class.
service properties
Service properties are added to a service to further describe its capabilities or distinguish one implementation of the service from another.
service implementation
The service implementation is the Java class that implements the service interface and enables the capabilities provided by the service.