openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r912465 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/component/ main/java/org/apache/webbeans/container/ main/java/org/apache/webbeans/intercept/ main/java/org/apache/webbeans/util/ test/java/org/apache/webbeans...
Date Mon, 22 Feb 2010 02:19:28 GMT
Author: struberg
Date: Mon Feb 22 02:19:27 2010
New Revision: 912465

URL: http://svn.apache.org/viewvc?rev=912465&view=rev
Log:
OWB-6 store information for all Beans in the passivationBeans list.

This is needed since we also need to serialise proxies of NormalScoped
Beans which are not passivating. Imagine an @ApplicationScoped userService
gets injected into a @ViewScoped ListModel.


Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractOwbBean.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractProducerBean.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ConversationBean.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ManagedBean.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/NewBean.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/OwbBean.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerMethodBean.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorHandler.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/contexts/SerializationTest.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/circular/beans/CircularDependenScopeBean.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=912465&r1=912464&r2=912465&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
Mon Feb 22 02:19:27 2010
@@ -207,7 +207,7 @@
     
     /**
      * TODO there are probably other infos which must get added to make the id unique!
-     * If not, it will crash in {@link BeanManagerImpl#addPassivationCapableBean(javax.enterprise.inject.spi.Bean)}
+     * If not, it will crash in {@link BeanManagerImpl#addPassivationInfo(javax.enterprise.inject.spi.Bean)}
      * anyway. 
      *
      * {@inheritDoc}
@@ -579,4 +579,10 @@
     {
         return this.logger;
     }
+
+    @Override
+    public boolean isDependent() {
+        return false;
+    }
+    
 }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractProducerBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractProducerBean.java?rev=912465&r1=912464&r2=912465&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractProducerBean.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractProducerBean.java
Mon Feb 22 02:19:27 2010
@@ -17,6 +17,7 @@
 import java.lang.annotation.Annotation;
 import java.util.Set;
 
+import javax.enterprise.context.Dependent;
 import javax.enterprise.context.spi.CreationalContext;
 import javax.enterprise.inject.spi.Bean;
 import javax.enterprise.inject.spi.InjectionPoint;
@@ -218,5 +219,13 @@
         return false;
     }
     
+    /**
+     * look at a Dependent scope annotation.
+     */
+    @Override
+    public boolean isDependent() {
+        return getScope().equals(Dependent.class);
+    }
+
 
 }
\ No newline at end of file

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ConversationBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ConversationBean.java?rev=912465&r1=912464&r2=912465&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ConversationBean.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ConversationBean.java
Mon Feb 22 02:19:27 2010
@@ -85,4 +85,5 @@
             instance = null;
         }
     }
+    
 }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ManagedBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ManagedBean.java?rev=912465&r1=912464&r2=912465&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ManagedBean.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ManagedBean.java
Mon Feb 22 02:19:27 2010
@@ -16,6 +16,7 @@
 import java.io.Serializable;
 import java.lang.reflect.Constructor;
 
+import javax.enterprise.context.Dependent;
 import javax.enterprise.context.spi.CreationalContext;
 import javax.enterprise.inject.spi.Bean;
 import javax.enterprise.inject.spi.Decorator;
@@ -114,5 +115,12 @@
         return false;
     }
 
+    /**
+     * look at a Dependent scope annotation.
+     */
+    @Override
+    public boolean isDependent() {
+        return getScope().equals(Dependent.class);
+    }
 
 }
\ No newline at end of file

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/NewBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/NewBean.java?rev=912465&r1=912464&r2=912465&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/NewBean.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/NewBean.java
Mon Feb 22 02:19:27 2010
@@ -54,4 +54,12 @@
         return definedType;
     }
 
+    /**
+     * always true for New qualifier
+     */
+    @Override
+    public boolean isDependent() {
+        return true;
+    }
+
 }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/OwbBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/OwbBean.java?rev=912465&r1=912464&r2=912465&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/OwbBean.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/OwbBean.java
Mon Feb 22 02:19:27 2010
@@ -172,4 +172,11 @@
      */
     public boolean isPassivationCapable();
     
+    /**
+     * This determines if this bean is really a dependent bean,
+     * and as such always creats a freshl instance for each
+     * InjectionPoint. A BeanManagerBean is e.g. not a dependent bean.
+     * @return <code>true</code> if this is a dependent bean
+     */
+    public boolean isDependent();
 }
\ No newline at end of file

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerMethodBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerMethodBean.java?rev=912465&r1=912464&r2=912465&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerMethodBean.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerMethodBean.java
Mon Feb 22 02:19:27 2010
@@ -42,6 +42,13 @@
     protected Method disposalMethod;
 
     /**
+     * This string will be used for passivating the Bean.
+     * It will be created on the first use.
+     * @see #getId()
+     */
+    private String passivatingId = null;
+
+    /**
      * Creates a new instance.
      * 
      * @param parent parent bean
@@ -96,6 +103,16 @@
         this.disposalMethod = disposalMethod;
     }
 
+    public String getId()
+    {
+        if (passivatingId == null)
+        {
+            String id = super.getId();
+            
+            passivatingId = id + "#" + creatorMethod.toGenericString();
+        }
+        return passivatingId;
+    }
     /**
      * Gets actual type arguments.
      * 

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java?rev=912465&r1=912464&r2=912465&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
Mon Feb 22 02:19:27 2010
@@ -56,6 +56,7 @@
 import org.apache.webbeans.component.EnterpriseBeanMarker;
 import org.apache.webbeans.component.InjectionTargetBean;
 import org.apache.webbeans.component.JmsBeanMarker;
+import org.apache.webbeans.component.OwbBean;
 import org.apache.webbeans.component.third.ThirdpartyBeanImpl;
 import org.apache.webbeans.config.WebBeansFinder;
 import org.apache.webbeans.context.ContextFactory;
@@ -137,10 +138,10 @@
     private List<AnnotatedType<?>> additionalAnnotatedTypes = new CopyOnWriteArrayList<AnnotatedType<?>>();
 
     /**
-     * This map stores all {@link PassivationCapable} beans along with their unique id.
-     * This is used for serialization.
+     * This map stores all beans along with their unique {@link PassivationCapable} id.
+     * This is used as a reference for serialization.
      */
-    private ConcurrentHashMap<String, Bean<?>> passivationCapableBeans = new
ConcurrentHashMap<String, Bean<?>>(); 
+    private ConcurrentHashMap<String, Bean<?>> passivationBeans = new ConcurrentHashMap<String,
Bean<?>>(); 
 
     /**
      * The parent Manager this child is depending from.
@@ -287,13 +288,13 @@
         if(newBean instanceof AbstractOwbBean)
         {
             this.deploymentBeans.add(newBean);
-            addPassivationCapableBean(newBean);
+            addPassivationInfo((OwbBean)newBean);
         }
         else
         {
             ThirdpartyBeanImpl<?> bean = new ThirdpartyBeanImpl(newBean);
             this.deploymentBeans.add(bean);
-            addPassivationCapableBean(bean);
+            addPassivationInfo(bean);
         }
         
 
@@ -301,20 +302,20 @@
     }
 
     /**
-     * Check if the bean is PassivationCapable and add it to the id store.
+     * Check if the bean is has a passivation id and add it to the id store.
      *
      * @param bean
      * @throws DefinitionException if the id is not unique.
      */
-    protected void addPassivationCapableBean(Bean<?> bean) throws DefinitionException
+    protected void addPassivationInfo(OwbBean<?> bean) throws DefinitionException
     {
-        String id = null;
-        if((id=WebBeansUtil.isPassivationCapable(bean)) != null)
+        String id = bean.getId();
+        if(id != null)
         {
-            Bean<?> oldBean = passivationCapableBeans.putIfAbsent(id, bean);
+            Bean<?> oldBean = passivationBeans.putIfAbsent(id, bean);
             if (oldBean != null)
             {
-                throw new DefinitionException("PassivationCapable bean id is not unique:
" + id);
+                throw new DefinitionException("PassivationCapable bean id is not unique:
" + id + " bean:" + bean);
             }
             
         }        
@@ -662,8 +663,7 @@
             instance = getReference(injectedBean, injectionPoint.getType(), injectedCreational);
             
             // add this dependent into bean dependent list
-            // only if the member is not static and not already a proxy
-            if (!WebBeansUtil.isStaticInjection(injectionPoint) && !JavassistProxyFactory.isProxyInstance(instance))
+            if (!WebBeansUtil.isStaticInjection(injectionPoint))
             {
                 ownerCreationalContextImpl.addDependent(injectedBean, instance, injectedCreational);
             }
@@ -710,7 +710,7 @@
     @Override
     public Bean<?> getPassivationCapableBean(String id)
     {
-        return passivationCapableBeans.get(id);
+        return passivationBeans.get(id);
     }
 
     /**

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=912465&r1=912464&r2=912465&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
Mon Feb 22 02:19:27 2010
@@ -373,21 +373,25 @@
     private  void writeObject(ObjectOutputStream s) throws IOException
     {
         s.writeLong(serialVersionUID);
-        if(WebBeansUtil.isPassivationCapable(this.bean) != null)
+        // we have to write the ids for all beans, not only PassivationCapable
+        // since this gets serialized along with the Bean proxy.
+        String passivationId = this.bean.getId();
+        if (passivationId!= null)
         {
-            s.writeUTF(this.bean.getId());   
+            s.writeObject(passivationId);
         }
         else
         {
+            s.writeObject(null);
             logger.warn("Trying to serialize not passivated capable bean proxy : " + this.bean);
         }
     }
     
     private  void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException
     {
-        if( s.readLong() == serialVersionUID)
+        if(s.readLong() == serialVersionUID)
         {
-            String passivationId = s.readUTF();
+            String passivationId = (String) s.readObject();
             if (passivationId != null)
             {
                 this.bean = (OwbBean<?>)BeanManagerImpl.getManager().getPassivationCapableBean(passivationId);

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java?rev=912465&r1=912464&r2=912465&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
Mon Feb 22 02:19:27 2010
@@ -2540,12 +2540,7 @@
     
     public static boolean isDependent(Bean<?> bean)
     {
-        if(bean.getScope().equals(Dependent.class))
-        {
-            return true;
-        }
-        
-        return false;
+        return ((OwbBean) bean).isDependent();
     }
     
     public static void inspectErrorStack(String logMessage)

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/contexts/SerializationTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/contexts/SerializationTest.java?rev=912465&r1=912464&r2=912465&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/contexts/SerializationTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/contexts/SerializationTest.java
Mon Feb 22 02:19:27 2010
@@ -32,6 +32,13 @@
 import org.apache.webbeans.newtests.injection.circular.beans.CircularConstructorOrProducerMethodParameterBean;
 import org.apache.webbeans.newtests.injection.circular.beans.CircularDependenScopeBean;
 import org.apache.webbeans.newtests.injection.circular.beans.CircularNormalInConstructor;
+import org.apache.webbeans.test.component.CheckWithCheckPayment;
+import org.apache.webbeans.test.component.CheckWithMoneyPayment;
+import org.apache.webbeans.test.component.IPayment;
+import org.apache.webbeans.test.component.PaymentProcessorComponent;
+import org.apache.webbeans.test.component.event.normal.ComponentWithObserves1;
+import org.apache.webbeans.test.component.event.normal.ComponentWithObserves2;
+import org.apache.webbeans.test.component.event.normal.TransactionalInterceptor;
 import org.apache.webbeans.util.WebBeansUtil;
 
 import junit.framework.Assert;
@@ -91,6 +98,13 @@
         classes.add(CircularConstructorOrProducerMethodParameterBean.class);
         classes.add(CircularDependenScopeBean.class);
         classes.add(CircularNormalInConstructor.class);
+        classes.add(TransactionalInterceptor.class);
+        classes.add(ComponentWithObserves1.class);
+        classes.add(ComponentWithObserves2.class);
+        classes.add(PaymentProcessorComponent.class);
+        classes.add(IPayment.class);
+        classes.add(CheckWithCheckPayment.class);
+        classes.add(CheckWithMoneyPayment.class);
 
         startContainer(classes);
 

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/circular/beans/CircularDependenScopeBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/circular/beans/CircularDependenScopeBean.java?rev=912465&r1=912464&r2=912465&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/circular/beans/CircularDependenScopeBean.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/circular/beans/CircularDependenScopeBean.java
Mon Feb 22 02:19:27 2010
@@ -23,6 +23,8 @@
 import javax.inject.Inject;
 import javax.inject.Named;
 
+import org.apache.webbeans.test.component.event.normal.Transactional;
+
 @Dependent
 @Named(value="org.apache.webbeans.newtests.injection.circular.beans.CircularDependenScopeBean")
 public class CircularDependenScopeBean
@@ -32,6 +34,7 @@
     public static boolean success = false;
     
     
+    @Transactional
     public void hello()
     {
         



Mime
View raw message