There are 2 approaches for doing this.
1. Class implementing Service Listener gets all service lifecycle Events .
public class PGServiceListener implements ServiceListener, BundleActivator {
……..
@Override
public void start(BundleContext cntxt) throws Exception {
cntxt.addServiceListener(this);
}
@Override
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"
interface="com.partygaming.service.monitor.external.IService"
cardinality="0..N">
<osgi:listener ref="serviceListener1" bind-method="bindService"
unbind-method="unBindService"></osgi:listener>
</osgi:list>
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.
Friday, October 23, 2009
Service Monitoring - OSGI
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment