geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r786256 - /geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintRepository.java
Date Thu, 18 Jun 2009 20:41:00 GMT
Author: gnodet
Date: Thu Jun 18 20:41:00 2009
New Revision: 786256

URL: http://svn.apache.org/viewvc?rev=786256&view=rev
Log:
Fix destruction order

Modified:
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintRepository.java

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintRepository.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintRepository.java?rev=786256&r1=786255&r2=786256&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintRepository.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintRepository.java
Thu Jun 18 20:41:00 2009
@@ -29,6 +29,7 @@
 import java.util.LinkedList;
 import java.util.Iterator;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CopyOnWriteArrayList;
 import java.lang.reflect.Type;
 
 import org.osgi.service.blueprint.container.ComponentDefinitionException;
@@ -71,6 +72,11 @@
     private final Map<String, Object> instances = new ConcurrentHashMap<String,
Object>();
 
     /**
+     * Keep track of creation order
+     */
+    private final List<String> creationOrder = new CopyOnWriteArrayList<String>();
+
+    /**
      * Lock for object instance creation
      */
     private final Object instanceLock = new Object();
@@ -232,15 +238,16 @@
 
     public void destroy() {
         // destroy objects in reverse creation order
-        List<Map.Entry<String, Object>> entries = new ArrayList<Map.Entry<String,
Object>>(instances.entrySet());
-        Collections.reverse(entries);
-        for (Map.Entry<String, Object> entry : entries) {
-            Recipe recipe = recipes.get(entry.getKey());
+        List<String> order = new ArrayList<String>(creationOrder);
+        Collections.reverse(order);
+        for (String name : order) {
+            Recipe recipe = recipes.get(name);
             if (recipe != null) {
-                recipe.destroy(entry.getValue());
+                recipe.destroy(instances.get(name));
             }
         }
         instances.clear();
+        creationOrder.clear();
     }
 
     public Object getInstanceLock() {
@@ -300,6 +307,7 @@
                 throw new ComponentDefinitionException("Name " + name + " is already registered
to instance " + instances.get(name));
             }
             instances.put(name, object);
+            creationOrder.add(name); 
             partialObjects.remove(name);
         }
     }



Mime
View raw message