Thursday, 3 August 2023

OSGi Configuration

What is OSGi Configuration? 

  • In the Context of software development, Osgi stands for(Open Services Gateway Initiative).
  • OSGi is a modular framework for building Java applications, allowing them to be dynamically composed of smaller, reusable components called bundles.
  • When you want to give some input to your Bundle means your Java file like you give for the component you write Osgi Configuration.
  • Basically Osgi Configuration Used in Run Modes
How Osgi Configuration look like?
  • Go to the System Console.
  • and than ConfigManager.

Osgi Configuration Fields



Save Osgi Configuration as a Node

  • In crxde (Content Repository Extreme Development Environment). All the OSGI configurations are stored under (/apps/sling/config or /apps/system/config) by default.
What is the need or purpose of using Osgi Configuration?
  • Basically Osgi Configuration Used in Run Modes.
  • for eg:
  • If our requirement is in Dev environment we want different configuration, In Stage environment we want different configuration & In Production environment we want different configuration then we will use Osgi Configuration. 
How to Create Osgi Configuration?
  • First of all we write Interface for Osgi Service.
  • for eg:
  • Second step, we write a class it means implemented class for Osgi Service
  • for eg:






 

 


In this class we are used few Specific annotation let's discuss what are these annotation and why we will use?

 

  • @Component annotation make services from a simple class.
  • @ObjectClassDefinition(name = "", description = " ")
  • @ObjectClassDefinition this is used to generate Osgi Configuration fields.
  • for eg:


  • @Designate  annotation this is used to generate designate element in the meta type resource for an @ObjectClassDefinition.
  • It means it will generate for this 

  • using the annotative declarative services .




  • we have to create a inner Interface class inside that you have to use public @interface this syntax.


  • Inside that there is 
  • @AttributeDefinition(name = "", description = "", type = AttributeType.STRING)
  • Basically this @AttributeDefination annotation will be using on particular method and you pass some parameters this is used to generate your fields.
  • you will be seeing here I used @AttributeDefinition which have name and than the description and then type.
  • This Type is defined which kind of filled it is so, I define the STRING.
  • It means the filled will be string type.
  • Then I define a method this method will return whatever, the value this filled have and you can give default value.
for eg:


  • Now we have Four fields
  1. First Name
  2. Last Name
  3. Employee ID
  4. Address

This is by default value.

Now let's, see how we can use it?
  • with the help of @Activate annotation method we can use.
What is the purpose of @Activate annotation? 
  • When you want to be load or executed at the time of this service initiation or to deploy this bundle you will write in activate.


I will display this value inside a component.
  • we create a sling Model.
  • for eg:
  1. Interface of Sling Model


2. Sling Model to call Osgi Service.


 
3.Inside Slightly

4.After Deployment the value is on page




In short, 
1)We have a OSGI Configuration that is residing in the OSGI Service.
2)We are calling the OSGI Service from the Sling Model.
3)We are calling the Sling Model using from Sightly/HTL.

Please feel free to comment in case of any mistake I am also learning.
Thanks
Matri Sharma

No comments:

Post a Comment

Servlet in AEM/Sling Servlet

  What is Servlet? A servlet is a Java class that runs on the server side where the application resides. It acts as a middle layer between t...