felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pde...@apache.org
Subject svn commit: r1639998 - /felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/DependencyManager.java
Date Sun, 16 Nov 2014 16:36:04 GMT
Author: pderop
Date: Sun Nov 16 16:36:03 2014
New Revision: 1639998

URL: http://svn.apache.org/r1639998
Log:
Optimization: use a ConcurrentHashMap instead of a CopyOnWriteArrayList because CopyOnWrite
list has a high cost when adding many
components in the same DependencyManager (DM benchmark may add thousands of Components to
the same DependencyManager).

Modified:
    felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/DependencyManager.java

Modified: felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/DependencyManager.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/DependencyManager.java?rev=1639998&r1=1639997&r2=1639998&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/DependencyManager.java
(original)
+++ felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/DependencyManager.java
Sun Nov 16 16:36:03 2014
@@ -20,11 +20,12 @@ package org.apache.felix.dm;
 
 import java.lang.ref.WeakReference;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
-import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.ConcurrentHashMap;
 
 import org.apache.felix.dm.impl.AdapterServiceImpl;
 import org.apache.felix.dm.impl.AspectServiceImpl;
@@ -73,7 +74,7 @@ public class DependencyManager {    
     
     private final BundleContext m_context;
     private final Logger m_logger;
-    private final List<Component> m_components = new CopyOnWriteArrayList<>();
+    private final ConcurrentHashMap<Component, Component> m_components = new ConcurrentHashMap<>();
 
     // service registry cache
     private static ServiceRegistryCache m_serviceRegistryCache;
@@ -171,7 +172,7 @@ public class DependencyManager {    
      * @param c the service to add
      */
     public void add(Component c) {
-        m_components.add(c);
+        m_components.put(c, c);
         ComponentScheduler.instance().add(c);
     }
 
@@ -560,7 +561,7 @@ public class DependencyManager {    
      * @return a list of components
      */
     public List<Component> getComponents() {
-        return m_components;
+        return Collections.list(m_components.elements());
     }
 
     /**
@@ -684,7 +685,7 @@ public class DependencyManager {    
      * Removes all components and their dependencies.
      */
     public void clear() {
-        for (Component component : m_components) {
+        for (Component component : m_components.keySet()) {
             remove(component);
         }
         m_components.clear();



Mime
View raw message