-
Notifications
You must be signed in to change notification settings - Fork 41
/
ReplicationListener.java
52 lines (45 loc) · 1.95 KB
/
ReplicationListener.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package com.aem.community.core.listeners;
import java.util.HashMap;
import org.apache.sling.event.jobs.JobManager;
import org.osgi.framework.Constants;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventConstants;
import org.osgi.service.event.EventHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.day.cq.replication.ReplicationAction;
import com.day.cq.replication.ReplicationActionType;
@Component(service=EventHandler.class,
immediate = true,
property = {
Constants.SERVICE_DESCRIPTION + "=Demo to listen event.job.topic on page Activation ",
EventConstants.EVENT_TOPIC + "=com/day/cq/replication"
})
public class ReplicationListener implements EventHandler{
private final Logger LOGGER = LoggerFactory.getLogger(getClass());
//dictates to the JobManager which JobConsumer will be instantiated in line 36
//event.job.topic = com/adobe/training/core/replicationjob
//from http://localhost:4502/system/console/events
private static final String TOPIC = "com/adobe/training/core/replicationjob";
@Reference
private JobManager jobManager;
@Override
public void handleEvent(final Event event) {
ReplicationAction action = ReplicationAction.fromEvent(event);
if(action.getType().equals(ReplicationActionType.ACTIVATE) && action.getPath()!=null) {
// Create a properties map that contains things we want to pass through the job
try {
HashMap<String, Object> jobprops = new HashMap<String, Object>();
jobprops.put("PAGE_PATH", action.getPath());
jobManager.addJob(TOPIC, jobprops);
// LOGGER.info("=============Topic: '"+TOPIC+"' with payload: '"+action.getPath()+"' was added to the Job Manager");
} catch (Exception e) {
// TODO Auto-generated catch block
LOGGER.info("============= ERROR CREATING JOB : NO PAYLOAD WAS DEFINED");
e.printStackTrace();
}
}
}
}