HomeBackend Development › Events & listeners

Events & listeners

Purpose: React to repository and platform changes with the right listener type and without melting the instance.

Who this page is for

AudienceWhy it matters to you
Backend engineersChange-driven behaviour

Options ranked

MechanismScopePrefer when
ResourceChangeListenerPath+type filtered resource changesDefault choice for content-change reactions
Sling Jobs (from a listener)Durable follow-up workThe reaction must not be lost
Workflow launcherContent ops visible to adminsBusiness users should see/manage the automation
JCR ObservationListenerLow-level node eventsRarely — legacy/edge cases
EventHandler (OSGi events)Platform topics (replication, page events)Reacting to activation etc.

ResourceChangeListener example

@Component(service = ResourceChangeListener.class, property = {
    ResourceChangeListener.PATHS + "=/content/phi/plans",
    ResourceChangeListener.CHANGES + "=ADDED",
    ResourceChangeListener.CHANGES + "=CHANGED"
})
public class PlanChangeListener implements ResourceChangeListener {
    @Reference private JobManager jobManager;
    @Override public void onChange(List<ResourceChange> changes) {
        changes.forEach(c -> jobManager.addJob("phi/plans/index", Map.of("path", c.getPath())));
    }
}

Pattern: listen thin, work in jobs. The listener thread must return fast; heavy work goes to the job queue.

Rules

Quick navigation