Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

How to check whether page invalidation is done for particular path in flush agents or not(Publish instance)

Avatar

Level 4

Hi All,

We have to trigger mail at Publish instance for the below scenario.

Consider page(with scaffolding content) is replicated from author to publish. Scaffolding content is considered as page

When we publish the page from author to publish, two entity(page and scaffolding page) will be replicated to publish instance. Flush agent is configured at publish instance to invalidate both the page and scaffolding page.

Mail has to be sent once cache invalidation(not after the successful replication from author to publish) is done for scaffolding page.

How to identify the cache invalidation successful event for particular path at publish instance?

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

You should observe the replication status of the page:

(ReplicationStatus ("The Adobe AEM Quickstart and Web Application.") )

ReplicationStatus status = page.adaptTo(ReplicationStatus.class);

if (status.isActivated()) {

...

}

The "tricky" part is to determine the exact time when to perform this check.

Jörg

View solution in original post

7 Replies

Avatar

Level 10

You may use workflows or sling events

For workflow- step 1 would be to publish and step2 to send emails. Configure the workflow to trigger automatically/manually for any activation under the project structure.

acs-aem-samples/SampleSlingEventHandler.java at master · Adobe-Consulting-Services/acs-aem-samples ·...

Avatar

Level 4

Your solution will not work for this scenario if cache validation failed for page due to web server not running.

Mail has to be sent once cache invalidation(not after the successful replication from author to publish) is done for scaffolding page.

Avatar

Level 10

Sling event could work in this use case.  Get hold of specific flush agents, listen to whenever they get triggered and check specific headers/path and wait for 200 response to trigger the email.

dispatcher handler-

/dispatcher/invalidate.cache

Avatar

Correct answer by
Employee Advisor

You should observe the replication status of the page:

(ReplicationStatus ("The Adobe AEM Quickstart and Web Application.") )

ReplicationStatus status = page.adaptTo(ReplicationStatus.class);

if (status.isActivated()) {

...

}

The "tricky" part is to determine the exact time when to perform this check.

Jörg

Avatar

Level 4

Gaurav,

Thanks for your response.

I listened on event for flush job completion(org/apache/sling/event/notification/job/FINISHED) for scaffolding page.

On handle event method, I tried to check the below status using replication status API whether it is delivered(cache invalidation done) or not. It is returning false and making the thread to sleep for few more seconds. But still it is returning value as false for the below code after pausing the thread.

ReplicationStatus status = page.adaptTo(ReplicationStatus.class);

status.isPending/isDelivered

Can u explain me how to do below things in event handler based on event path ?

check specific headers/path and wait for 200 response to trigger the email.

Avatar

Level 10

I'm not sure if the org/apache/sling/event/notification/job/FINISHED is the correct topic to listen.

Try these - ReplicationAction.EVENT_TOPIC or ReplicationActionType.Activate or Delete whatever is configured in your flush agents

In my mind, there couple of ways to tackle this. See what works best -

  • Sling event
    1. implement EventHandler, listen to flush event, get the ReplicationAction from event and then get ReplicationStatus from it
    2. listen to content page changes/creation, trigger the replication agents and flush agents programmatically using ReplicationOptions (use filter to get specific agents) so that you can control the agents/data and perform the entire activity in same session. Get replication status from this object
  • JCR event (use it only if it justifies the need as they operate at low level)
    1. implement EventListener, register to a particular event, use observationmanager to get either nodes or current session form event and then get replicationaction/status from it
    2. make sure to unregister the listener/close session on deactivate otherwise you may run into other issues

path is available in both event & replicationaction if you listen to replicationaction otherwise if you listen to content page then also you would have the path to proceed further.

header is same as path for flush agents, however replicationaction/replicationoptions would give you other headers as required.

Adobe CQ Help | Creating Replication Event Handlers for Adobe Experience Manager

Creating an Event Listener for Adobe Experience Manager 6.4

Adobe Experience Manager Help | Creating an Adobe Experience Manager Event Listener that tags pages

http://www.sotheanim.com/27-how-to-write-a-replication-event-listener