0

I have one doubt in understanding the term component and service in OSGI. I am using apache felix framework. I have read in the this link http://wiki.osgi.org/wiki/Declarative_Services#Providing_Services that components provide a service. But i didn't get that when component provides a service than what does interface does ? In my opinion interface is a service which is implemented by the component.

One more doubt is that if another bundle want to use the service of the other bundle than how it is done ? It uses the interface( service) or component(implementation class).

Please clear my doubts so that i can get better feel of the two term service and component and there relationship with scr notation.

user2091202
  • 33
  • 1
  • 5

1 Answers1

1

You're right that the names of things are somewhat unclear at times, there are also some minor differences in naming between Felix and Equinox.

In Declarative Services:

A Service in OSGi is an Object registered to the service registry. It can be a component, but it could be any object you like.

A Component is a concrete instance of an object, managed by the declarative service container. You need to supply an implementation class, which the container can use to instantiate the class.

Sometimes that is all you need: If all its references are present, this object will be instantiated, and the activation / deactivation methods will be called when applicable.

If you also want to register it as an OSGi service so other Components can use it, you need to:

  1. Implement the interface of the service you want to supply
  2. Indicate that you want to register it as a service with that interface

If you really want to you can register the implementation class as a provided service, but using an interface is better separation.

To use another service in a component, you need to reference it. On the OSGi wiki you mention that section seems to be missing. This blog explains it quite well.

regards, Frank

Frank Lee
  • 2,728
  • 19
  • 30