You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2015/03/30 16:36:34 UTC

svn commit: r1670113 - in /sling/trunk/bundles/jcr/resource/src: main/java/org/apache/sling/jcr/resource/internal/ main/java/org/apache/sling/jcr/resource/internal/helper/jcr/ test/java/org/apache/sling/jcr/resource/internal/

Author: cziegeler
Date: Mon Mar 30 14:36:34 2015
New Revision: 1670113

URL: http://svn.apache.org/r1670113
Log:
SLING-4533 : OakResourceListener does not allow to configure the OAK observation queue length. Apply patch from Marc Pfaff

Modified:
    sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/OakResourceListener.java
    sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProviderFactory.java
    sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/SynchronousOakResourceListener.java

Modified: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/OakResourceListener.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/OakResourceListener.java?rev=1670113&r1=1670112&r2=1670113&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/OakResourceListener.java (original)
+++ sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/OakResourceListener.java Mon Mar 30 14:36:34 2015
@@ -80,7 +80,8 @@ public class OakResourceListener extends
             final ObservationListenerSupport support,
             final BundleContext bundleContext,
             final Executor executor,
-            final PathMapper pathMapper)
+            final PathMapper pathMapper,
+            final int  observationQueueLength)
     throws RepositoryException {
         super("/", "jcr:primaryType", "sling:resourceType", "sling:resourceSuperType");
         this.support = support;
@@ -91,7 +92,15 @@ public class OakResourceListener extends
         props.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation");
         props.put(Constants.SERVICE_DESCRIPTION, "Apache Sling JCR Observation Listener for Oak");
 
-        final Observer observer = new BackgroundObserver(this, executor);
+        final Observer observer = new BackgroundObserver(this, executor, observationQueueLength) {
+            @Override
+            protected void added(int queueSize) {
+                if (queueSize == observationQueueLength) {
+                    logger.warn("Revision queue for observer {} is full (max = {}). Further revisions will be compacted.",
+                            getClass().getName(), observationQueueLength);
+                }
+            }
+        };
         serviceRegistration = bundleContext.registerService(Observer.class.getName(), observer, props);
     }
 

Modified: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProviderFactory.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProviderFactory.java?rev=1670113&r1=1670112&r2=1670113&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProviderFactory.java (original)
+++ sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProviderFactory.java Mon Mar 30 14:36:34 2015
@@ -84,6 +84,8 @@ public class JcrResourceProviderFactory
      */
     private static final String NEW_PASSWORD = "user.newpassword";
 
+    private static final int DEFAULT_OBSERVATION_QUEUE_LENGTH = 1000;
+
     /** Logger */
     private final Logger log = LoggerFactory.getLogger(getClass());
 
@@ -93,6 +95,12 @@ public class JcrResourceProviderFactory
               description="If this switch is enabled, and Oak is used as the repository implementation, some optimized components are used.")
     private static final String PROPERTY_OPTIMIZE_FOR_OAK = "optimize.oak";
 
+    @Property(
+            intValue = DEFAULT_OBSERVATION_QUEUE_LENGTH,
+            label = "Observation queue length",
+            description = "Maximum number of pending revisions in a observation listener queue")
+    private static final String OBSERVATION_QUEUE_LENGTH = "oak.observation.queue-length";
+
     private static final String REPOSITORY_REFERNENCE_NAME = "repository";
 
     /** The dynamic class loader */
@@ -147,8 +155,9 @@ public class JcrResourceProviderFactory
         try {
             if ( isOak ) {
                 try {
-                    this.listener = new OakResourceListener(root, support, context.getBundleContext(), executor, pathMapper);
-                    log.info("Detected Oak based repository. Using improved JCR Resource Listener");
+                    int observationQueueLength = PropertiesUtil.toInteger(context.getProperties().get(OBSERVATION_QUEUE_LENGTH), DEFAULT_OBSERVATION_QUEUE_LENGTH);
+                    this.listener = new OakResourceListener(root, support, context.getBundleContext(), executor, pathMapper, observationQueueLength);
+                    log.info("Detected Oak based repository. Using improved JCR Resource Listener with observation queue length {}", observationQueueLength);
                 } catch ( final RepositoryException re ) {
                     throw re;
                 } catch ( final Throwable t ) {

Modified: sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/SynchronousOakResourceListener.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/SynchronousOakResourceListener.java?rev=1670113&r1=1670112&r2=1670113&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/SynchronousOakResourceListener.java (original)
+++ sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/SynchronousOakResourceListener.java Mon Mar 30 14:36:34 2015
@@ -45,7 +45,7 @@ public class SynchronousOakResourceListe
             final ServiceTracker tracker,
             final Executor executor)
             throws LoginException, RepositoryException, NoSuchFieldException {
-        super("/", new ObservationListenerSupport(bundleContext, repo), bundleContext, executor, new PathMapperImpl());
+        super("/", new ObservationListenerSupport(bundleContext, repo), bundleContext, executor, new PathMapperImpl(), 1000);
         PrivateAccessor.setField(this.support, "resourceResolver", resolver);
         PrivateAccessor.setField(this.support, "eventAdminTracker", tracker);
     }