openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1606215 - in /openwebbeans/trunk: webbeans-impl/src/main/java/org/apache/webbeans/component/ webbeans-impl/src/main/java/org/apache/webbeans/context/ webbeans-impl/src/main/java/org/apache/webbeans/intercept/ webbeans-tck/src/main/resource...
Date Fri, 27 Jun 2014 20:36:35 GMT
Author: struberg
Date: Fri Jun 27 20:36:35 2014
New Revision: 1606215

URL: http://svn.apache.org/r1606215
Log:
OWB-974 natively implement InjectionTargetBean serialisation

Added:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/CustomAlterablePassivatingContextImpl.java
      - copied, changed from r1602806, openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/CustomPassivatingContextImpl.java
    openwebbeans/trunk/webbeans-tck/src/main/resources/
    openwebbeans/trunk/webbeans-tck/src/main/resources/META-INF/
    openwebbeans/trunk/webbeans-tck/src/main/resources/META-INF/openwebbeans/
    openwebbeans/trunk/webbeans-tck/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InjectionTargetBean.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/AbstractContext.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/ApplicationContext.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/ContextFactory.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/CustomPassivatingContextImpl.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/ApplicationScopedBeanInterceptorHandler.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InjectionTargetBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InjectionTargetBean.java?rev=1606215&r1=1606214&r2=1606215&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InjectionTargetBean.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InjectionTargetBean.java
Fri Jun 27 20:36:35 2014
@@ -27,6 +27,11 @@ import org.apache.webbeans.container.Inj
 
 import javax.enterprise.inject.spi.InjectionTarget;
 
+
+import java.io.NotSerializableException;
+import java.io.ObjectStreamException;
+import java.io.Serializable;
+
 import org.apache.webbeans.util.Asserts;
 
 /**
@@ -35,7 +40,7 @@ import org.apache.webbeans.util.Asserts;
  * @version $Rev$ $Date$
  * @param <T> bean class
  */
-public class InjectionTargetBean<T> extends AbstractOwbBean<T>
+public class InjectionTargetBean<T> extends AbstractOwbBean<T> implements Serializable
 {    
     /**Annotated type for bean*/
     private AnnotatedType<T> annotatedType;
@@ -86,4 +91,39 @@ public class InjectionTargetBean<T> exte
     {
         return annotatedType;
     }
+
+    /**
+     * This uses the {@link org.apache.webbeans.component.InjectionTargetBean.PassivationBeanWrapper}
+     * to only store the beanPassivationId.
+     */
+    private Object writeReplace() throws ObjectStreamException
+    {
+        String passivationId = getId();
+        if (passivationId == null)
+        {
+            throw new NotSerializableException("Bean is about to be serialized and does not
have any any PassivationCapable id: " + toString());
+        }
+
+        return new PassivationBeanWrapper(passivationId);
+    }
+
+
+    public static class PassivationBeanWrapper implements Serializable
+    {
+        private static final long serialVersionUID = -7588343501478247476L;
+
+        private final String passivationId;
+
+        public PassivationBeanWrapper(String passivationId)
+        {
+            this.passivationId = passivationId;
+        }
+
+        private Object readResolve() throws ObjectStreamException
+        {
+            WebBeansContext webBeansContext = WebBeansContext.getInstance();
+            return webBeansContext.getBeanManagerImpl().getPassivationCapableBean(passivationId);
+        }
+
+    }
 }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/AbstractContext.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/AbstractContext.java?rev=1606215&r1=1606214&r2=1606215&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/AbstractContext.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/AbstractContext.java
Fri Jun 27 20:36:35 2014
@@ -32,7 +32,6 @@ import java.util.concurrent.ConcurrentMa
 
 import javax.enterprise.context.ContextNotActiveException;
 import javax.enterprise.context.spi.AlterableContext;
-import javax.enterprise.context.spi.Context;
 import javax.enterprise.context.spi.Contextual;
 import javax.enterprise.context.spi.CreationalContext;
 
@@ -41,7 +40,7 @@ import org.apache.webbeans.container.Ser
 import org.apache.webbeans.context.creational.BeanInstanceBag;
 
 /**
- * Abstract implementation of the {@link Context} interfaces.
+ * Abstract implementation of the {@link javax.enterprise.context.spi.Context} interfaces.
  * 
  * @see javax.enterprise.context.spi.Context
  * @see RequestContext
@@ -50,7 +49,7 @@ import org.apache.webbeans.context.creat
  * @see ApplicationContext
  * @see ConversationContext
  */
-public abstract class AbstractContext implements Context, AlterableContext, Serializable
+public abstract class AbstractContext implements AlterableContext, Serializable
 {
     private static final long serialVersionUID = 2357678967444477818L;
     /**Context status, active or not*/
@@ -169,6 +168,12 @@ public abstract class AbstractContext im
     {
         
         BeanInstanceBag<?> instance = componentInstanceMap.get(contextual);
+        if (instance == null)
+        {
+            // just exit if people manually invoke destroy after the bean already got ditched
+            return;
+        }
+
         //Get creational context
         CreationalContext<Object> cc = (CreationalContext<Object>)instance.getBeanCreationalContext();
 

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/ApplicationContext.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/ApplicationContext.java?rev=1606215&r1=1606214&r2=1606215&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/ApplicationContext.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/ApplicationContext.java
Fri Jun 27 20:36:35 2014
@@ -42,7 +42,13 @@ public class ApplicationContext extends 
     public void setComponentInstanceMap()
     {
         componentInstanceMap = new ConcurrentHashMap<Contextual<?>, BeanInstanceBag<?>>();
-
     }
 
+    @Override
+    public void destroy(Contextual<?> contextual)
+    {
+        super.destroy(contextual);
+
+        // and now we also need to
+    }
 }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/ContextFactory.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/ContextFactory.java?rev=1606215&r1=1606214&r2=1606215&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/ContextFactory.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/ContextFactory.java
Fri Jun 27 20:36:35 2014
@@ -26,6 +26,7 @@ import javax.enterprise.context.Applicat
 import javax.enterprise.context.ConversationScoped;
 import javax.enterprise.context.RequestScoped;
 import javax.enterprise.context.SessionScoped;
+import javax.enterprise.context.spi.AlterableContext;
 import javax.enterprise.context.spi.Context;
 import javax.inject.Singleton;
 import org.apache.webbeans.logger.WebBeansLoggerFacade;
@@ -79,7 +80,14 @@ public final class ContextFactory
     {
         if (webBeansContext.getBeanManagerImpl().isPassivatingScope(context.getScope()))
         {
-            return new CustomPassivatingContextImpl(webBeansContext.getSerializableBeanVault(),
context);
+            if (context instanceof AlterableContext)
+            {
+                return new CustomAlterablePassivatingContextImpl(webBeansContext.getSerializableBeanVault(),
(AlterableContext) context);
+            }
+            else
+            {
+                return new CustomPassivatingContextImpl(webBeansContext.getSerializableBeanVault(),
context);
+            }
         }
 
         return context;

Copied: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/CustomAlterablePassivatingContextImpl.java
(from r1602806, openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/CustomPassivatingContextImpl.java)
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/CustomAlterablePassivatingContextImpl.java?p2=openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/CustomAlterablePassivatingContextImpl.java&p1=openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/CustomPassivatingContextImpl.java&r1=1602806&r2=1606215&rev=1606215&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/CustomPassivatingContextImpl.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/CustomAlterablePassivatingContextImpl.java
Fri Jun 27 20:36:35 2014
@@ -18,49 +18,24 @@
  */
 package org.apache.webbeans.context;
 
-import org.apache.webbeans.container.SerializableBeanVault;
-
-import javax.enterprise.context.spi.Context;
+import javax.enterprise.context.spi.AlterableContext;
 import javax.enterprise.context.spi.Contextual;
-import javax.enterprise.context.spi.CreationalContext;
-import java.lang.annotation.Annotation;
+
+import org.apache.webbeans.container.SerializableBeanVault;
 
 /**
- *
+ * Wrapper for custom AlterableContexts
  */
-public class CustomPassivatingContextImpl implements Context
+public class CustomAlterablePassivatingContextImpl extends CustomPassivatingContextImpl implements
AlterableContext
 {
-    private final SerializableBeanVault sbv;
-    private final Context context;
-
-
-    CustomPassivatingContextImpl(SerializableBeanVault sbv, Context context)
-    {
-        this.sbv = sbv;
-        this.context = context;
-    }
-
-    @Override
-    public <T> T get(Contextual<T> contextual, CreationalContext<T> creationalContext)
-    {
-        return context.get(sbv.getSerializableBean(contextual), creationalContext);
-    }
-
-    @Override
-    public <T> T get(Contextual<T> contextual)
-    {
-        return context.get(sbv.getSerializableBean(contextual));
-    }
-
-    @Override
-    public Class<? extends Annotation> getScope()
+    CustomAlterablePassivatingContextImpl(SerializableBeanVault sbv, AlterableContext context)
     {
-        return context.getScope();
+        super(sbv, context);
     }
 
     @Override
-    public boolean isActive()
+    public void destroy(Contextual<?> contextual)
     {
-        return context.isActive();
+        ((AlterableContext) context).destroy(sbv.getSerializableBean(contextual));
     }
 }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/CustomPassivatingContextImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/CustomPassivatingContextImpl.java?rev=1606215&r1=1606214&r2=1606215&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/CustomPassivatingContextImpl.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/CustomPassivatingContextImpl.java
Fri Jun 27 20:36:35 2014
@@ -30,8 +30,8 @@ import java.lang.annotation.Annotation;
  */
 public class CustomPassivatingContextImpl implements Context
 {
-    private final SerializableBeanVault sbv;
-    private final Context context;
+    protected final SerializableBeanVault sbv;
+    protected final Context context;
 
 
     CustomPassivatingContextImpl(SerializableBeanVault sbv, Context context)

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/ApplicationScopedBeanInterceptorHandler.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/ApplicationScopedBeanInterceptorHandler.java?rev=1606215&r1=1606214&r2=1606215&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/ApplicationScopedBeanInterceptorHandler.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/ApplicationScopedBeanInterceptorHandler.java
Fri Jun 27 20:36:35 2014
@@ -29,6 +29,10 @@ import javax.enterprise.inject.spi.BeanM
  * <p>Since there is only one single contextual instance of an &#064;ApplicationScoped
bean,
  * we can simply cache this instance inside our bean. We only need to reload this instance
  * if it is null. This happens at the first usage and after the MethodHandler got deserialized</p>
+ *
+ * <p>Also if the application uses the {@link javax.enterprise.context.spi.AlterableContext#destroy(javax.enterprise.context.spi.Contextual)}
+ * method on any ApplicationScoped bean, then the standard NormalScopedBeanInterceptorHandler
must be configured to prevent any caching.
+ * Be careful as this might slow down your application!</p>
  */
 public class ApplicationScopedBeanInterceptorHandler extends NormalScopedBeanInterceptorHandler
 {

Added: openwebbeans/trunk/webbeans-tck/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-tck/src/main/resources/META-INF/openwebbeans/openwebbeans.properties?rev=1606215&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-tck/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
(added)
+++ openwebbeans/trunk/webbeans-tck/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
Fri Jun 27 20:36:35 2014
@@ -0,0 +1,33 @@
+#Licensed to the Apache Software Foundation (ASF) under one
+#or more contributor license agreements.  See the NOTICE file
+#distributed with this work for additional information
+#regarding copyright ownership.  The ASF licenses this file
+#to you under the Apache License, Version 2.0 (the
+#"License"); you may not use this file except in compliance
+#with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+#Unless required by applicable law or agreed to in writing,
+#software distributed under the License is distributed on an
+#"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#KIND, either express or implied.  See the License for the
+#specific language governing permissions and limitations
+#under the License.
+#---------------------------------------------------------------
+# The TCK configuration for OpenWebBeans
+#
+#---------------------------------------------------------------
+
+
+################################################################################################
+###################################### TCK CONFIGURATION SECTION ###############################
+################################################################################################
+
+# this is the tck configuration, thus it has a very high ordinal of 150
+configuration.ordinal=150
+
+
+
+# we have to switch back to the un-cached version of the normal scoping handler 
+org.apache.webbeans.proxy.mapping.javax.enterprise.context.ApplicationScoped=org.apache.webbeans.intercept.NormalScopedBeanInterceptorHandler



Mime
View raw message