How to implement a Replication Event Listener


How can I implement a Replication Event Listener?

Answer, Resolution

  1. Create a class that implements EventHandler interfaces.
  2. Add the following SCR annotations
     @scr.component metatype="false" immediate="true"
     @scr.service interface="org.osgi.service.event.EventHandler"
 name="event.topics" valueRef="ReplicationAction.EVENT_TOPIC"
  3. Implement public void handleEvent(Event event) method.


This simple example adds a Replication Event Listener to Geometrixx application. All it does is log the events it receives.

  1. Open CRXDE
  2. Add the following class implementation. Make sure to save it in the correct folder under /apps/geometrixx/src/impl/src/main/java based on the package name.
    import org.osgi.service.event.Event;
    import org.osgi.service.event.EventHandler;
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
     * This is an example listener that listens for replication events and
     * logs a message.
     * @scr.component metatype="false" immediate="true"
     * @scr.service interface="org.osgi.service.event.EventHandler"
     * name="event.topics" valueRef="ReplicationAction.EVENT_TOPIC"
    public class ReplicationEventListener implements EventHandler {
         * default logger
        private static final Logger log = LoggerFactory.getLogger(ReplicationEventListener.class);
     public void handleEvent(Event event) {
      String n[] = event.getPropertyNames();
 "Event occurred: {}", event.getProperty(WorkflowEvent.EVENT_TYPE));
 "Event properties: ");
      for(String s : n) {
   + " = " + event.getProperty(s));
      ReplicationAction action = ReplicationAction.fromEvent(event);
      if(action != null) {
  "Replication action {} occured on {} ", action.getType().getName(), action.getPath());
  3. Right click file under /apps/geometrixx/src/impl/src/main/java and select Build->Build Bundle. This should build and restart geometrixx bundle in CQ instance your CRXDE is connected to.
    • Note, if you don't see then right click on pom.xml and select Build->Generate .bnd file.
  4. To verify that your new event lister has been deployed go to the components tab in the Felix Console and make sure is there.

To test your replication listener activate a page in CQ and examine crx-quickstart/logs/error.log file under your CQ installation. By default all logging from code deployed in CQ should go there. You should see messages similar to

16.07.2010 13:01:32.525 *INFO* [Thread-5560] 

16.07.2010 13:01:32.525 *INFO* [Thread-5560] Event occurred: null

16.07.2010 13:01:32.525 *INFO* [Thread-5560] Event properties: 

16.07.2010 13:01:32.525 *INFO* [Thread-5560] event.topics = com/day/cq/replication

16.07.2010 13:01:32.525 *INFO* [Thread-5560] path = /content/geometrixx/en/news/webcasts

16.07.2010 13:01:32.525 *INFO* [Thread-5560] type = ACTIVATE

16.07.2010 13:01:32.526 *INFO* [Thread-5560] modificationDate = java.util.GregorianCalendar[time=1279310491837,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="America/Los_Angeles",offset=-28800000,dstSavings=3600000,useDaylight=true,transitions=185,lastRule=java.util.SimpleTimeZone[id=America/Los_Angeles,offset=-28800000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=3,startMonth=2,startDay=8,startDayOfWeek=1,startTime=7200000,startTimeMode=0,endMode=3,endMonth=10,endDay=1,endDayOfWeek=1,endTime=7200000,endTimeMode=0]],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2010,MONTH=6,WEEK_OF_YEAR=29,WEEK_OF_MONTH=3,DAY_OF_MONTH=16,DAY_OF_YEAR=197,DAY_OF_WEEK=6,DAY_OF_WEEK_IN_MONTH=3,AM_PM=1,HOUR=1,HOUR_OF_DAY=13,MINUTE=1,SECOND=31,MILLISECOND=837,ZONE_OFFSET=-28800000,DST_OFFSET=3600000]

16.07.2010 13:01:32.526 *INFO* [Thread-5560] event.distribute = 

16.07.2010 13:01:32.526 *INFO* [Thread-5560] userId = admin

16.07.2010 13:01:32.526 *INFO* [Thread-5560] Replication action Activate occured on /content/geometrixx/en/news/webcasts 

16.07.2010 13:01:32.526 *INFO* [Thread-5560]


Applies To

CQ 5.3


Other Related Articles:


Получайте помощь быстрее и проще

Новый пользователь?