Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

<Critical> Event handler not triggering while delete page

Avatar

Level 2

Hi Team,

 

Event handler not triggering for event topic(SlingConstants.TOPIC_RESOURCE_REMOVED). It is working perfectly fine in all our lower environments even in PROD, but recently in our PROD it is not calling custom event handler which was working in PROD.

 

I have gone through couple of tickets and blogs(everyone saying event handler is blacklisted after certain time mentioned in "Apache felix Event admin implementation" configuration) , but not find solution except adding ignore list.

 

Note:

 

- AEM version - 6.5.11

- All bundles are active and component also active. Able to see component registered in logs.

- As we are getting in critical production application, not suggested restart AEM or start component to solve the issue. 

 

Few queries below.

 

1) How to find blacklisted event handler? Is there any configurations or any place it will maintain the list of blacklisted eventhandlers?

2) How to find event handler blacklisted in logs?

3) Is there anyway to solve without restarting component or AEM instance?

 

sample code snippet

 

@SuppressWarnings("deprecation")
@component(immediate = true, metatype = true, label = "Page Delete event")
@service(EventHandler.class)
@Properties({ @property(name = EventConstants.EVENT_TOPIC, value = { SlingConstants.TOPIC_RESOURCE_REMOVED }),
@property(name = Constants.SERVICE_PID, value = "com.company.module.site.listeners.PageDeleteEventHandler", propertyPrivate = true),
@property(name = EventConstants.EVENT_FILTER, value = "(path=/content/module/*)"),
@property(name = Constants.SERVICE_DESCRIPTION, value = "Page Delete event", propertyPrivate = true),
@property(name = Constants.SERVICE_VENDOR, value = "Company") })
public class PageDeleteEventHandler implements EventHandler {

private String className = this.getClass().getName();
@reference
private SlingSettingsService slingSettingsService;
@reference
private Replicator replicator;
@reference
private SlingRepository slingRepository;
@reference
private IReplicationAgentsConfig agentConfig;


@activate
protected void activate(ComponentContext context) {
String methodName = "activate";

}

@Override
public void handleEvent(Event event) {
String methodName = "handleEvent";
Session session = null;
try {
if (event != null) {
String path = (String) event.getProperty("path");
session = slingRepository.loginService(null, null);
ReplicationOptions options = fetchReplicationOptions();
ReplicationActionType actionType = DELETE;
replicator.replicate(session, actionType, path, options);
}
}
} catch (RepositoryException e) {
} catch (ReplicationException e) {
} finally {
if (session != null && session.isLive()) {
session.logout();
}
}


}

private ReplicationOptions fetchReplicationOptions() {
String methodName = "fetchReplicationOptions";
ReplicationOptions options = new ReplicationOptions();
AgentFilter agentFilter = new AgentIdFilter(<<getting replication agent>>);
options.setSuppressVersions(true);
options.setFilter(agentFilter);
return options;
}

}

 

1 Accepted Solution

Avatar

Correct answer by
Level 6

This is a known issue , when delete event is not working it means none of the events will work.

Quick workaround - restart the instance.

 

We often face there issue in author , where there are so many events on MSM, replication ...etc.

View solution in original post

6 Replies

Avatar

Community Advisor

Hi @gurup36748304, in general AEM is not providing any mechanism that will allow you to see blacklisted events, it also does not expose any UI to mange blacklisted events.

If you have groovy console you can run below script it will list all bundles that contains event handler implementation with information if specific implementation is blacklisted. It will also allow you to remove event handler from blacklist without any restarts etc - you will need to change REMOVE_FROM_BLACKLIST to true. I would suggest to first run the script and review the list of event handlers looking for blacklisted ones. Next run script again but this time with REMOVE_FROM_BLACKLIST flag changed to true. This should solve the problem. Please keep in mind that your event handler can be blacklisted again unless you apply one of the permanent solutions I have described under the script code.

import org.osgi.service.event.EventAdmin

def REMOVE_FROM_BLACKLIST = false

def eventAdmin = getService(EventAdmin.class)

// exact topic matches
eventAdmin?.m_admin?.tracker?.matchingTopic?.each {topic, handlers ->
    println "topic: $topic"
    handlers?.each { handler ->
        def symbolicName = handler?.reference?.bundle?.symbolicName
        println "bundle symbolic name: $symbolicName"
        println "blacklisted: $handler.blacklisted"
        if (REMOVE_FROM_BLACKLIST) {
            handler.update()
            println "event handler from bundle $symbolicName removed from blacklist"
        }
    }
    println "*********"
}

// wildcard topics
eventAdmin?.m_admin?.tracker?.matchingPrefixTopic?.each {topic, handlers ->
    println "topic: $topic"
    handlers?.each { handler ->
        def symbolicName = handler?.reference?.bundle?.symbolicName
        println "bundle symbolic name: $symbolicName"
        println "blacklisted: $handler.blacklisted"
        if (REMOVE_FROM_BLACKLIST) {
            handler.update()
            println "event handler from bundle $symbolicName removed from blacklist"
        }
    }
    println "*********"
}

Above script is a workaround that will allow you to clear blacklist.

The proper solution that you should apply is to re-implement all your event handlers to use jobs for any business logic instead of keeping it directly in EventHandler implementation. You can find more information with some examples under https://sling.apache.org/documentation/tutorials-how-tos/how-to-manage-events-in-sling.html In other words even simple logic should be delegated to Sling Job.

Alternatively you could add your packages to IgnoreTimeout list under  org.apache.felix.eventadmin.impl.EventAdmin OSGi configuration.

If you want to review logs you should look for something like this:

org.apache.felix.eventadmin EventAdmin: Blacklisting ServiceReference [[org.osgi.service.event.EventHandler] | Bundle(your-bundle-name [123])] due to timeout!

 

Avatar

Level 2

Hi lukaszm,

 

Thank you very much for the update. I will try changes suggest and update.

 

Regards,

Guru Pavan

Avatar

Level 2

Hi Lukaszm,

 

One more quick clarification I got the error  mentioned " due to timeout!" but unable to trace out which event handler has issue. Same bundle we have multiple eventhandlers. can you please assist how to find eventhandler name which causing the issue from logs.

 

Regards,

Guru

 

Avatar

Community Advisor

@gurup36748304I do not think you can get more information from logs. This is why I've prepared the script. Which will give you not only bundle information but also event topic - this will allow you to recognize which event is the problematic one - of course unless you have multiple implementations of events handling specific topic. But even then list of potential event handlers to review will be much smaller.

Avatar

Correct answer by
Level 6

This is a known issue , when delete event is not working it means none of the events will work.

Quick workaround - restart the instance.

 

We often face there issue in author , where there are so many events on MSM, replication ...etc.