Hi All,
I read the below in one of the forum.
What is a Service?
An OSGi service is a java object instance, registered into an OSGi framework with a set of properties. Any java object can be registered as a service, but typically it implements a well-known interface.
The client of a service is always an OSGi bundle, i.e. a piece of java code possible to start via the BundleActivator interface.
Each bundle may register zero or more services. Each bundle may also use zero or more services. There exists no limit on the number of services, more than the ones given by memory limits or java security permissions.
My doubts are as below :
- "The client of a service is always an OSGi bundle, i.e. a piece of java code possible to start via the BundleActivator interface.Each bundle may register zero or more services".
What exactly does the above statement imply.
a]If I create a bundle, a service for it is automatically created?
b] If a start the bundle, the service is invoked.
Any detailed explanation on this will be helpful.
Solved! Go to Solution.
Views
Replies
Total Likes
Hi,
Thanks for reaching out to Adobe community.
Yes, what you have said above exactly correct about the OSGI service. Here are your answers for your statements below.
a]If I create a bundle, a service for it is automatically created?
Basically service is, component providing the service, means it implementing one or more Java interfaces(i.e., services). If you use annotation in Implementation class @service, then service will be created after building the bundle.
b] If a start the bundle, the service is invoked.
Yes, the service will be invoked through sling.getService() method like ex: com.adobe.cq.KeyService keyService = sling.getService(com.adobe.cq.KeyService.class);
For reference, please see this article, how to create the service and invoke the service by creating object instance : https://helpx.adobe.com/experience-manager/using/first-osgi.html
Thanks,
Ratna Kumar.
Views
Replies
Total Likes
Hi,
Thanks for reaching out to Adobe community.
Yes, what you have said above exactly correct about the OSGI service. Here are your answers for your statements below.
a]If I create a bundle, a service for it is automatically created?
Basically service is, component providing the service, means it implementing one or more Java interfaces(i.e., services). If you use annotation in Implementation class @service, then service will be created after building the bundle.
b] If a start the bundle, the service is invoked.
Yes, the service will be invoked through sling.getService() method like ex: com.adobe.cq.KeyService keyService = sling.getService(com.adobe.cq.KeyService.class);
For reference, please see this article, how to create the service and invoke the service by creating object instance : https://helpx.adobe.com/experience-manager/using/first-osgi.html
Thanks,
Ratna Kumar.
Views
Replies
Total Likes
In addition to what Ranta stated - a powerful way to use a service in another service is to inject Service A into Service B using Dependency Injection. See this article to learn how to perform Dependency Injection:
https://helpx.adobe.com/experience-manager/using/datasourcepool.html
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies