incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1520051 - in /sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl: dea/DistributedEventReceiver.java support/BatchResourceRemover.java
Date Wed, 04 Sep 2013 15:29:15 GMT
Author: cziegeler
Date: Wed Sep  4 15:29:15 2013
New Revision: 1520051

URL: http://svn.apache.org/r1520051
Log:
SLING-3039 :  Obsolete events should be removed in batches from the resource tree 

Added:
    sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/support/BatchResourceRemover.java
  (with props)
Modified:
    sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/dea/DistributedEventReceiver.java

Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/dea/DistributedEventReceiver.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/dea/DistributedEventReceiver.java?rev=1520051&r1=1520050&r2=1520051&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/dea/DistributedEventReceiver.java
(original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/dea/DistributedEventReceiver.java
Wed Sep  4 15:29:15 2013
@@ -45,6 +45,7 @@ import org.apache.sling.discovery.Topolo
 import org.apache.sling.discovery.TopologyEvent.Type;
 import org.apache.sling.discovery.TopologyEventListener;
 import org.apache.sling.event.EventUtil;
+import org.apache.sling.event.impl.support.BatchResourceRemover;
 import org.apache.sling.event.impl.support.Environment;
 import org.apache.sling.event.impl.support.ResourceHelper;
 import org.apache.sling.event.jobs.JobUtil;
@@ -255,13 +256,15 @@ public class DistributedEventReceiver
                 final Resource baseResource = resolver.getResource(this.config.getRootPathWithSlash());
                 // sanity check - should never be null
                 if ( baseResource != null ) {
+                    final BatchResourceRemover brr = new BatchResourceRemover();
                     final Iterator<Resource> iter = baseResource.listChildren();
                     while ( iter.hasNext() ) {
                         final Resource rootResource = iter.next();
                         if ( !slingIds.contains(rootResource.getName()) ) {
-                            resolver.delete(rootResource);
+                            brr.delete(rootResource);
                         }
                     }
+                    // final commit for outstanding deletes
                     resolver.commit();
                 }
 
@@ -285,6 +288,7 @@ public class DistributedEventReceiver
             ResourceResolver resolver = null;
             try {
                 resolver = this.resourceResolverFactory.getAdministrativeResourceResolver(null);
+                final BatchResourceRemover brr = new BatchResourceRemover();
 
                 final Resource baseResource = resolver.getResource(this.config.getOwnRootPath());
                 // sanity check - should never be null
@@ -299,7 +303,7 @@ public class DistributedEventReceiver
                         final Resource yearResource = yearIter.next();
                         final int year = Integer.valueOf(yearResource.getName());
                         if ( year < oldYear ) {
-                            resolver.delete(yearResource);
+                            brr.delete(yearResource);
                         } else if ( year == oldYear ) {
 
                             // same year - check months
@@ -309,7 +313,7 @@ public class DistributedEventReceiver
                                 final Resource monthResource = monthIter.next();
                                 final int month = Integer.valueOf(monthResource.getName());
                                 if ( month < oldMonth ) {
-                                    resolver.delete(monthResource);
+                                    brr.delete(monthResource);
                                 } else if ( month == oldMonth ) {
 
                                     // same month - check days
@@ -319,7 +323,7 @@ public class DistributedEventReceiver
                                         final Resource dayResource = dayIter.next();
                                         final int day = Integer.valueOf(dayResource.getName());
                                         if ( day < oldDay ) {
-                                            resolver.delete(dayResource);
+                                            brr.delete(dayResource);
                                         } else if ( day == oldDay ) {
 
                                             // same day - check hours
@@ -329,7 +333,7 @@ public class DistributedEventReceiver
                                                 final Resource hourResource = hourIter.next();
                                                 final int hour = Integer.valueOf(hourResource.getName());
                                                 if ( hour < oldHour ) {
-                                                    resolver.delete(hourResource);
+                                                    brr.delete(hourResource);
                                                 } else if ( hour == oldHour ) {
 
                                                     // same hour - check minutes
@@ -340,7 +344,7 @@ public class DistributedEventReceiver
 
                                                         final int minute = Integer.valueOf(minuteResource.getName());
                                                         if ( minute < oldMinute ) {
-                                                            resolver.delete(minuteResource);
+                                                            brr.delete(minuteResource);
                                                         }
                                                     }
                                                 }
@@ -352,6 +356,7 @@ public class DistributedEventReceiver
                         }
                     }
                 }
+                // final commit for outstanding resources
                 resolver.commit();
 
             } catch (final PersistenceException pe) {

Added: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/support/BatchResourceRemover.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/support/BatchResourceRemover.java?rev=1520051&view=auto
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/support/BatchResourceRemover.java
(added)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/support/BatchResourceRemover.java
Wed Sep  4 15:29:15 2013
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.event.impl.support;
+
+import org.apache.sling.api.resource.PersistenceException;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceResolver;
+
+/**
+ * This class can be used for batch removal of resources
+ */
+public class BatchResourceRemover {
+
+    private final int max;
+
+    private int count;
+
+    public BatchResourceRemover() {
+        this(50);
+    }
+
+    public BatchResourceRemover(final int batchSize) {
+        this.max = batchSize;
+    }
+
+    public void delete(final Resource rsrc )
+    throws PersistenceException {
+        final ResourceResolver resolver = rsrc.getResourceResolver();
+        for(final Resource child : rsrc.getChildren()) {
+            delete(child);
+        }
+        resolver.delete(rsrc);
+        count++;
+        if ( count >= max ) {
+            resolver.commit();
+            count = 0;
+        }
+    }
+}

Propchange: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/support/BatchResourceRemover.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/support/BatchResourceRemover.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url



Mime
View raw message