What is OSGi Service?
- OSGI services are the reusable services just like method in java.
- Suppose, we have functionality like email triggering so, we will have requirement to reuse this email triggering functionality in whole website.
- So, instead of writing this code again & again we will write this in one time in OSGI Service.
- It has additional annotation which let AEM manipulate this OSGI Service as per the Bundle & Life cycle i.e:- Start, Stop etc.
- We should always have an interface when you are writing a service and implement that interface.
- The mandatory annotation is
@Component
, which designates a class as a service.
- Inside that you have [Service = whenever your interface is and this is mandatory part].
- Some optional methods are executed when your service is activated and your bundle is deployed. As soon as your service is activated, the method that is returned in the 'activated' state is executed.
@Activate Annotation
- In any method, if you add an 'activate' annotation, it will execute at the time of service activation.
@Deactivate annotation
- In OSGi services, the @Deactivate annotation is used to mark a method as the deactivation method for the service.
- This method is called when the service is being deactivated by the OSGi container.
@Modified annotation
- The @Modified annotation is used in Apache Felix.
- other OSGi frameworks to mark a method that should be called whenever the properties of the component change.
Step1:-
- Write an interface named 'ServiceWithModelOsgi'.
- Write a class named 'ServiceWithModelOsgiImpl'.
Step3:-
Thanks Matri
No comments:
Post a Comment