openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gerdo...@apache.org
Subject svn commit: r933524 - in /openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans: component/ intercept/
Date Tue, 13 Apr 2010 09:07:26 GMT
Author: gerdogdu
Date: Tue Apr 13 09:07:26 2010
New Revision: 933524

URL: http://svn.apache.org/viewvc?rev=933524&view=rev
Log:
[OWB-352]Please not reinvert until issue closed succesfully. Thread Safety Problem in our
InterceptorHandlers, aka proxies. Adding another sideeefect is not good
to change old logic altough old logic may not be correct.

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractOwbBean.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/ApplicationScopedBeanIntereptorHandler.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/DependentScopedBeanInterceptorHandler.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorHandler.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/NormalScopedBeanInterceptorHandler.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=933524&r1=933523&r2=933524&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
Tue Apr 13 09:07:26 2010
@@ -166,6 +166,9 @@ public abstract class AbstractOwbBean<T>
                 }
             }
             
+            //Remove incmplete instance from creational Context
+            ((CreationalContextImpl)creationalContext).remove();
+            
         }
         catch (Exception re)
         {

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/ApplicationScopedBeanIntereptorHandler.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/ApplicationScopedBeanIntereptorHandler.java?rev=933524&r1=933523&r2=933524&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/ApplicationScopedBeanIntereptorHandler.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/ApplicationScopedBeanIntereptorHandler.java
Tue Apr 13 09:07:26 2010
@@ -21,7 +21,6 @@ package org.apache.webbeans.intercept;
 import javax.enterprise.context.spi.CreationalContext;
 
 import org.apache.webbeans.component.OwbBean;
-import org.apache.webbeans.context.creational.CreationalContextImpl;
 
 
 /**
@@ -43,7 +42,7 @@ public class ApplicationScopedBeanIntere
     /**
      * Creates a new handler.
      * @param bean bean
-     * @param creationalContext creational context
+     * @param creationalContext creaitonal context
      */
     public ApplicationScopedBeanIntereptorHandler(OwbBean<?> bean, CreationalContext<?>
creationalContext)
     {
@@ -53,11 +52,11 @@ public class ApplicationScopedBeanIntere
     /**
      * {@inheritDoc}
      */
-    protected Object getContextualInstance(OwbBean<Object> bean, CreationalContextImpl<?>
creationalContext)
+    protected Object getContextualInstance(OwbBean<Object> bean)
     {
         if (cachedInstance == null) 
         {
-            cachedInstance = super.getContextualInstance(bean, creationalContext);
+            cachedInstance = super.getContextualInstance(bean);
         }
         
         return cachedInstance;

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/DependentScopedBeanInterceptorHandler.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/DependentScopedBeanInterceptorHandler.java?rev=933524&r1=933523&r2=933524&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/DependentScopedBeanInterceptorHandler.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/DependentScopedBeanInterceptorHandler.java
Tue Apr 13 09:07:26 2010
@@ -67,12 +67,10 @@ public class DependentScopedBeanIntercep
     /**
      * {@inheritDoc}
      */
-    protected Object callAroundInvokes(Method proceed, Object[] arguments, List<InterceptorData>
stack,
-                                       CreationalContextImpl<?> cc)
-    throws Exception
+    protected Object callAroundInvokes(Method proceed, Object[] arguments, List<InterceptorData>
stack) throws Exception
     {
         InvocationContextImpl impl = new InvocationContextImpl(this.bean, this.actualInstance
,proceed, arguments, stack, InterceptorType.AROUND_INVOKE);
-        impl.setCreationalContext(cc);
+        impl.setCreationalContext(creationalContext);
         
         return impl.proceed();
     }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorHandler.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorHandler.java?rev=933524&r1=933523&r2=933524&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorHandler.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorHandler.java
Tue Apr 13 09:07:26 2010
@@ -169,13 +169,11 @@ public abstract class InterceptorHandler
      * @param method business method
      * @param proceed proceed method
      * @param arguments method arguments
-     * @param creationalContext bean creational context
+     * @param ownerCreationalContext bean creational context
      * @return method result
      * @throws Exception for exception
      */
-    public Object invoke(Object instance, Method method, Method proceed, Object[] arguments,

-                         CreationalContextImpl<?> creationalContext)
-    throws Exception
+    public Object invoke(Object instance, Method method, Method proceed, Object[] arguments,
CreationalContextImpl<?> ownerCreationalContext) throws Exception
     {
         //Result of invocation
         Object result = null;
@@ -212,7 +210,7 @@ public abstract class InterceptorHandler
                         ((ProxyObject)delegate).setHandler(this.delegateHandler);
 
                         // Gets component decorator stack
-                        decorators = WebBeansDecoratorConfig.getDecoratorStack(injectionTarget,
instance, delegate, creationalContext);                        
+                        decorators = WebBeansDecoratorConfig.getDecoratorStack(injectionTarget,
instance, delegate, ownerCreationalContext);                        
                         //Sets decorator stack of delegate
                         this.delegateHandler.setDecorators(decorators);
                         
@@ -249,10 +247,7 @@ public abstract class InterceptorHandler
                         // Call Around Invokes
                         if (WebBeansUtil.isContainsInterceptorMethod(this.interceptedMethodMap.get(method),
InterceptorType.AROUND_INVOKE))
                         {
-                            return callAroundInvokes(method, arguments, 
-                                                    InterceptorUtil.getInterceptorMethods(this.interceptedMethodMap.get(method),
-                                                                                        
 InterceptorType.AROUND_INVOKE),
-                                                    creationalContext);
+                            return callAroundInvokes(method, arguments, InterceptorUtil.getInterceptorMethods(this.interceptedMethodMap.get(method),
InterceptorType.AROUND_INVOKE));
                         }
                         
                     }
@@ -307,9 +302,7 @@ public abstract class InterceptorHandler
      * @return return of method
      * @throws Exception for any exception
      */
-    protected abstract Object callAroundInvokes(Method interceptedMethod, Object[] arguments,

-                                                List<InterceptorData> stack, CreationalContextImpl<?>
creationalContext)
-    throws Exception;
+    protected abstract Object callAroundInvokes(Method interceptedMethod, Object[] arguments,
List<InterceptorData> stack) throws Exception;
     
     /**
      * 

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/NormalScopedBeanInterceptorHandler.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/NormalScopedBeanInterceptorHandler.java?rev=933524&r1=933523&r2=933524&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/NormalScopedBeanInterceptorHandler.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/NormalScopedBeanInterceptorHandler.java
Tue Apr 13 09:07:26 2010
@@ -18,6 +18,7 @@
  */
 package org.apache.webbeans.intercept;
 
+import java.lang.ref.WeakReference;
 import java.lang.reflect.Method;
 import java.util.List;
 
@@ -42,6 +43,9 @@ public class NormalScopedBeanInterceptor
     /**Serial id*/
     private static final long serialVersionUID = 1L;
     
+    /**Creational context*/
+    private transient WeakReference<CreationalContext<?>> creationalContext =
null;
+
     /**
      * Creates a new bean instance
      * @param bean bean 
@@ -50,6 +54,7 @@ public class NormalScopedBeanInterceptor
     public NormalScopedBeanInterceptorHandler(OwbBean<?> bean, CreationalContext<?>
creationalContext)
     {
         super(bean);
+        this.creationalContext = new WeakReference<CreationalContext<?>>(creationalContext);
     }
     
     /**
@@ -58,38 +63,21 @@ public class NormalScopedBeanInterceptor
     @Override
     public Object invoke(Object instance, Method method, Method proceed, Object[] arguments)
throws Exception
     {
-        CreationalContextImpl<?> creationalContext = null;
-        
-        //Context of the bean
-        Context webbeansContext = getBeanManager().getContext(bean.getScope());
-
-        if (webbeansContext instanceof AbstractContext)
-        {
-            creationalContext = (CreationalContextImpl<?>) ((AbstractContext)webbeansContext).getCreationalContext(bean);
-        }
-        if (creationalContext == null)
-        {
-            // if there was no CreationalContext set from external, we create a new one
-            creationalContext = (CreationalContextImpl<?>) CreationalContextFactory.getInstance().getCreationalContext(bean);
-        }
-        
         //Get instance from context
-        Object webbeansInstance = getContextualInstance((OwbBean<Object>) this.bean,
creationalContext);
+        Object webbeansInstance = getContextualInstance((OwbBean<Object>) this.bean);
         
         //Call super
-        return super.invoke(webbeansInstance, method, proceed, arguments, creationalContext);
+        return super.invoke(webbeansInstance, method, proceed, arguments, (CreationalContextImpl<?>)
this.creationalContext.get());
     }
         
     /**
      * {@inheritDoc}
      */
-    protected Object callAroundInvokes(Method proceed, Object[] arguments, List<InterceptorData>
stack, CreationalContextImpl<?> creationalContext)
-    throws Exception
+    protected Object callAroundInvokes(Method proceed, Object[] arguments, List<InterceptorData>
stack) throws Exception
     {
-        InvocationContextImpl impl = new InvocationContextImpl(this.bean, 
-                                                               getContextualInstance((OwbBean<Object>)
this.bean, creationalContext),
+        InvocationContextImpl impl = new InvocationContextImpl(this.bean, getContextualInstance((OwbBean<Object>)
this.bean),
                                                                proceed, arguments, stack,
InterceptorType.AROUND_INVOKE);
-        impl.setCreationalContext(creationalContext);
+        impl.setCreationalContext(creationalContext.get());
 
         return impl.proceed();
 
@@ -99,10 +87,9 @@ public class NormalScopedBeanInterceptor
     /**
      * Gets instance from context.
      * @param bean bean instance
-     * @param creationalContext
      * @return the underlying contextual instance, either cached or resolved from the context

      */
-    protected Object getContextualInstance(OwbBean<Object> bean, CreationalContextImpl<?>
creationalContext)
+    protected Object getContextualInstance(OwbBean<Object> bean)
     {
         Object webbeansInstance = null;
         
@@ -117,8 +104,22 @@ public class NormalScopedBeanInterceptor
             return webbeansInstance;
         }
         
+        if (webbeansContext instanceof AbstractContext)
+        {
+            CreationalContext<?> cc = ((AbstractContext)webbeansContext).getCreationalContext(bean);
+            if (cc != null)
+            {
+                creationalContext = new WeakReference<CreationalContext<?>>(cc);
+            }
+        }
+        if (creationalContext == null)
+        {
+            // if there was no CreationalContext set from external, we create a new one
+            creationalContext = new WeakReference<CreationalContext<?>>(CreationalContextFactory.getInstance().getCreationalContext(bean));
+        }
+        
         // finally, we create a new contextual instance
-        webbeansInstance = webbeansContext.get((Contextual<Object>)this.bean, (CreationalContext<Object>)
creationalContext);
+        webbeansInstance = webbeansContext.get((Contextual<Object>)this.bean, (CreationalContext<Object>)
creationalContext.get());
         
         return webbeansInstance;
     }



Mime
View raw message