Friday, December 11, 2009

Introduction to OSGi Services

Recently I'm doing some work at WSO2 with OSGi Services and I'm reading some OSGi books which is very interesting for a typical Java developer. So I thought of blogging little by little about what I'm learning by reading about OSGi since there are little number of resources to read about OSGi in the internet.

In simple OSGi Service is again a service which we expose using a Java class as we do in a typical Web Service, but here we have our consumers run in the same JVM and message parsing happens through the same JVM, so no remote calls at all. With OSGi services it contains it's own way of handling clients and it's own way of handling consumers of the services like we have in Web Services. In web services we should have a framework to process web service calls and with OSGi services we have to have the an OSGi framework running to consume and expose OSGi services.
We can write a simple service interface first and implement it in a class and register the service.You can register different number of services by creating different implementation of the same interface. In OSGi we keep all the service information in a Service Registry and when someone wants to consume a given service it actually talk to the Service Broker which is aware of the OSGi registry. Through the service Broker it connect with the service and give a reference of the service object, so that we can call appropriate methods in the service class. Instead of just consuming service operations OSGi services provide set of features like monitoring service registration and unregistration using different approaches. So we can do certain things while a particular service register and while a service is unregistering. I will be writing more on how to register a service, consume a service and how to track service life-cycle, how to use service properties to select required and how to use filters with OSGi Services. I hope to write on those things in few blog posts rather writing all together.

No comments :