openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gerdo...@apache.org
Subject svn commit: r985746 - in /openwebbeans/trunk: webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/component/ webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/ webbeans-openejb/src/main/java/org/apache/webbeans/ejb/ webbeans-openejb/...
Date Sun, 15 Aug 2010 20:25:32 GMT
Author: gerdogdu
Date: Sun Aug 15 20:25:31 2010
New Revision: 985746

URL: http://svn.apache.org/viewvc?rev=985746&view=rev
Log:
[OWB-439]  EjbPlugin session bean proxy creation thread safe problem

Modified:
    openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/component/BaseEjbBean.java
    openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/EjbDefinitionUtility.java
    openwebbeans/trunk/webbeans-openejb/src/main/java/org/apache/webbeans/ejb/EjbPlugin.java
    openwebbeans/trunk/webbeans-openejb/src/main/java/org/apache/webbeans/ejb/component/OpenEjbBean.java

Modified: openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/component/BaseEjbBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/component/BaseEjbBean.java?rev=985746&r1=985745&r2=985746&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/component/BaseEjbBean.java
(original)
+++ openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/component/BaseEjbBean.java
Sun Aug 15 20:25:31 2010
@@ -40,10 +40,7 @@ import org.apache.webbeans.util.ClassUti
 public abstract class BaseEjbBean<T> extends AbstractInjectionTargetBean<T> implements
EnterpriseBeanMarker
 {
     /**Session bean type*/
-    protected SessionBeanType ejbType;
-    
-    /**Injected reference local interface type*/
-    protected Class<?> iface = null;
+    protected final SessionBeanType ejbType;
     
     /** Map of proxy instances to the dependent SFSB they've acquired but not yet removed
*/
     private Map<Object, Object> dependentSFSBToBeRemoved = new ConcurrentHashMap<Object,
Object>();
@@ -52,28 +49,18 @@ public abstract class BaseEjbBean<T> ext
      * Creates a new instance of the session bean.
      * @param ejbClassType ebj class type
      */
-    public BaseEjbBean(Class<T> ejbClassType)
+    public BaseEjbBean(Class<T> ejbClassType, SessionBeanType type)
     {
         super(WebBeansType.ENTERPRISE,ejbClassType);
-
+        
+        //type of the ejb
+        this.ejbType = type;
+        
         //Setting inherited meta data instance
         setInheritedMetaData();
     }
 
-    /**
-     * Sets local interface type.
-     * @param iface local interface type
-     */
-    public void setIface(Class<?> iface)
-    {
-        this.iface = iface;
-    }
-    
-    public Class<?> getIface()
-    {
-        return this.iface;
-    }
-    
+
     /**
      * {@inheritDoc}
      */
@@ -157,15 +144,6 @@ public abstract class BaseEjbBean<T> ext
         }
     }
 
-    /**
-     * Sets session bean type.
-     * @param type session bean type
-     */
-    public void setEjbType(SessionBeanType type)
-    {
-        this.ejbType = type;
-        
-    }
     
     /**
      * Subclasses can override this.

Modified: openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/EjbDefinitionUtility.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/EjbDefinitionUtility.java?rev=985746&r1=985745&r2=985746&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/EjbDefinitionUtility.java
(original)
+++ openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/EjbDefinitionUtility.java
Sun Aug 15 20:25:31 2010
@@ -47,14 +47,12 @@ public final class EjbDefinitionUtility
         creator.defineApiType();
     }
     
-    @SuppressWarnings({"unchecked","deprecation"})
+    @SuppressWarnings({"unchecked"})
     public static <T> T defineEjbBeanProxy(BaseEjbBean<T> bean, Class<?>
iface, CreationalContext<?> creationalContext)
     {
         try
         {
-            T proxyInstance = null;
-            bean.setIface(iface);
-            
+            T proxyInstance = null;            
             Class<?> clazz = JavassistProxyFactory.getInstance().getEjbBeanProxyClass(bean);
             if(clazz == null)
             {
@@ -64,6 +62,7 @@ public final class EjbDefinitionUtility
             }
             
             proxyInstance = (T) ClassUtil.newInstance(clazz);
+            
             EjbBeanProxyHandler handler = new EjbBeanProxyHandler(bean, creationalContext);
             ((ProxyObject)proxyInstance).setHandler(handler);
             

Modified: openwebbeans/trunk/webbeans-openejb/src/main/java/org/apache/webbeans/ejb/EjbPlugin.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-openejb/src/main/java/org/apache/webbeans/ejb/EjbPlugin.java?rev=985746&r1=985745&r2=985746&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-openejb/src/main/java/org/apache/webbeans/ejb/EjbPlugin.java
(original)
+++ openwebbeans/trunk/webbeans-openejb/src/main/java/org/apache/webbeans/ejb/EjbPlugin.java
Sun Aug 15 20:25:31 2010
@@ -318,9 +318,8 @@ public class EjbPlugin extends AbstractO
             throw new IllegalArgumentException("Illegal EJB type with class : " + clazz.getName());
         }
 
-        OpenEjbBean<T> bean = new OpenEjbBean<T>(clazz);
+        OpenEjbBean<T> bean = new OpenEjbBean<T>(clazz, type);
         bean.setDeploymentInfo(info);
-        bean.setEjbType(type);
 
         EjbUtility.fireEvents(clazz, bean, processAnnotatedTypeEvent);
 

Modified: openwebbeans/trunk/webbeans-openejb/src/main/java/org/apache/webbeans/ejb/component/OpenEjbBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-openejb/src/main/java/org/apache/webbeans/ejb/component/OpenEjbBean.java?rev=985746&r1=985745&r2=985746&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-openejb/src/main/java/org/apache/webbeans/ejb/component/OpenEjbBean.java
(original)
+++ openwebbeans/trunk/webbeans-openejb/src/main/java/org/apache/webbeans/ejb/component/OpenEjbBean.java
Sun Aug 15 20:25:31 2010
@@ -24,14 +24,13 @@ import java.util.List;
 
 import javax.ejb.Remove;
 import javax.enterprise.context.spi.CreationalContext;
-import javax.naming.Context;
-import javax.naming.NamingException;
+import javax.enterprise.inject.spi.SessionBeanType;
 
 import org.apache.openejb.DeploymentInfo;
 import org.apache.openejb.InterfaceType;
-import org.apache.openejb.assembler.classic.JndiBuilder;
-import org.apache.openejb.loader.SystemInstance;
-import org.apache.openejb.spi.ContainerSystem;
+import org.apache.openejb.DeploymentInfo.BusinessLocalHome;
+import org.apache.openejb.core.CoreDeploymentInfo;
+import org.apache.openejb.core.ivm.EjbHomeProxyHandler;
 import org.apache.webbeans.ejb.common.component.BaseEjbBean;
 
 /**
@@ -48,9 +47,9 @@ public class OpenEjbBean<T> extends Base
      * Creates a new instance of the session bean.
      * @param ejbClassType ebj class type
      */
-    public OpenEjbBean(Class<T> ejbClassType)
+    public OpenEjbBean(Class<T> ejbClassType, SessionBeanType type)
     {
-        super(ejbClassType);
+        super(ejbClassType, type);
     }
     
     /**
@@ -78,36 +77,14 @@ public class OpenEjbBean<T> extends Base
     @SuppressWarnings("unchecked")
     protected T getInstance(CreationalContext<T> creationalContext)
     {
-        T instance = null;
-        
-        ContainerSystem containerSystem =  SystemInstance.get().getComponent(ContainerSystem.class);
-        Context jndiContext = containerSystem.getJNDIContext();
-        DeploymentInfo deploymentInfo = this.getDeploymentInfo();
-        try
+        List<Class> interfaces = new ArrayList<Class>();
+        for(Class clazz : getBusinessLocalInterfaces())
         {
-            if(iface != null)
-            {
-                InterfaceType type = deploymentInfo.getInterfaceType(iface);
-                if(!type.equals(InterfaceType.BUSINESS_LOCAL))
-                {
-                    throw new IllegalArgumentException("Interface type is not legal business
local interface for session bean class : " + getReturnType().getName());
-                }   
-            }    
-            else
-            {
-                iface = this.deploymentInfo.getBusinessLocalInterface();
-            }
-            
-        String jndiName = "java:openejb/Deployment/" + JndiBuilder.format(deploymentInfo.getDeploymentID(),
this.iface.getName()); 
-        instance = (T)this.iface.cast(jndiContext.lookup(jndiName));                    
        
-            
+            interfaces.add(clazz);
         }
-        catch(NamingException e)
-        {
-            throw new RuntimeException(e);
-        }        
-
-        return instance;
+        
+        BusinessLocalHome home = getBusinessLocalHome(interfaces);
+        return (T)home.create();
     }
 
     
@@ -194,4 +171,29 @@ public class OpenEjbBean<T> extends Base
         return toReturn;
     }
     
+    @SuppressWarnings("unchecked")
+    private BusinessLocalHome getBusinessLocalHome(List<Class> interfaces)
+    {
+        if (getBusinessLocalInterfaces().size() == 0)
+        {
+            throw new IllegalStateException("This component has no business local interfaces:
" 
+                    + ((CoreDeploymentInfo)this.deploymentInfo).getDeploymentID());
+        }
+        
+        if (interfaces.size() == 0)
+        {
+            throw new IllegalArgumentException("No interface classes were specified");
+        }
+       
+        for (Class<?> clazz : interfaces)
+        {
+            if (!getBusinessLocalInterfaces().contains(clazz))
+            {
+                throw new IllegalArgumentException("Not a business interface of this bean:"
+ clazz.getName());
+            }
+        }
+
+        return (BusinessLocalHome) EjbHomeProxyHandler.createHomeProxy(this.deploymentInfo,
InterfaceType.BUSINESS_LOCAL_HOME, interfaces);
+    }
+    
 }
\ No newline at end of file



Mime
View raw message