Adding multiple paths in event listener | Community
Skip to main content
New Participant
Feb 3, 2022 9:53 PM UTC
Solved

Adding multiple paths in event listener

I have an event listener in which I am listening to a path as in the below screenshot using Observation Manger . How can I add multiple paths here , so that I can listen to multiple paths. I cannot add the root path, since I don't want to listen to the root path due to other project requirement constraints.

 

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Kishore_Kumar_
Kishore_Kumar_Accepted solution
Level 9
Feb 4, 2022 3:36 AM UTC

Hi @p_v_nair ,

 

Try using ResourceChangeListener to handle multiple paths.

 

https://techrevel.blog/2017/03/15/resourcechangelistener/ 

3 replies

Employee
Sep 26, 2023 12:24 PM UTC

In my case adding multiple paths worked with below syntax

 

@8220494(service = EventHandler.class, immediate = true, property = { EventConstants.EVENT_TOPIC + "=" + ReplicationAction.EVENT_TOPIC, EventConstants.EVENT_FILTER + "=(|(paths=/content/projectname/*)(paths=/content/dam/projectname/*))" }) @ServiceDescription("Listener to listen on replication action in the resource tree") @Designate(ocd = ReplicationListener.SolrSearchPropertiesConfiguration.class) public class ReplicationListener implements EventHandler {

 Specially when we are working on Sling events like Activate or deactivate, the above piece of code will be really handy because you have to listen to activate or deactivate specific paths under your project related folders only in dam and sites.

Translate
joerghoh
Employee
Feb 5, 2022 7:43 PM UTC

As @kishore_kumar_ already pointed out, use the ResourceChangeListener.

 

if that's not possible: 

JackrabbitObservationManager mgr = (JackrabbitObservationManager) session.getWorkspace().getObservationManager;

JackrabbitEventFilter filter = new JackrabbitEventFilter()
  .setAbsPath(PATH1)
  .setAdditionalPaths(PATH2,PATH3, ...)
...

mgr.addEventListener(listener, filter);

This allows to you specify more constraints than the JCR compliant JCR ObservationManager. In Oak the ObservationManager implements the JackrabbitObservationManager.

 

See

https://jackrabbit.apache.org/api/2.12/org/apache/jackrabbit/api/observation/JackrabbitEventFilter.html https://jackrabbit.apache.org/api/2.12/org/apache/jackrabbit/api/observation/JackrabbitObservationManager.html

 

Translate
Kishore_Kumar_
Kishore_Kumar_Accepted solution
Level 9
Feb 4, 2022 3:36 AM UTC

Hi @p_v_nair ,

 

Try using ResourceChangeListener to handle multiple paths.

 

https://techrevel.blog/2017/03/15/resourcechangelistener/ 

Translate