{"id":14988148,"url":"https://github.com/apache/sling-org-apache-sling-event","last_synced_at":"2025-10-13T07:14:46.955Z","repository":{"id":38629099,"uuid":"107433198","full_name":"apache/sling-org-apache-sling-event","owner":"apache","description":"Apache Sling Event Support","archived":false,"fork":false,"pushed_at":"2025-10-01T11:03:28.000Z","size":1829,"stargazers_count":6,"open_issues_count":8,"forks_count":26,"subscribers_count":27,"default_branch":"master","last_synced_at":"2025-10-06T00:37:00.984Z","etag":null,"topics":["java","sling"],"latest_commit_sha":null,"homepage":"https://sling.apache.org/","language":"Java","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/apache.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2017-10-18T16:19:10.000Z","updated_at":"2025-08-06T12:32:55.000Z","dependencies_parsed_at":"2022-09-15T11:02:04.847Z","dependency_job_id":"b077b5ba-5f2f-4f82-879a-1fb89d82adcf","html_url":"https://github.com/apache/sling-org-apache-sling-event","commit_stats":{"total_commits":159,"total_committers":28,"mean_commits":5.678571428571429,"dds":0.6981132075471699,"last_synced_commit":"71c6d4b3219adb640fa5628fb31cad84d31eff2b"},"previous_names":[],"tags_count":63,"template":false,"template_full_name":null,"purl":"pkg:github/apache/sling-org-apache-sling-event","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apache%2Fsling-org-apache-sling-event","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apache%2Fsling-org-apache-sling-event/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apache%2Fsling-org-apache-sling-event/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apache%2Fsling-org-apache-sling-event/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/apache","download_url":"https://codeload.github.com/apache/sling-org-apache-sling-event/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apache%2Fsling-org-apache-sling-event/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279014113,"owners_count":26085461,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-13T02:00:06.723Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["java","sling"],"created_at":"2024-09-24T14:16:09.970Z","updated_at":"2025-10-13T07:14:46.923Z","avatar_url":"https://github.com/apache.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Apache Sling](https://sling.apache.org/res/logos/sling.png)](https://sling.apache.org)\n\n\u0026#32;[![Build Status](https://ci-builds.apache.org/job/Sling/job/modules/job/sling-org-apache-sling-event/job/master/badge/icon)](https://ci-builds.apache.org/job/Sling/job/modules/job/sling-org-apache-sling-event/job/master/)\u0026#32;[![Test Status](https://img.shields.io/jenkins/tests.svg?jobUrl=https://ci-builds.apache.org/job/Sling/job/modules/job/sling-org-apache-sling-event/job/master/)](https://ci-builds.apache.org/job/Sling/job/modules/job/sling-org-apache-sling-event/job/master/test/?width=800\u0026height=600)\u0026#32;[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=apache_sling-org-apache-sling-event\u0026metric=coverage)](https://sonarcloud.io/dashboard?id=apache_sling-org-apache-sling-event)\u0026#32;[![Sonarcloud Status](https://sonarcloud.io/api/project_badges/measure?project=apache_sling-org-apache-sling-event\u0026metric=alert_status)](https://sonarcloud.io/dashboard?id=apache_sling-org-apache-sling-event)\u0026#32;[![JavaDoc](https://www.javadoc.io/badge/org.apache.sling/org.apache.sling.event.svg)](https://www.javadoc.io/doc/org.apache.sling/org.apache.sling.event)\u0026#32;[![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.apache.sling/org.apache.sling.event/badge.svg)](https://search.maven.org/#search%7Cga%7C1%7Cg%3A%22org.apache.sling%22%20a%3A%22org.apache.sling.event%22) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0)\n\n# Apache Sling Event Support\n\nThis module is part of the [Apache Sling](https://sling.apache.org) project.\n\nFor user documentation see https://sling.apache.org/documentation/bundles/apache-sling-eventing-and-job-handling.html. \nThis README contains information on the bundle, APIs and implementation details.\n\n## Bundle\n\nSling Event contains support for Jobs. It provides an Api for Job, JobManager and Queue, as well as consumer Apis for a \nJobConsumer. There are ancillary APIs to support the work of these core interfaces. The core APIs are exported from \norg.apache.sling.event.jobs with the consumers exported from org.apache.sling.event.jobs.consumer.\n\n\n## Design and implementation\n\n\n### Processing model\n\nJobs are created using the JobManager API. When a Job is created the JobManager writes an entry into the resource tree\n(usually backed up by JCR) via the ResourceResolver. \n\nFor notification of interested parties - not for processing the jobs(!) - adding a job emits an OSGi \nEvent on org/apache/sling/api/resource/Resource/ADDED topic, which is picked up by the \n[NewJobSender](src/main/java/org/apache/sling/event/impl/jobs/notifications/NewJobSender.java) which emits a new OSGi\nEvent on the org/apache/sling/event/notification/job/ADDED topic.\n\nSimilar other notification events are sent out if the state of a job changes. However these events are just FYI events.\nThe events used are contained in [NotificationConstants.java](src/main/java/org/apache/sling/event/jobs/NotificationConstants.java).\n\nThe QueueManager which identifies the queue from s job is periodically scanning the resource tree for new jobs. In\naddition it listens to the org/apache/sling/event/notification/job/ADDED topic for optimization and picking up new\njobs faster (than by scanning). Once a new job is found, the manager triggers the JobQueueImpl to start processing. \nVarious other operations ensure that the JobQueueImpl runs jobs according to its configuration. These are either \nperiodic maintenance classes or triggered by calls to the QueueManager or triggered by Jobs on the queue changing state.\n\nThe queue is maintained by the JobManagerImpl, but each Queue is managed by a JobQueueImpl that receives calls from the\nQueueManager to process jobs. Any thread may update the persisted job state, by resolving the Job name and performing the operation.\n\n### Storage\n\nThe JobManager uses the resource tree and therefore by default the JCR repository provided by Oak for persisting Jobs. The \ncontent tree structure was developed in conjunction with advice from the Oak team to avoid write concurrency issues and the \nneed for maintaining in Oak repository locks. To avoid OakMergeConflicts on write, each job gets a UUID. If a new job is\ncreated on a Sling instance, this instance decides - based on configuration - which Sling instance will process the job\nand writes the new job to an area dedicated to that instance (/var/eventing/jobs/assigned/\u003cSlingID\u003e). Each Sling instance\nonly reads and modifies its own subtree under /var/eventing/jobs/assigned/\u003cSlingID\u003e. This prevents more than one instance from\nattempting to process a Job at the same time. This means that when a Job is started, the path of the job is formed from\nthe target SlingID and the queue name. The target SlingID is formed from the queue configuration informed\nby properties contained within Topology. Every Sling instance advertises is capabilities for processing jobs via topology,\nhence the JobManager pre-allocates Jobs to instance when the job is created.\n\nThe JobQueueImpl then receives the job. The JobQueueImpl only considers jobs allocated to the local instance, and runs\nthose jobs. \n\nSince the SlingID is part of the JobID, there is no risk of 2 instances writing to the same job at the same time when the \njob is allocated or re-allocated to an instance. In the case of first allocation, the creating sling instance will perform \nthe write operation and the target sling instance wont know about the job until after Oak commits. In the case of re-allocation\nthe target sling instance is dead, the cluster leader performs the write and the new target sling instnance wont see the job \nuntil after Oak commits.\n\n### Topology changes\n\nWhen a Sling instance in a cluster is shutdown, it will stop processing all the jobs allocated to it. When it shuts down\na Topology change event propagates and the cluster leader scans all instances under /var/eventing/jobs/assigned/ to see\nif there are any instances that don't exist any more. If there are, the topology leader moves those jobs to a different\nnode by deleting the Oak node and writing a new node into the new targetId assigned location. Any jobs that cant be re-assigned\nare written to the unassigned location.\n\n### Known issues with current implementation and design\n\nThese issues may have been addressed since this document was written, if they have please remove the known issues.\n\n1. Pre-allocation of jobs to queues bound to instances will not ensure load is distributed amongst available instances\nespecially when the queues are large, as jobs complexity and resource requirements vary wildly.\n2. When the topology changes, with many jobs the cost of reallocating jobs may be prohibitive.\n\n\n## Scheduled Jobs.\n\nIn addition to one off jobs the bundle has support for scheduled jobs. The schedule is stored in /var/eventing/scheduled-jobs, \nand the cluster leader uses the Sling commons Scheduler service to run a schedules which add jobs to the appropriate queues\nusing the job manager. For info see org.apache.sling.event.impl.jobs.scheduling.JobSchedulerImpl.execute which is called by the \nSling commons Scheduler service.\n\n\n \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapache%2Fsling-org-apache-sling-event","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fapache%2Fsling-org-apache-sling-event","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapache%2Fsling-org-apache-sling-event/lists"}