incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1409872 - in /sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl: EntityResourceList.java OsgiInstallerImpl.java PersistentResourceList.java
Date Thu, 15 Nov 2012 16:36:00 GMT
Author: bdelacretaz
Date: Thu Nov 15 16:35:59 2012
New Revision: 1409872

URL: http://svn.apache.org/viewvc?rev=1409872&view=rev
Log:
SLING-2668 - avoid non-robust remove methods

Modified:
    sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/EntityResourceList.java
    sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/OsgiInstallerImpl.java
    sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/PersistentResourceList.java

Modified: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/EntityResourceList.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/EntityResourceList.java?rev=1409872&r1=1409871&r2=1409872&view=diff
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/EntityResourceList.java
(original)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/EntityResourceList.java
Thu Nov 15 16:35:59 2012
@@ -22,8 +22,10 @@ import java.io.IOException;
 import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Set;
 import java.util.SortedSet;
 import java.util.TreeSet;
 
@@ -339,13 +341,6 @@ public class EntityResourceList implemen
         }
     }
 
-    public void remove(final TaskResource r) {
-        if ( resources.remove(r) ) {
-            LOGGER.debug("Removing unused: {}", r);
-            this.cleanup(r);
-        }
-    }
-
     /**
      * Compact the resource group by removing uninstalled entries
      * @return <code>true</code> if another cycle should be started.
@@ -360,14 +355,24 @@ public class EntityResourceList implemen
             }
             first = false;
         }
-        for(final RegisteredResource r : toDelete) {
-            resources.remove(r);
+        
+        if(!toDelete.isEmpty()) {
+            // Avoid resources.remove(r) as the resource might have
+            // changed since it was added, which causes it to compare()
+            // differently and trip the TreeSet.remove() search.
+            final Set<TaskResource> copy = new HashSet<TaskResource>(resources);
+            for(final RegisteredResource r : toDelete) {
+                copy.remove(r);
+                this.cleanup(r);
+                LOGGER.debug("Removing uninstalled from list: {}", r);
+            }
+            resources.clear();
+            resources.addAll(copy);
             if ( !this.isEmpty() ) {
                 startNewCycle = true;
             }
-            this.cleanup(r);
-            LOGGER.debug("Removing uninstalled from list: {}", r);
         }
+        
         return startNewCycle;
     }
 }

Modified: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/OsgiInstallerImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/OsgiInstallerImpl.java?rev=1409872&r1=1409871&r2=1409872&view=diff
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/OsgiInstallerImpl.java
(original)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/OsgiInstallerImpl.java
Thu Nov 15 16:35:59 2012
@@ -507,7 +507,7 @@ implements OsgiInstaller, ResourceChange
                         first = false;
                     }
                     for(final TaskResource rr : toRemove) {
-                        this.persistentList.remove(rr);
+                        this.persistentList.remove(rr.getURL());
                     }
                 }
                 if ( registeredResources != null ) {

Modified: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/PersistentResourceList.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/PersistentResourceList.java?rev=1409872&r1=1409871&r2=1409872&view=diff
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/PersistentResourceList.java
(original)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/PersistentResourceList.java
Thu Nov 15 16:35:59 2012
@@ -263,16 +263,6 @@ public class PersistentResourceList {
     }
 
     /**
-     * Remove a resource.
-     */
-    public void remove(final TaskResource r) {
-        final EntityResourceList group = this.data.get(r.getEntityId());
-        if ( group != null ) {
-            group.remove(r);
-        }
-    }
-
-    /**
      * Get the resource group for an entity id.
      */
     public EntityResourceList getEntityResourceList(final String entityId) {



Mime
View raw message