-1

I have some little silly doubts in an OSGI concepts but they need to be clarified to have better understanding of concepts. Can anybody tell me what is the difference between OSGI Service and Component. What i know is that Service is like an interface file in java that can be used either by a different service or by a component. While component is like a particular implementation of the service.

Please let me know if i am wrong or suggest some link from where i can get the things nicely.

2 Answers2

3

The OSGi Core specification defines the service model which is a key part of the OSGi concept. A service is an object (instance) which implements a declared type (normally an interface). The OSGi framework provides the service layer which is a broker between service providers and service consumers.

DS introduced the concept of Service Components which are classes in a bundle which that are managed by the DS runtime (SCR). The components are described by XML in the bundle which is read by SCR. These components, once instantiated and if declared to be services, can be registered as services by SCR.

So components can be services (but they do not have to be) and they can use services.

BJ Hargrave
  • 9,324
  • 1
  • 19
  • 27
  • A service is an object (instance) which implements a declared type ... ?? didn't get the idea ?? Please explain it . It help me to clear my doubts – user2191593 Mar 22 '13 at 16:29
  • Is it mean it's an implementation class which implements the interface ... and all the objects of this class is service – user2191593 Mar 22 '13 at 16:36
1

OSGi evolved the concept of services, so that bundles could reduce their coupling with other bundles - ie. achieve loose coupling. The 'loosest' coupling comes from using dynamic services, where bundles that produce services are started dynamically as consumers register to consume those services. The dynamic services model went through several evolutions with OSGi, through service registration and event listening, Service Tracker, and finally Declarative Services.

With all but the last (Declarative Services), the service registration code is put in the bundle's Activator. With Declarative Services, the bundle that exposes a service is called a component and it's declared in a component.xml file that the framework understands - no need for activators. In the Eclipse IDE, you can use Declarative Services by right-clicking on a bundle and adding a 'Component Definition'. There's a really good book on the subject that takes you through the technology with tutorials:

OSGi and Equinox

Rich
  • 46
  • 3
  • according to you component is the bundle ?? ? – user2191593 Mar 22 '13 at 13:49
  • Yes. When using Declarative Services, and by creating the component.xml file, you are declaring the bundle as a component. Under DS, a component can export zero or more services and consume zero or more services so it can be a bundle that is either an exporter or consumer or both. – Rich Mar 22 '13 at 14:56
  • Like when we defined a scr component in java file than what does it mean ? Is it something different than the component bundle. what is the relationship if any ??? – user2191593 Mar 22 '13 at 16:22
  • A component is not a bundle. A bundle can declare zero or more components and each component can be declared to be a service. – BJ Hargrave Mar 22 '13 at 16:23
  • What do you mean by each component can be declared to be service ?? – user2191593 Mar 22 '13 at 16:25