16 Replies Latest reply on Jan 25, 2018 7:15 AM by smacdonald2008

    EventListener event never triggered

    Jdruwe Level 1

      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)
      public class MyCustomListener implements EventListener {
      private static final Logger LOG = LoggerFactory.getLogger("logger");
      private ResourceResolverFactory resolverFactory;
      private Session session;
      private ObservationManager observationManager;
      public void run() {
      //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) {
      if (session != null) {
      session = null;
      public void onEvent(EventIterator eventIterator) {


      My debug point in the onEvent method never gets called. Am I doing something wrong?




      - my session or resource resolver are NOT null.

      - AEM