Last active
March 9, 2021 18:16
-
-
Save floriankraft/3710f30f4eaf212410a3 to your computer and use it in GitHub Desktop.
OSGi EventHandler for AEM replication events, which makes use of a JobProcessor to avoid blacklisting of the EventAdmin.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.apache.felix.scr.annotations.Component; | |
import org.apache.felix.scr.annotations.Property; | |
import org.apache.felix.scr.annotations.Service; | |
import org.apache.sling.event.jobs.JobProcessor; | |
import org.osgi.service.event.Event; | |
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; | |
import static org.apache.sling.event.jobs.JobUtil.processJob; | |
@Component(immediate = true) | |
@Service | |
@Property(name = "event.topics", value = { ReplicationAction.EVENT_TOPIC }) | |
public class MyCoolEventHandler implements EventHandler, JobProcessor { | |
private static final Logger LOG = LoggerFactory.getLogger(MyCoolEventHandler.class); | |
/** | |
* Default constructor. | |
*/ | |
public MyCoolEventHandler() { | |
super(LOG.getName()); | |
} | |
@Override | |
public void handleEvent(final Event event) { | |
if (isInstanceInMode(INSTANCE_MODE.AUTHOR)) { | |
processJob(event, this); | |
} | |
} | |
@Override | |
public boolean process(Event event) { | |
ReplicationAction action = ReplicationAction.fromEvent(event); | |
LOG.debug("Processing event for {}", action.getPath()); | |
if (action.getPath().contains(A_RELEVANT_PATH)) { | |
// Do something cool here | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment