openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1435150 - in /openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans: component/AbstractOwbBean.java context/creational/CreationalContextImpl.java
Date Fri, 18 Jan 2013 14:14:58 GMT
Author: arne
Date: Fri Jan 18 14:14:58 2013
New Revision: 1435150

URL: http://svn.apache.org/viewvc?rev=1435150&view=rev
Log:
OWB-755: Fixed disposal of dependent instances

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractOwbBean.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/CreationalContextImpl.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractOwbBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractOwbBean.java?rev=1435150&r1=1435149&r2=1435150&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractOwbBean.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractOwbBean.java
Fri Jan 18 14:14:58 2013
@@ -164,6 +164,10 @@ public abstract class AbstractOwbBean<T>
                 injectionTarget.inject(instance, creationalContext);
                 injectionTarget.postConstruct(instance);
             }
+            if (getScope().equals(Dependent.class))
+            {
+                ((CreationalContextImpl<T>)creationalContext).addDependent(null, this,
instance);
+            }
             return instance;
         }
         catch (Exception re)

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/CreationalContextImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/CreationalContextImpl.java?rev=1435150&r1=1435149&r2=1435150&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/CreationalContextImpl.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/CreationalContextImpl.java
Fri Jan 18 14:14:58 2013
@@ -50,11 +50,10 @@ public class CreationalContextImpl<T> im
 
     /**
      * Contextual bean dependent instances
-     * key: contextual instance --> value: dependents
      *
      * <p><b>ATTENTION</b> This variable gets initiated lazily!</p>
      */
-    private Map<Object, List<DependentCreationalContext<?>>> dependentObjects
= null;
+    private List<DependentCreationalContext<?>> dependentObjects = null;
 
     /**Contextual bean*/
     private Contextual<T> contextual = null;
@@ -126,17 +125,9 @@ public class CreationalContextImpl<T> im
             {
                 if (dependentObjects == null)
                 {
-                    dependentObjects = new HashMap<Object, List<DependentCreationalContext<?>>>();
+                    dependentObjects = new ArrayList<DependentCreationalContext<?>>();
                 }
-
-                List<DependentCreationalContext<?>> dependentList = dependentObjects.get(ownerInstance);
-                if(dependentList == null)
-                {
-                    dependentList = new ArrayList<DependentCreationalContext<?>>();
-                    dependentObjects.put(ownerInstance, dependentList);
-                }
-
-                dependentList.add(dependentCreational);
+                dependentObjects.add(dependentCreational);
             }
         }
     }
@@ -157,35 +148,27 @@ public class CreationalContextImpl<T> im
         {
             if (dependentObjects != null)
             {
-                Collection<List<DependentCreationalContext<?>>> values
= dependentObjects.values();
-                if (values != null)
+                // this is kind of an emergency valve...
+                int maxRemoval = dependentObjects.size() * 3;
+                while (!dependentObjects.isEmpty() && maxRemoval > 0)
                 {
-                    for (List<DependentCreationalContext<?>> value : values)
-                    {
-                        // this is kind of an emergency valve...
-                        int maxRemoval = value.size() * 3;
-                        while (!value.isEmpty() && maxRemoval > 0)
-                        {
-                            // we don't use an iterator because the destroyal might register
a 
-                            // fresh PreDestroy interceptor as dependent object...
-                            DependentCreationalContext<T> dependent = (DependentCreationalContext<T>)
value.get(0);
-                            dependent.getContextual().destroy((T) dependent.getInstance(),
this);
-                        
-                            value.remove(0);
-                            maxRemoval--;
-                        }
+                    // we don't use an iterator because the destroyal might register a 
+                    // fresh PreDestroy interceptor as dependent object...
+                    DependentCreationalContext<T> dependent = (DependentCreationalContext<T>)
dependentObjects.get(0);
+                    dependent.getContextual().destroy((T) dependent.getInstance(), this);
                     
-                        if (maxRemoval == 0)
-                        {
-                            throw new WebBeansException("infinite loop detected while destroying
bean " + contextual);
-                        }
-                    }
+                    dependentObjects.remove(0);
+                    maxRemoval--;
+                }
+                    
+                if (maxRemoval == 0)
+                {
+                    throw new WebBeansException("infinite loop detected while destroying
bean " + contextual);
                 }
-
-                dependentObjects = null;
             }
         }
 
+        dependentObjects = null;
     }
     
     /**
@@ -234,7 +217,7 @@ public class CreationalContextImpl<T> im
     throws IOException, ClassNotFoundException
     {
         webBeansContext = WebBeansContext.currentInstance();
-        dependentObjects = (HashMap<Object, List<DependentCreationalContext<?>>>)s.readObject();
+        dependentObjects = (List<DependentCreationalContext<?>>)s.readObject();
 
         String id = (String) s.readObject();
         if (id != null)



Mime
View raw message