Tuesday, March 4, 2014

OSGi Service

A service in OSGi is a java object in a bundle.  The service is listed in the OSGi service registry for other services to use.  The service registry allow search for service and send notification to services when a dependent service state changed.

The recommended practice for OSGi service is to comprise a Java interface and its accompanied implementing class.

When a bundle enters ACTIVE state, the service is activated by RegiesterService() call in the start() method of the activator .  It will also search for services that it depends on.  Services can rely on the OSGi framework's listener method to obtain notification when the dependent service undergo state changes.

The strength of OSGi is that service can be upgraded without the need to restarting the JVM or other services that it interacts with.  The trick is the use of Interface and the implementing classes are packaged as 2 separate bundle.  The interacting class work with the interface bundle that never changes.  OSGi registry will ensure all consuming bundle to get a reference to the updated service the next time it is accessed.

If the interface and the implementing classes are packaged in the same bundle, update to the bundle would requires uninstalling and reinstalling the bundle and all other bundles in the dependency hierarchy.


No comments: