public void onEvent()

in org.apache.sling.ddr/core/src/main/java/org/apache/sling/ddr/core/DeclarativeDynamicResourceManagerService.java [325:377]


    public void onEvent(EventIterator events) {
        log.info("Handle Events: '{}'", events);
        try (ResourceResolver resourceResolver = resourceResolverFactory.getServiceResourceResolver(
            new HashMap<String, Object>() {{ put(ResourceResolverFactory.SUBSERVICE, DYNAMIC_COMPONENTS_SERVICE_USER); }}
        )) {
            while (events.hasNext()) {
                Event event = events.nextEvent();
                String path = event.getPath();
                log.info("Handle Event: '{}', path: '{}', type: '{}'", event, path, event.getType());
                switch (event.getType()) {
                    case Event.PROPERTY_ADDED:
                    case Event.PROPERTY_CHANGED:
                        int index = path.lastIndexOf('/');
                        if(index > 0) {
                            path = path.substring(0, index);
                        }
                        log.info("Property Added or Changed, path: '{}'", path);
                        handleNodeChange(path, true);
                        break;
                    case Event.NODE_ADDED:
                        handleNodeChange(path, true);
                        break;
                    case Event.NODE_REMOVED:
                        handleNodeRemoved(path);
                        break;
                    case Event.NODE_MOVED:
                        // The only thing to handle here is when the location changed
                        Map info = event.getInfo();
                        Object temp = info.get("srcAbsPath");
                        if(temp instanceof String) {
                            // Source found -> get target and remove it
                            String sourcePath = temp.toString();
                            handleNodeRemoved(sourcePath);
                        }
                        temp = info.get("destAbsPath");
                        if(temp instanceof String) {
                            // Destination found -> get target and add it
                            String destPath = temp.toString();
                            handleNodeChange(destPath, true);
                        }
                        break;
                    case Event.PROPERTY_REMOVED:
                        index = path.lastIndexOf('/');
                        if(index > 0) {
                            String resourcePath = path.substring(0, index);
                            handleNodeChange(resourcePath, false);
                        }
                }
            }
        } catch (LoginException | RepositoryException e) {
            log.error("Failed to Handle Events", e);
        }
    }