5 Replies Latest reply on Nov 8, 2012 5:58 PM by rush_pawan

    detect page activation/replication complete event


      Hello everyone,


      We have a caching service in front of CQ, so I'm trying to detect when a page is both activated and fully replicated to all publish nodes in order to notify this caching service that a given page has been updated (so it can clear the cache).  I have tried multiple methods:

      1) listening to JCR property changes on the entire tree root, on specifically"lastReplicated" property

      2) sling event handler (org.osgi.service.event.EventHandler) to listen to Activation events


      But either way, this "event" doesn't really give us our desired goal.  If one of the publish nodes is down, both of those methods above would trigger the event.  We want to know when a page is activated, when (and only when) every single publish node in the cluster has the new copy of the page in question.


      Furthermore, even if the publish node(s) are up, the event gets fired BEFORE it is finished replicating to them.  For example I added the following code to check replication status on the pages.  The limited testing I'm doing is completely random.  It's a timing issue.  Sometimes it just happened to finish replication before I poll for Replication Status.


      ResourceResolver resourceResolver = resourceResolverFactory.getAdministrativeResourceResolver(null);

      Resource resource = resourceResolver.getResource(action.getPath());

      ReplicationStatus replicationStatus = resource.adaptTo(ReplicationStatus.class);


      There's a somewhat complicated solution in here somewhere.  I could take the events as they come in, and if the page is still replicating to nodes, then queue them up and poll for successfull replication.  But that would cause all the joy of managing a custom queue (performance, multi-threading, edge cases, etc). 


      Is there a simpler solution?

        • 1. Re: detect page activation/replication complete event
          Jörg Hoh Adobe Employee

          In short: There is no easy solution, which solves this problem efficiently.


          In length: The problem is, that the state of a page is distributed over multiple instances (publishs). Only when the same version of a page is available on all publishs it should be allowed to flush that page on the caching layer. If you reduce the requirements/expectations to the cache-hit-ratio, it's getting easier: Then everytime a page on publish is changed, the cache is invalidated. So every publish invalidates the cache for this page exactly once, which increases the cache-misses.


          An optimal solution would require, that each publish knows the state of each page on all other publishs; and only if one publish updates the state of a page and all other publishs have already reached that state for this page, this specific publish will invalidate the cache. That's not easy, because you get a lot more data to manage and lot of traffic and data updates between the publishs.


          So my advice: Create a simple solution and reduce your expectations for cache-hit-ratio.

          1 person found this helpful
          • 2. Re: detect page activation/replication complete event
            justdoit503 Level 1

            Thanks very much for your help.  Unfortunately, I think you're right about this. 


            One thing that I'm currently looking into is the fact that CQ Author has the little green/red/orange status indicators on pages that indicates (i think) that the given page has been activated/replicated properly to all nodes.  I'm looking into the JS right now to seee how it hooks up.

            • 3. Re: detect page activation/replication complete event
              Jörg Hoh Adobe Employee

              Try the ReplicationStatus interface (http://dev.day.com/docs/en/cq/current/javadoc/index.html?com/day/cq/replication/Replicatio nStatus.html)


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

              • 4. Re: detect page activation/replication complete event
                justdoit503 Level 1


                Thanks.   We've experimented with that API.  The thing is that we get the activation event, then we may have to create our own little multi-threaded queue that doesn't block the event callback thread and consantly POLLS the replication status of previously captured activation events/pages to see if the queue is empty.  Our concern is the strong potential for a performance disaster.  If it's our only option, since nothing else officially supports this concept, then we may just have to do some performance testing and roll with that.  

                • 5. Re: detect page activation/replication complete event
                  rush_pawan Level 4

                  After looking at above conversation i thought to share some information that i have planned of when we were having similar situation to flush out the cache layer.


                  If we think from author prospect its really tough to manage/capture replication event because when replication starts, the event fired first and update the status where actual replication go through queue (all about time and tracking).


                  Just an idea (not sure whether it fit in your case or not): What if we think about writing something only to fire at publish node let say a workflow at modify event (only on publish node) and it will be perfact information which will confirm that something has happened with resource (as CQ does provide this to do 'writing workflow at publish node').


                  I didn't try that but thought to share if it helps you some where.

                  1 person found this helpful