I am trying to hook to the rollout event of a page to a live copy. I am experimenting with the EvenListener but I am unable to get it to work. This is my code:
@Component(metatype = true)
@Service
public class MyCustomListener implements EventListener {
private static final Logger LOG = LoggerFactory.getLogger("logger");
@Reference
private ResourceResolverFactory resolverFactory;
private Session session;
private ObservationManager observationManager;
public void run() {
LOG.info("Running...");
}
//Place app logic here to define the AEM Custom Event Handler
protected void activate(ComponentContext ctx) {
try {
//Invoke the adaptTo method to create a Session
ResourceResolver resourceResolver = resolverFactory.getServiceResourceResolver(AutoClosableResourceResolverFactory.getCredentials());
session = resourceResolver.adaptTo(Session.class);
observationManager = session.getWorkspace().getObservationManager();
final String[] types = {"cq:Page", "nt:unstructured"};
final String path = "/"; // define the path
observationManager.addEventListener(this, Event.NODE_ADDED, path, true, null, null, false);
LOG.info("Observing property changes to {} nodes under {}", Arrays.asList(types), path);
} catch (Exception e) {
LOG.error("unable to register session", e);
}
}
protected void deactivate(ComponentContext componentContext) throws RepositoryException {
if (observationManager != null) {
observationManager.removeEventListener(this);
}
if (session != null) {
session.logout();
session = null;
}
}
@Override
public void onEvent(EventIterator eventIterator) {
System.out.println();
}
}
My debug point in the onEvent method never gets called. Am I doing something wrong?
NOTES:
- my session or resource resolver are NOT null.
- AEM 6.3.1.0
Views
Replies
Total Likes