sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mpet...@apache.org
Subject svn commit: r1687606 - in /sling/trunk/contrib/extensions/distribution/core/src: main/java/org/apache/sling/distribution/trigger/impl/ test/java/org/apache/sling/distribution/trigger/impl/
Date Thu, 25 Jun 2015 18:45:09 GMT
Author: mpetria
Date: Thu Jun 25 18:45:08 2015
New Revision: 1687606

URL: http://svn.apache.org/r1687606
Log:
SLING-4834: jcr trigger should distribute asyncronously to avoid observation limits

Modified:
    sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/trigger/impl/AbstractJcrEventTrigger.java
    sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/trigger/impl/JcrEventDistributionTrigger.java
    sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/trigger/impl/JcrEventDistributionTriggerFactory.java
    sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/trigger/impl/PersistedJcrEventDistributionTrigger.java
    sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/trigger/impl/PersistedJcrEventDistributionTriggerFactory.java
    sling/trunk/contrib/extensions/distribution/core/src/test/java/org/apache/sling/distribution/trigger/impl/JcrEventDistributionTriggerTest.java
    sling/trunk/contrib/extensions/distribution/core/src/test/java/org/apache/sling/distribution/trigger/impl/PersistingJcrEventDistributionTriggerTest.java

Modified: sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/trigger/impl/AbstractJcrEventTrigger.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/trigger/impl/AbstractJcrEventTrigger.java?rev=1687606&r1=1687605&r2=1687606&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/trigger/impl/AbstractJcrEventTrigger.java
(original)
+++ sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/trigger/impl/AbstractJcrEventTrigger.java
Thu Jun 25 18:45:08 2015
@@ -32,6 +32,7 @@ import java.util.Set;
 import java.util.TreeSet;
 import java.util.concurrent.ConcurrentHashMap;
 
+import org.apache.sling.commons.scheduler.Scheduler;
 import org.apache.sling.distribution.DistributionRequest;
 import org.apache.sling.distribution.DistributionRequestType;
 import org.apache.sling.distribution.SimpleDistributionRequest;
@@ -60,13 +61,16 @@ public abstract class AbstractJcrEventTr
 
     private Session cachedSession;
 
-    AbstractJcrEventTrigger(SlingRepository repository, String path, String serviceUser)
{
+    private final Scheduler scheduler;
+
+    AbstractJcrEventTrigger(SlingRepository repository, Scheduler scheduler, String path,
String serviceUser) {
         if (path == null || serviceUser == null) {
             throw new IllegalArgumentException("path and service are required");
         }
         this.repository = repository;
         this.path = path;
         this.serviceUser = serviceUser;
+        this.scheduler = scheduler;
     }
 
     public void register(@Nonnull DistributionRequestHandler requestHandler) throws DistributionTriggerException
{
@@ -103,27 +107,34 @@ public abstract class AbstractJcrEventTr
         }
 
         public void onEvent(EventIterator eventIterator) {
-            log.info("handling event {}");
+            log.info("jcr trigger onevent");
+
             List<DistributionRequest> requestList = new ArrayList<DistributionRequest>();
 
             while (eventIterator.hasNext()) {
                 Event event = eventIterator.nextEvent();
+                log.info("handling event {}", event);
                 try {
                     if (DistributionJcrUtils.isSafe(event)) {
                         DistributionRequest request = processEvent(event);
                         if (request != null) {
                             addToList(request, requestList);
                         }
-
+                    } else {
+                        log.info("skip unsafe event {}", event);
                     }
                 } catch (RepositoryException e) {
                     log.error("Error while handling event {}", event, e);
                 }
             }
 
-            for (DistributionRequest request: requestList) {
-                requestHandler.handle(request);
+
+            if (requestList.size() > 0) {
+                boolean scheduled = scheduler.schedule(new DistributionExecutor(requestList,
requestHandler), scheduler.NOW());
+
+                log.info("scheduled {} distributions {}", scheduled, requestList.size());
             }
+
         }
     }
 
@@ -228,4 +239,23 @@ public abstract class AbstractJcrEventTr
     }
 
 
+    class DistributionExecutor implements Runnable {
+
+        private final List<DistributionRequest> requestList;
+        private final DistributionRequestHandler requestHandler;
+
+        public DistributionExecutor(List<DistributionRequest> requestList, DistributionRequestHandler
requestHandler) {
+
+            this.requestList = requestList;
+            this.requestHandler = requestHandler;
+        }
+
+        public void run() {
+            for (DistributionRequest request: requestList) {
+                requestHandler.handle(request);
+            }
+        }
+    }
+
+
 }

Modified: sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/trigger/impl/JcrEventDistributionTrigger.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/trigger/impl/JcrEventDistributionTrigger.java?rev=1687606&r1=1687605&r2=1687606&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/trigger/impl/JcrEventDistributionTrigger.java
(original)
+++ sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/trigger/impl/JcrEventDistributionTrigger.java
Thu Jun 25 18:45:08 2015
@@ -21,6 +21,7 @@ package org.apache.sling.distribution.tr
 import javax.jcr.RepositoryException;
 import javax.jcr.observation.Event;
 
+import org.apache.sling.commons.scheduler.Scheduler;
 import org.apache.sling.distribution.DistributionRequest;
 import org.apache.sling.distribution.DistributionRequestType;
 import org.apache.sling.distribution.SimpleDistributionRequest;
@@ -38,14 +39,13 @@ public class JcrEventDistributionTrigger
     private final Logger log = LoggerFactory.getLogger(this.getClass());
     private final String[] ignoredPathsPatterns;
 
-    public JcrEventDistributionTrigger(SlingRepository repository, String path, String serviceName,
String[] ignoredPathsPatterns) {
-        super(repository, path, serviceName);
+    public JcrEventDistributionTrigger(SlingRepository repository, Scheduler scheduler, String
path, String serviceName, String[] ignoredPathsPatterns) {
+        super(repository, scheduler, path, serviceName);
         this.ignoredPathsPatterns = ignoredPathsPatterns;
     }
 
     @Override
     protected DistributionRequest processEvent(Event event) throws RepositoryException {
-        log.info("triggering distribution from jcr event {}", event);
         DistributionRequest distributionRequest = null;
         String eventPath = event.getPath();
         String replicatingPath = getNodePathFromEvent(event);
@@ -55,7 +55,7 @@ public class JcrEventDistributionTrigger
                 // distribute all policies
                 replicatingPath = VltUtils.findParent(replicatingPath, "rep:policy") + "/rep:policy";
 
-                distributionRequest = new SimpleDistributionRequest(DistributionRequestType.ADD,
true, replicatingPath);
+                distributionRequest = new SimpleDistributionRequest(DistributionRequestType.ADD,
replicatingPath);
             } else if (VltUtils.findParent(replicatingPath, "rep:membersList") != null ||
eventPath.endsWith("/rep:members")) {
                 // group member list structure is an implementation detail and it is safer
to distribute the entire group.
 

Modified: sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/trigger/impl/JcrEventDistributionTriggerFactory.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/trigger/impl/JcrEventDistributionTriggerFactory.java?rev=1687606&r1=1687605&r2=1687606&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/trigger/impl/JcrEventDistributionTriggerFactory.java
(original)
+++ sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/trigger/impl/JcrEventDistributionTriggerFactory.java
Thu Jun 25 18:45:08 2015
@@ -26,6 +26,7 @@ import org.apache.felix.scr.annotations.
 import org.apache.felix.scr.annotations.Reference;
 import org.apache.felix.scr.annotations.Service;
 import org.apache.sling.commons.osgi.PropertiesUtil;
+import org.apache.sling.commons.scheduler.Scheduler;
 import org.apache.sling.distribution.component.impl.DistributionComponentConstants;
 import org.apache.sling.distribution.component.impl.SettingsUtils;
 import org.apache.sling.distribution.trigger.DistributionRequestHandler;
@@ -75,6 +76,9 @@ public class JcrEventDistributionTrigger
     @Reference
     private SlingRepository repository;
 
+    @Reference
+    private Scheduler scheduler;
+
 
     @Activate
     public void activate(BundleContext bundleContext, Map<String, Object> config) {
@@ -84,7 +88,7 @@ public class JcrEventDistributionTrigger
         ignoredPathsPatterns = SettingsUtils.removeEmptyEntries(ignoredPathsPatterns);
 
 
-        trigger =  new JcrEventDistributionTrigger(repository, path, serviceName, ignoredPathsPatterns);
+        trigger =  new JcrEventDistributionTrigger(repository, scheduler, path, serviceName,
ignoredPathsPatterns);
         trigger.enable();
     }
 

Modified: sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/trigger/impl/PersistedJcrEventDistributionTrigger.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/trigger/impl/PersistedJcrEventDistributionTrigger.java?rev=1687606&r1=1687605&r2=1687606&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/trigger/impl/PersistedJcrEventDistributionTrigger.java
(original)
+++ sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/trigger/impl/PersistedJcrEventDistributionTrigger.java
Thu Jun 25 18:45:08 2015
@@ -27,6 +27,7 @@ import java.util.Collection;
 import java.util.Map;
 import java.util.Set;
 
+import org.apache.sling.commons.scheduler.Scheduler;
 import org.apache.sling.distribution.DistributionRequest;
 import org.apache.sling.distribution.DistributionRequestType;
 import org.apache.sling.distribution.SimpleDistributionRequest;
@@ -47,8 +48,8 @@ public class PersistedJcrEventDistributi
 
     private final String nuggetsPath;
 
-    public PersistedJcrEventDistributionTrigger(SlingRepository repository, String path,
String servicename, String nuggetsPath) {
-        super(repository, path, servicename);
+    public PersistedJcrEventDistributionTrigger(SlingRepository repository, Scheduler scheduler,
String path, String servicename, String nuggetsPath) {
+        super(repository, scheduler, path, servicename);
         this.nuggetsPath = nuggetsPath == null || nuggetsPath.length() == 0 ? DEFAULT_NUGGETS_PATH
: nuggetsPath;
     }
 

Modified: sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/trigger/impl/PersistedJcrEventDistributionTriggerFactory.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/trigger/impl/PersistedJcrEventDistributionTriggerFactory.java?rev=1687606&r1=1687605&r2=1687606&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/trigger/impl/PersistedJcrEventDistributionTriggerFactory.java
(original)
+++ sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/trigger/impl/PersistedJcrEventDistributionTriggerFactory.java
Thu Jun 25 18:45:08 2015
@@ -26,6 +26,7 @@ import org.apache.felix.scr.annotations.
 import org.apache.felix.scr.annotations.Reference;
 import org.apache.felix.scr.annotations.Service;
 import org.apache.sling.commons.osgi.PropertiesUtil;
+import org.apache.sling.commons.scheduler.Scheduler;
 import org.apache.sling.distribution.component.impl.DistributionComponentConstants;
 import org.apache.sling.distribution.trigger.DistributionRequestHandler;
 import org.apache.sling.distribution.trigger.DistributionTrigger;
@@ -75,6 +76,9 @@ public class PersistedJcrEventDistributi
     @Reference
     private SlingRepository repository;
 
+    @Reference
+    private Scheduler scheduler;
+
 
     @Activate
     public void activate(BundleContext bundleContext, Map<String, Object> config) {
@@ -83,7 +87,7 @@ public class PersistedJcrEventDistributi
         String serviceName = PropertiesUtil.toString(config.get(SERVICE_NAME), null);
         String nuggetsPath = PropertiesUtil.toString(config.get(NUGGETS_PATH), null);
 
-        trigger =  new PersistedJcrEventDistributionTrigger(repository, path, serviceName,
nuggetsPath);
+        trigger =  new PersistedJcrEventDistributionTrigger(repository, scheduler, path,
serviceName, nuggetsPath);
         trigger.enable();
     }
 

Modified: sling/trunk/contrib/extensions/distribution/core/src/test/java/org/apache/sling/distribution/trigger/impl/JcrEventDistributionTriggerTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/distribution/core/src/test/java/org/apache/sling/distribution/trigger/impl/JcrEventDistributionTriggerTest.java?rev=1687606&r1=1687605&r2=1687606&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/distribution/core/src/test/java/org/apache/sling/distribution/trigger/impl/JcrEventDistributionTriggerTest.java
(original)
+++ sling/trunk/contrib/extensions/distribution/core/src/test/java/org/apache/sling/distribution/trigger/impl/JcrEventDistributionTriggerTest.java
Thu Jun 25 18:45:08 2015
@@ -20,6 +20,7 @@ package org.apache.sling.distribution.tr
 
 import javax.jcr.observation.Event;
 
+import org.apache.sling.commons.scheduler.Scheduler;
 import org.apache.sling.distribution.DistributionRequest;
 import org.apache.sling.jcr.api.SlingRepository;
 import org.junit.Test;
@@ -37,9 +38,11 @@ public class JcrEventDistributionTrigger
     @Test
     public void testProcessEventWithoutPathProperty() throws Exception {
         SlingRepository repository = mock(SlingRepository.class);
+        Scheduler scheduler = mock(Scheduler.class);
+
         String path = "/some/path";
         String serviceName = "serviceId";
-        JcrEventDistributionTrigger jcrEventdistributionTrigger = new JcrEventDistributionTrigger(repository,
path, serviceName, null);
+        JcrEventDistributionTrigger jcrEventdistributionTrigger = new JcrEventDistributionTrigger(repository,
scheduler, path, serviceName, null);
         Event event = mock(Event.class);
         DistributionRequest distributionRequest = jcrEventdistributionTrigger.processEvent(event);
         assertNull(distributionRequest);
@@ -48,9 +51,11 @@ public class JcrEventDistributionTrigger
     @Test
     public void testProcessEventWithPathProperty() throws Exception {
         SlingRepository repository = mock(SlingRepository.class);
+        Scheduler scheduler = mock(Scheduler.class);
+
         String path = "/some/path";
         String serviceName = "serviceId";
-        JcrEventDistributionTrigger jcrEventdistributionTrigger = new JcrEventDistributionTrigger(repository,
path, serviceName, null);
+        JcrEventDistributionTrigger jcrEventdistributionTrigger = new JcrEventDistributionTrigger(repository,
scheduler, path, serviceName, null);
         Event event = mock(Event.class);
         when(event.getPath()).thenReturn("/some/path/generating/event");
         DistributionRequest distributionRequest = jcrEventdistributionTrigger.processEvent(event);

Modified: sling/trunk/contrib/extensions/distribution/core/src/test/java/org/apache/sling/distribution/trigger/impl/PersistingJcrEventDistributionTriggerTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/distribution/core/src/test/java/org/apache/sling/distribution/trigger/impl/PersistingJcrEventDistributionTriggerTest.java?rev=1687606&r1=1687605&r2=1687606&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/distribution/core/src/test/java/org/apache/sling/distribution/trigger/impl/PersistingJcrEventDistributionTriggerTest.java
(original)
+++ sling/trunk/contrib/extensions/distribution/core/src/test/java/org/apache/sling/distribution/trigger/impl/PersistingJcrEventDistributionTriggerTest.java
Thu Jun 25 18:45:08 2015
@@ -24,6 +24,7 @@ import javax.jcr.Workspace;
 import javax.jcr.observation.Event;
 import javax.jcr.observation.ObservationManager;
 
+import org.apache.sling.commons.scheduler.Scheduler;
 import org.apache.sling.distribution.DistributionRequest;
 import org.apache.sling.distribution.trigger.DistributionRequestHandler;
 import org.apache.sling.jcr.api.SlingRepository;
@@ -49,11 +50,12 @@ public class PersistingJcrEventDistribut
         Session session = mock(Session.class);
         when(session.nodeExists("/var/nuggets")).thenReturn(true);
         SlingRepository repository = mock(SlingRepository.class);
+        Scheduler scheduler = mock(Scheduler.class);
         when(repository.loginService(serviceName, null)).thenReturn(session);
         String path = "/some/path";
         String nuggetsPath = "/var/nuggets";
         PersistedJcrEventDistributionTrigger persistingJcrEventdistributionTrigger = new
PersistedJcrEventDistributionTrigger(
-                repository, path, serviceName, nuggetsPath);
+                repository, scheduler, path, serviceName, nuggetsPath);
         Event event = mock(Event.class);
         DistributionRequest distributionRequest = persistingJcrEventdistributionTrigger.processEvent(event);
         assertNull(distributionRequest);
@@ -74,11 +76,12 @@ public class PersistingJcrEventDistribut
         when(rootNode.addNode("var", "sling:Folder")).thenReturn(varNode);
         when(session.getRootNode()).thenReturn(rootNode);
         SlingRepository repository = mock(SlingRepository.class);
+        Scheduler scheduler = mock(Scheduler.class);
         when(repository.loginService(serviceName, null)).thenReturn(session);
         String path = "/some/path";
         String nuggetsPath = "/var/nuggets";
         PersistedJcrEventDistributionTrigger persistingJcrEventdistributionTrigger = new
PersistedJcrEventDistributionTrigger(
-                repository, path, serviceName, nuggetsPath);
+                repository, scheduler, path, serviceName, nuggetsPath);
         Event event = mock(Event.class);
         DistributionRequest distributionRequest = persistingJcrEventdistributionTrigger.processEvent(event);
         assertNull(distributionRequest);
@@ -97,11 +100,13 @@ public class PersistingJcrEventDistribut
         when(session.hasPermission(nuggetsPath, Session.ACTION_ADD_NODE)).thenReturn(true);
 
         SlingRepository repository = mock(SlingRepository.class);
+        Scheduler scheduler = mock(Scheduler.class);
+
         when(repository.loginService(serviceName, null)).thenReturn(session);
 
         String path = "/some/path";
         PersistedJcrEventDistributionTrigger persistingJcrEventdistributionTrigger = new
PersistedJcrEventDistributionTrigger(
-                repository, path, serviceName, nuggetsPath);
+                repository, scheduler, path, serviceName, nuggetsPath);
         DistributionRequestHandler handler = mock(DistributionRequestHandler.class);
         persistingJcrEventdistributionTrigger.register(handler);
 
@@ -135,11 +140,13 @@ public class PersistingJcrEventDistribut
         when(session.hasPermission(any(String.class), eq(Session.ACTION_ADD_NODE))).thenReturn(true);
 
         SlingRepository repository = mock(SlingRepository.class);
+        Scheduler scheduler = mock(Scheduler.class);
+
         when(repository.loginService(serviceName, null)).thenReturn(session);
 
         String path = "/some/path";
         PersistedJcrEventDistributionTrigger persistingJcrEventdistributionTrigger = new
PersistedJcrEventDistributionTrigger(
-                repository, path, serviceName, nuggetsPath);
+                repository, scheduler, path, serviceName, nuggetsPath);
         DistributionRequestHandler handler = mock(DistributionRequestHandler.class);
         persistingJcrEventdistributionTrigger.register(handler);
 



Mime
View raw message