Friday, October 23, 2009

Service Monitoring - OSGI

There are 2 approaches for doing this.

1. Class implementing Service Listener gets all service lifecycle Events .

public class PGServiceListener implements ServiceListener, BundleActivator {

public void start(BundleContext cntxt) throws Exception {


public void stop(BundleContext cntxt) throws Exception {
// TODO Auto-generated method stub


public void serviceChanged(ServiceEvent event) {
-à this is called for every service life cycle event


Here this class will be mentioned in the manifest file as a bundle Activator

2. Listening to the market Interface . Assuming that all the services implement a interface IService we can have the following listener which get all service related events.

<osgi:list id="listService"



<osgi:listener ref="serviceListener1" bind-method="bindService"



Looks like the second approach is better, as we get only 2 events, service register and unregister which we are interested in .It also gives all the properties of the service which will help us maintain other info like version.

No comments:

Free Domain Names @!