openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gerdo...@apache.org
Subject svn commit: r1028218 - in /openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans: component/ResourceBean.java proxy/JavassistProxyFactory.java
Date Thu, 28 Oct 2010 08:40:28 GMT
Author: gerdogdu
Date: Thu Oct 28 08:40:28 2010
New Revision: 1028218

URL: http://svn.apache.org/viewvc?rev=1028218&view=rev
Log:
[OWB-486] ResourceBean tries to proxy final classes before testing them for being final, thanks
to David Jencks, Also includes sync. problem that Ying has provided

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ResourceBean.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/JavassistProxyFactory.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ResourceBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ResourceBean.java?rev=1028218&r1=1028217&r2=1028218&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ResourceBean.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ResourceBean.java
Thu Oct 28 08:40:28 2010
@@ -21,8 +21,6 @@ package org.apache.webbeans.component;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Modifier;
 
-import javassist.util.proxy.ProxyFactory;
-
 import javax.enterprise.context.spi.CreationalContext;
 
 import javassist.util.proxy.ProxyObject;
@@ -35,8 +33,6 @@ import org.apache.webbeans.spi.api.Resou
 
 public class ResourceBean<X, T extends Annotation> extends ProducerFieldBean<X>
 {
-    private X actualResourceReference = null;
-    
     private ResourceReference<X,T> resourceReference = null;
     
     public ResourceBean(Class<X> returnType, InjectionTargetBean<?> ownerBean,
@@ -55,34 +51,23 @@ public class ResourceBean<X, T extends A
         X instance = null;
         try
         {
-            //X TODO cache proxy class!
-            ProxyFactory proxyFactory = JavassistProxyFactory.getInstance().createProxyFactory(this);
-            
             ResourceInjectionService resourceService = ServiceLoader.getService(ResourceInjectionService.class);
-            this.actualResourceReference = resourceService.getResourceReference(this.resourceReference);
+            instance = resourceService.getResourceReference(this.resourceReference);
 
-            instance = (X)(JavassistProxyFactory.getInstance().getProxyClass(proxyFactory).newInstance());
-            ((ProxyObject)instance).setHandler(new ResourceProxyHandler(this, this.actualResourceReference));
-        }
-        catch (Exception e)
-        {
-            //check type is final
-            //return actual resource
-            if(Modifier.isFinal(this.actualResourceReference.getClass().getModifiers()))
+            if (instance != null && Modifier.isFinal(instance.getClass().getModifiers()))
             {
-                return this.actualResourceReference;
+                return instance;
             }
             
+            instance = (X) JavassistProxyFactory.getInstance().getResourceBeanProxyClass(this).newInstance();
+            ((ProxyObject) instance).setHandler(new ResourceProxyHandler(this,instance));
+        }
+        catch (Exception e)
+        {
             throw new WebBeansException(e);
         }
-        
-        return instance;
-    }
 
-    @Override
-    protected void destroyInstance(X instance, CreationalContext<X> creationalContext)
-    {
-        this.actualResourceReference = null;
+        return instance;
     }
 
     /**
@@ -94,8 +79,8 @@ public class ResourceBean<X, T extends A
     public X getActualInstance() 
     {
         ResourceInjectionService resourceService = ServiceLoader.getService(ResourceInjectionService.class);
-        this.actualResourceReference = resourceService.getResourceReference(this.resourceReference);
-        return actualResourceReference;
+        X instance = resourceService.getResourceReference(this.resourceReference);
+        return instance;
     }
     
     public boolean isPassivationCapable()

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/JavassistProxyFactory.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/JavassistProxyFactory.java?rev=1028218&r1=1028217&r2=1028218&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/JavassistProxyFactory.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/JavassistProxyFactory.java
Thu Oct 28 08:40:28 2010
@@ -40,6 +40,7 @@ import javax.enterprise.inject.spi.Decor
 import org.apache.webbeans.annotation.WebBeansAnnotation;
 import org.apache.webbeans.component.InjectionTargetBean;
 import org.apache.webbeans.component.OwbBean;
+import org.apache.webbeans.component.ResourceBean;
 import org.apache.webbeans.config.WebBeansFinder;
 import org.apache.webbeans.context.creational.CreationalContextImpl;
 import org.apache.webbeans.decorator.WebBeansDecorator;
@@ -61,7 +62,8 @@ public final class JavassistProxyFactory
     
     private ConcurrentMap<OwbBean<?>, Class<?>> normalScopedBeanProxyClasses
= new ConcurrentHashMap<OwbBean<?>, Class<?>>();    
     private ConcurrentMap<OwbBean<?>, Class<?>> dependentScopedBeanProxyClasses
= new ConcurrentHashMap<OwbBean<?>, Class<?>>();    
-    private ConcurrentMap<OwbBean<?>, Class<?>> interceptorProxyClasses
= new ConcurrentHashMap<OwbBean<?>, Class<?>>();    
+    private ConcurrentMap<OwbBean<?>, Class<?>> interceptorProxyClasses
= new ConcurrentHashMap<OwbBean<?>, Class<?>>();
+    private ConcurrentMap<ResourceBean<?, ?>, Class<?>> resourceBeanProxyClasses
= new ConcurrentHashMap<ResourceBean<?,?>, Class<?>>();
     // second level map is indexed on local interface
     private ConcurrentMap<OwbBean<?>, ConcurrentMap<Class<?>, Class<?>>>
ejbProxyClasses = new ConcurrentHashMap<OwbBean<?>, ConcurrentMap<Class<?>,
Class<?>>>();    
     
@@ -100,6 +102,32 @@ public final class JavassistProxyFactory
         }
         return proxyClass;
     }
+    
+    public Class<?> getResourceBeanProxyClass(ResourceBean<?, ?> resourceBean)
+    {
+        Class<?> proxyClass = null;
+        try
+        {
+            proxyClass = this.resourceBeanProxyClasses.get(resourceBean);
+            if (proxyClass == null)
+            {
+                ProxyFactory fact = createProxyFactory(resourceBean);
+                proxyClass = getProxyClass(fact);
+
+                Class<?> oldClazz = this.resourceBeanProxyClasses.putIfAbsent(resourceBean,
proxyClass);
+                if (oldClazz != null)
+                {
+                    return oldClazz;
+                }                
+            }                
+        }
+        catch (Exception e)
+        {
+            WebBeansUtil.throwRuntimeExceptions(e);
+        }
+
+        return proxyClass;
+    }    
 
     /**
      * Defines the proxy for the given bean and iface using callers factory. Due



Mime
View raw message