Expand my Community achievements bar.

Enhance your AEM Assets & Boost Your Development: [AEM Gems | June 19, 2024] Improving the Developer Experience with New APIs and Events
SOLVED

Event listeners

Avatar

Level 4

What is the difference between ResourceChangeListener and EventListener in AEM ?

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

There are three type of Listener is in AEM

1. JCR Event Listeners

2. Sling Event Listener

3. Osgi Event listener

 

It is encouraging to use Sling Resource Listener if you are listening just the resource changes.

 

Check for more about sling event listener https://cqdump.joerghoh.de/2022/02/03/the-deprecation-of-sling-resource-events/

 



Arun Patidar

View solution in original post

5 Replies

Avatar

Employee Advisor

@Prashanth_02a Former is called when a resource is added/deleted/modified in Target path. These resources are not changed through the installer but through any other means like a bundle being installed directly through the framework or a configuration directly changed through the configuration admin.

ex:

 

@Property( label = "Change Types", description = "[ Optional ] The change event types this listener will listener for. ", name = ResourceChangeListener.CHANGES, value = {"ADDED", "CHANGED", "REMOVED", "PROVIDER_ADDED", "PROVIDER_REMOVED"} )

 

https://sling.apache.org/apidocs/sling7/org/apache/sling/installer/api/ResourceChangeListener.html

 

while EventListener can be used for  event handling at the JCR level by implementing the EventListener interface. Ex: you can create an event listener that listens to the event when a new node is added.

 

javax.jcr.observation.Event lists the following types:
  1. Event.NODE_ADDED
  2. Event.NODE_MOVED
  3. Event.NODE_REMOVED
  4. Event.PERSIST
  5. Event.PROPERTY_ADDED
  6. Event.PROPERTY_CHANGED
  7. Event.PROPERTY_REMOVED

https://aemhints.com/2020/11/08/event-listener-in-aem-6-5/

Avatar

Level 4

@Mayank_Gandhi 
There are two ResourceChangeListeners one is

 

1. org.apache.sling.installer.api.ResourceChangeListener

 and other one is 

2. org.apache.sling.api.resource.observation.ResourceChangeListener;

 I think you mentioned about first one(org.apache.sling.installer.api.ResourceChangeListener), but i want to know about second one(org.apache.sling.api.resource.observation.ResourceChangeListener;

Avatar

Level 5

@Prashanth_02a 

org.apache.sling.installer.api.ResourceChangeListener

public interface ResourceChangeListener
OSGi Service listening for changes of resources. These resources are not changed through the installer but through any other means like a bundle being installed directly through the framework or a configuration directly changed through the configuration admin.

 

 

 

org.apache.sling.api.resource.observation.ResourceChangeListener;


public interface ResourceChangeListener
Listener for resource change events.
ResourceChangeListener objects are registered with the Framework service registry and are notified with ResourceChange objects when a change occurs.

ResourceChangeListener objects can inspect the received ResourceChange objects to determine the type of change, location and other properties

Avatar

Correct answer by
Community Advisor

There are three type of Listener is in AEM

1. JCR Event Listeners

2. Sling Event Listener

3. Osgi Event listener

 

It is encouraging to use Sling Resource Listener if you are listening just the resource changes.

 

Check for more about sling event listener https://cqdump.joerghoh.de/2022/02/03/the-deprecation-of-sling-resource-events/

 



Arun Patidar