When click on a page sub-pages will open --->internal servlet is called by granite.js-- Approchable for 3rd party.
What if i want some functionalities internally??
Eg: When a page is created i want to set few properties automatically.
When to use??
To assign some default functionalities when some event occurred.
UseCase::
-->When a node is created felix console throws some event (Internally :: 'A node created' event is created by event manager)
-->Whiteboard pattern is a memory in aem
When we load a bundle it goes into active state. What happen in this process??
All components in the bundle will get activated. At time of Activation.
Anything with @Component is a singleton, So Object is created for that component.
While creating that Object.
If it is a servlet, in memory it created a list of servlets.
If it is a Event listener, in memory it created a list of Event listener.
If it is a Event handler, in memory it created a list of Event handler.
If it is a Workflow, in memory it created a list of Workflow.
It will separate/Categorize --> This is called whiteboard pattern.
Whiteboard pattern is a design pattern implemented by apache felix.
In a nutshell: Whiteboard pattern brings the objects into the memory & Segregate them.
Eg: In Jcr any small changes then triggers an event like -->craete node+save triggers an event & felix console catches the event. Now felix will go to whiteboard & check for the eventListener.
Event-- Event Listener binding/registering/tagging is done by ObservationManager.
If it is registered then it executes that class.
Case2:
:: @Reference -->While code execution it will search for that singleton object -->goes to the registered service object & executes it.
-->
All this happens in runtime
1. Whiteboard pattern
2.EventListener pattern.
3.Singleton Pattern
Q) What happens when a singleton object is requested by multiple events??
A) for Each call a thread is created.
EVENT LISTENER:
Adv:
Its very fast in repository level events & single level nodes.
Eg:tag remove or add.
Dis Adv:
1. When a node is created with automatic child nodes also created then event listener will applied child nodes also(eg: page is created -> event is triggered 2 times).
2. When dealing with more nodes say 5000 nodes then 5000 event will be triggered which consumes a lot of time & memory . System will hang.
3. Its In-memory, When restared there might be a data loss so UN RELIABLE.
-->EventListener class should implement EventListener.
--> get ListenerSession when active is called.
--> From Session-->get workspace -->get observation manager (in repository i.e in JCR level).
For this observation manager add an EventListener.
When create a tag it is stored as cq:tags string[] namespace:tag
Here comes in Event Handler
Event Handler::
-->Based on node type event will be triggered.
For page -->event will be triggered single time.
For Asset -->event will be triggered single time.
--> Better than Event Listener but still expensive.
--> Doesn't have observation manager but works on EVENT_TOPIC
-->EventConstansts: We can manually register our own events.
--> EVENT_TOPIC : implemented by sling-->to bind/register to events---> Here Dam & page events
--> One event can be converted in to another by formEvent()--->take the details in one event & converts into another
There are some functionalities which should be executed even if system hangs out (renditions etc)then the savior is: