Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

AEM 6.3 Event problem

Avatar

Level 1

Hi,

I would need some help regarding the AEM events for the 6.3 beta.

So far we used simple EventHandlers to observe repository changes. Unfortunately the support for the ChangedAttributeNames etc values within the event seems to be gone.

When I realized this I tried to implement the documentation suggested ResourceChangeListener, unfortunately the event is missing the attribute change informations too. Last option was to implement a JCR event listener that works fine as long I register this listener to the observerManager of a session that I got via

session = repository.login( new SimpleCredentials( ... ) )

this for I need login credentials within the code what is pretty uncomfortable.

This shows me that the jcr event contains the information pretty well but this is not added to the sling events properly.

Additionally to this we needed to adapt our code to use

resolver = resourceResolverFactory.getServiceResourceResolver( paramMap )

instead of the old administrative resourceResolver call.

So my idea was to combine both and register the eventListener to the observerManager of the serviceResolver session.

After some debugging I realized that the session I get via the repository login call is working for this while the session of the service resource resolver is not because it gets closed and seems to be just a temporary one, what seems kill the workspace and the observermanager.

So is it possible somehow to avoid this problem somehow? Or maybe is it possible to set the path value of the observed node by additionally specifying a special attribute to be observed instead?

 

thx,

Sven

12 Replies

Avatar

Level 3

Why was this never addressed? We're having the same problem over a year later.

Avatar

Community Advisor

Hi,

You can try below to get Session using below to observe JCR events.

session = repository.loginService("subservice-name", null);

More Info SlingRepository (Apache Sling 7 API)

Thanks

Arun



Arun Patidar

Avatar

Level 3

Sorry, I'm not sure if I'm misunderstanding, but the problem I'm seeing that's similar is I don't see the property changed / property added messages from Events. It appears to have been removed in AEM 6.3.              

Avatar

Community Advisor

Hi,

I am able to listen property changes in AEM 6.3

I have added JCR events like below:

protected void activate(ComponentContext context) throws Exception {

  session = repository.loginService("readService",null);

  observationManager = session.getWorkspace().getObservationManager();

  observationManager.addEventListener(this, Event.PROPERTY_ADDED | Event.PROPERTY_CHANGED, "/content/AEM63App/fr/jcreventpage", true, null,

  new String[]{"cq:PageContent","nt:unstructured"} , true);

  //logger.debug("*************added JCR event listener");

  }

Could you please tell me what you are trying?



Arun Patidar

Avatar

Level 3

You're using the EventListener, it looks like. Like the user above I tried a ResourceListener like this. I tried this code from Stack Overflow as a sanity check.

When I debug this the addedPropertyNames and changedPropertyNames properties of "change" are null. I would expect to see what changed here.

Avatar

Level 3

So like I said in my own thread I opened​, I'm having trouble with the ResourceChangeListener. I haven't tried an EventListener yet. I'm worried that I'll go to the trouble of implementing it and land in the same place.

Avatar

Level 3

arunp99088702​ - I just tried a sample of an EventListener and it worked. I was able to see which property changed. In their sample code ACS Commons warns against using this often, it seems, saying...

This is why I've been trying to get the ResourceChangeListener to work. Plus it seems more precise.     

Avatar

Community Advisor

I try to get changed property using ResourceChangeListener

but according to documentation getChangedPropertyNames() is deprecated.

ResourceChange (Apache Sling 9 API)

I am not sure if there is any alternative to this method or use JCR Events Listeners instead of ResourceChangeListener



Arun Patidar

Avatar

Level 10

Sometimes it seems things are noted deprecated without any replacement. It may be in that state for a long time. In some cases - you may need to still use that as there is no replacement method.

Avatar

Level 3

I think this is what's throwing me off. When I think of deprecated I think of things that will be removed in the future. Not things that are being removed immediately. This feels like a documentation error on Adobe's part if I'm being honest. When I did the upgrade from 6.1 to 6.3 I explicitly looked for things that were being removed and dealt with those first. This wasn't noted as something that was being removed.

Avatar

Level 10

Sometimes - they mark something as depricated and it still remains for quite a long time. ie - look at:

ResourceResolver resourceResolver = resolverFactory.getAdministrativeResourceResolver(null);

  session = resourceResolver.adaptTo(Session.class);

This is marked deprecated - but been here for a while and still works.

Avatar

Level 3

Right. It's unfortunate in terms of documentation, though. I need to figure out how to call out documentation mistakes, because I think it is a mistake to have something marked as deprecated and not call out when the underlying functionality was removed.

In terms of the solution, I've been working to implement a JCR EventListener. The main problem I can see is a potential performance problem as you essentially have to listen for every change or update event on a given path in the entire datastore and then check the path and exit quickly if there isn't a match.

This strikes me as potentially a performance problem.