You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by di...@apache.org on 2021/12/30 09:22:09 UTC

[sling-org-apache-sling-sitemap] 01/01: SLING-11036: use dedicated threadpool for scheduled jobs

This is an automated email from the ASF dual-hosted git repository.

diru pushed a commit to branch issue/SLING-11036
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-sitemap.git

commit 83b27574d3a060925c30f4e0c2f4364eb65553b6
Author: Dirk Rudolph <di...@apache.org>
AuthorDate: Thu Dec 30 10:21:54 2021 +0100

    SLING-11036: use dedicated threadpool for scheduled jobs
---
 .../apache/sling/sitemap/impl/SitemapScheduler.java |  5 ++++-
 .../apache/sling/sitemap/impl/SitemapStorage.java   | 21 +++++++++++----------
 2 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/src/main/java/org/apache/sling/sitemap/impl/SitemapScheduler.java b/src/main/java/org/apache/sling/sitemap/impl/SitemapScheduler.java
index ec6898d..d0fdc72 100644
--- a/src/main/java/org/apache/sling/sitemap/impl/SitemapScheduler.java
+++ b/src/main/java/org/apache/sling/sitemap/impl/SitemapScheduler.java
@@ -48,7 +48,8 @@ import static org.apache.sling.sitemap.SitemapUtil.findSitemapRoots;
         configurationPolicy = ConfigurationPolicy.REQUIRE,
         property = {
                 Scheduler.PROPERTY_SCHEDULER_CONCURRENT + ":Boolean=false",
-                Scheduler.PROPERTY_SCHEDULER_RUN_ON + "=" + Scheduler.VALUE_RUN_ON_SINGLE
+                Scheduler.PROPERTY_SCHEDULER_RUN_ON + "=" + Scheduler.VALUE_RUN_ON_SINGLE,
+                Scheduler.PROPERTY_SCHEDULER_THREAD_POOL + "=" + SitemapScheduler.THREADPOOL_NAME
         }
 )
 @Designate(ocd = SitemapScheduler.Configuration.class, factory = true)
@@ -83,6 +84,8 @@ public class SitemapScheduler implements Runnable {
         String searchPath() default "/content";
     }
 
+    public static final String THREADPOOL_NAME = "org-apache-sling-sitemap";
+
     private static final Logger LOG = LoggerFactory.getLogger(SitemapScheduler.class);
     private static final Map<String, Object> AUTH = Collections.singletonMap(ResourceResolverFactory.SUBSERVICE,
             "sitemap-reader");
diff --git a/src/main/java/org/apache/sling/sitemap/impl/SitemapStorage.java b/src/main/java/org/apache/sling/sitemap/impl/SitemapStorage.java
index 5ba3273..c8fc05e 100644
--- a/src/main/java/org/apache/sling/sitemap/impl/SitemapStorage.java
+++ b/src/main/java/org/apache/sling/sitemap/impl/SitemapStorage.java
@@ -58,7 +58,8 @@ import static org.apache.sling.sitemap.impl.SitemapEventUtil.newUpdateEvent;
         property = {
                 Scheduler.PROPERTY_SCHEDULER_NAME + "=sitemap-storage-cleanup",
                 Scheduler.PROPERTY_SCHEDULER_CONCURRENT + ":Boolean=false",
-                Scheduler.PROPERTY_SCHEDULER_RUN_ON + "=" + Scheduler.VALUE_RUN_ON_SINGLE
+                Scheduler.PROPERTY_SCHEDULER_RUN_ON + "=" + Scheduler.VALUE_RUN_ON_SINGLE,
+                Scheduler.PROPERTY_SCHEDULER_THREAD_POOL + "=" + SitemapScheduler.THREADPOOL_NAME
         }
 )
 @Designate(ocd = SitemapStorage.Configuration.class)
@@ -146,6 +147,7 @@ public class SitemapStorage implements Runnable {
                 }
             }
             for (Resource resource : toDelete) {
+                LOG.debug("Purging: {}", toDelete);
                 resolver.delete(resource);
             }
             resolver.commit();
@@ -323,8 +325,15 @@ public class SitemapStorage implements Runnable {
     public Collection<SitemapStorageInfo> getSitemaps(Resource sitemapRoot, Collection<String> names) {
         try (ResourceResolver resolver = resourceResolverFactory.getServiceResourceResolver(AUTH)) {
             Resource topLevelSitemapRoot = getTopLevelSitemapRoot(sitemapRoot);
-            Predicate<SitemapStorageInfo> filter;
+            String storagePath = rootPath + topLevelSitemapRoot.getPath();
+            Resource storageResource = resolver.getResource(storagePath);
 
+            if (storageResource == null) {
+                LOG.debug("Resource at {} does not exist.", storagePath);
+                return Collections.emptySet();
+            }
+
+            Predicate<SitemapStorageInfo> filter;
             if (!isTopLevelSitemapRoot(sitemapRoot) || !names.isEmpty()) {
                 // return only those that match at least on of the names requested
                 filter = info -> names.stream()
@@ -335,14 +344,6 @@ public class SitemapStorage implements Runnable {
                 filter = any -> true;
             }
 
-            String storagePath = rootPath + topLevelSitemapRoot.getPath();
-            Resource storageResource = resolver.getResource(storagePath);
-
-            if (storageResource == null) {
-                LOG.debug("Resource at {} does not exist.", storagePath);
-                return Collections.emptySet();
-            }
-
             return StreamSupport.stream(storageResource.getChildren().spliterator(), false)
                     .filter(SitemapStorage::isValidSitemapFile)
                     .map(SitemapStorage::newSitemapStorageInfo)