openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1681656 - in /openwebbeans/trunk: webbeans-impl/src/main/java/org/apache/webbeans/context/ webbeans-impl/src/main/java/org/apache/webbeans/corespi/se/ webbeans-impl/src/main/java/org/apache/webbeans/intercept/ webbeans-impl/src/main/resour...
Date Mon, 25 May 2015 21:41:51 GMT
Author: struberg
Date: Mon May 25 21:41:51 2015
New Revision: 1681656

URL: http://svn.apache.org/r1681656
Log:
OWB-1051 move cache request scope proxies by default

* RequestScopedBeanInterceptorHandler got moved from owb-web to owb-core and enabled by default
* Also enable caches for @SessionScoped beans


Added:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/RequestScopedBeanInterceptorHandler.java
      - copied, changed from r1681588, openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/intercept/RequestScopedBeanInterceptorHandler.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/SessionScopedBeanInterceptorHandler.java
  (with props)
Removed:
    openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/intercept/RequestScopedBeanInterceptorHandler.java
    openwebbeans/trunk/webbeans-web/src/test/resources/
Modified:
    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/RequestContext.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/SessionContext.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/se/DefaultContextsService.java
    openwebbeans/trunk/webbeans-impl/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
    openwebbeans/trunk/webbeans-tck/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
    openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/context/WebContextsService.java
    openwebbeans/trunk/webbeans-web/src/main/resources/META-INF/openwebbeans/openwebbeans.properties

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=1681656&r1=1681655&r2=1681656&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
Mon May 25 21:41:51 2015
@@ -166,6 +166,14 @@ public abstract class AbstractContext im
     @Override
     public void destroy(Contextual<?> contextual)
     {
+        destroyInstance(contextual);
+    }
+
+    /**
+     * Internal destroy method.
+     */
+    public void destroyInstance(Contextual<?> contextual)
+    {
         
         BeanInstanceBag<?> instance = componentInstanceMap.get(contextual);
         if (instance == null)
@@ -207,7 +215,7 @@ public abstract class AbstractContext im
         Set<Contextual<?>> keySet = new HashSet<Contextual<?>>(componentInstanceMap.keySet());
         for (Contextual<?> contextual: keySet)
         {
-            destroy(contextual);
+            destroyInstance(contextual);
         }
         setActive(false);
     }

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=1681656&r1=1681655&r2=1681656&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
Mon May 25 21:41:51 2015
@@ -64,7 +64,7 @@ public class ApplicationContext extends
                 continue;
             }
 
-            destroy(contextual);
+            destroyInstance(contextual);
         }
     }
 

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/RequestContext.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/RequestContext.java?rev=1681656&r1=1681655&r2=1681656&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/RequestContext.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/RequestContext.java
Mon May 25 21:41:51 2015
@@ -24,6 +24,7 @@ import javax.enterprise.context.RequestS
 import javax.enterprise.context.spi.Contextual;
 
 import org.apache.webbeans.context.creational.BeanInstanceBag;
+import org.apache.webbeans.intercept.RequestScopedBeanInterceptorHandler;
 
 /**
  * Request context implementation.
@@ -82,4 +83,11 @@ public class RequestContext extends Abst
         return propagatedSessionContext;
     }
 
+
+    @Override
+    public void destroy(Contextual<?> contextual)
+    {
+        super.destroy(contextual);
+        RequestScopedBeanInterceptorHandler.removeThreadLocals();
+    }
 }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/SessionContext.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/SessionContext.java?rev=1681656&r1=1681655&r2=1681656&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/SessionContext.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/SessionContext.java
Mon May 25 21:41:51 2015
@@ -25,6 +25,7 @@ import javax.enterprise.context.SessionS
 import javax.enterprise.context.spi.Contextual;
 
 import org.apache.webbeans.context.creational.BeanInstanceBag;
+import org.apache.webbeans.intercept.SessionScopedBeanInterceptorHandler;
 
 /**
  * Session context implementation.
@@ -44,4 +45,10 @@ public class SessionContext extends Pass
         componentInstanceMap = new ConcurrentHashMap<Contextual<?>, BeanInstanceBag<?>>();
     }
 
+    @Override
+    public void destroy(Contextual<?> contextual)
+    {
+        super.destroy(contextual);
+        SessionScopedBeanInterceptorHandler.removeThreadLocals();
+    }
 }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/se/DefaultContextsService.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/se/DefaultContextsService.java?rev=1681656&r1=1681655&r2=1681656&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/se/DefaultContextsService.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/se/DefaultContextsService.java
Mon May 25 21:41:51 2015
@@ -42,6 +42,8 @@ import org.apache.webbeans.context.Reque
 import org.apache.webbeans.context.SessionContext;
 import org.apache.webbeans.context.SingletonContext;
 import org.apache.webbeans.conversation.ConversationManager;
+import org.apache.webbeans.intercept.RequestScopedBeanInterceptorHandler;
+import org.apache.webbeans.intercept.SessionScopedBeanInterceptorHandler;
 
 
 public class DefaultContextsService extends AbstractContextsService
@@ -193,6 +195,7 @@ public class DefaultContextsService exte
         if (requestCtx != null)
         {
             requestCtx.destroy();
+            RequestScopedBeanInterceptorHandler.removeThreadLocals();
             requestContext.set(null);
             requestContext.remove();
         }
@@ -201,6 +204,7 @@ public class DefaultContextsService exte
         if (sessionCtx != null)
         {
             sessionCtx.destroy();
+            SessionScopedBeanInterceptorHandler.removeThreadLocals();
             sessionContext.set(null);
             sessionContext.remove();
         }
@@ -406,6 +410,7 @@ public class DefaultContextsService exte
 
         requestContext.set(null);
         requestContext.remove();
+        RequestScopedBeanInterceptorHandler.removeThreadLocals();
         webBeansContext.getBeanManagerImpl().fireContextLifecyleEvent(
             new Object(), DestroyedLiteral.INSTANCE_REQUEST_SCOPED);
     }
@@ -420,6 +425,7 @@ public class DefaultContextsService exte
 
         sessionContext.set(null);
         sessionContext.remove();
+        SessionScopedBeanInterceptorHandler.removeThreadLocals();
         webBeansContext.getBeanManagerImpl().fireContextLifecyleEvent(
             new Object(), DestroyedLiteral.INSTANCE_SESSION_SCOPED);
     }

Copied: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/RequestScopedBeanInterceptorHandler.java
(from r1681588, openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/intercept/RequestScopedBeanInterceptorHandler.java)
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/RequestScopedBeanInterceptorHandler.java?p2=openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/RequestScopedBeanInterceptorHandler.java&p1=openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/intercept/RequestScopedBeanInterceptorHandler.java&r1=1681588&r2=1681656&rev=1681656&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/intercept/RequestScopedBeanInterceptorHandler.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/RequestScopedBeanInterceptorHandler.java
Mon May 25 21:41:51 2015
@@ -16,9 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.webbeans.web.intercept;
-
-import org.apache.webbeans.intercept.NormalScopedBeanInterceptorHandler;
+package org.apache.webbeans.intercept;
 
 import javax.enterprise.inject.spi.Bean;
 import javax.enterprise.inject.spi.BeanManager;

Added: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/SessionScopedBeanInterceptorHandler.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/SessionScopedBeanInterceptorHandler.java?rev=1681656&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/SessionScopedBeanInterceptorHandler.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/SessionScopedBeanInterceptorHandler.java
Mon May 25 21:41:51 2015
@@ -0,0 +1,83 @@
+/*
+ * 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.
+ */
+package org.apache.webbeans.intercept;
+
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+import java.util.HashMap;
+
+
+/**
+ * <p>This is a {@link javax.inject.Provider} especially
+ * made for &#064;SessionScoped beans used in web applications.</p>
+ * 
+ * <p>Since there is only one single contextual instance of an &#064;SessionScoped
bean per thread,
+ * we can simply cache this instance inside our bean. We only need to reload this instance
+ * if it is null or if the thread ends.</p>
+ */
+public class SessionScopedBeanInterceptorHandler extends NormalScopedBeanInterceptorHandler
+{
+    /**default serial id*/
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * Cached bean instance for each thread
+     */
+    private static ThreadLocal<HashMap<Bean<?>, Object>> cachedInstances
= new ThreadLocal<HashMap<Bean<?>, Object>>();
+
+
+    public static void removeThreadLocals()
+    {
+        cachedInstances.set(null);
+        cachedInstances.remove();
+    }
+
+    /**
+     * Creates a new handler.
+     */
+    public SessionScopedBeanInterceptorHandler(BeanManager beanManager, Bean<?> bean)
+    {
+        super(beanManager, bean);
+    }
+    
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected Object getContextualInstance()
+    {
+        HashMap<Bean<?>, Object> beanMap = cachedInstances.get();
+        if (beanMap == null)
+        {
+            beanMap = new HashMap<Bean<?>, Object>();
+            cachedInstances.set(beanMap);
+        }
+
+        Object cachedInstance = beanMap.get(bean);
+        if (cachedInstance == null)
+        {
+
+            cachedInstance = super.getContextualInstance();
+            beanMap.put(bean, cachedInstance);
+        }
+
+        return cachedInstance;
+    }
+
+}

Propchange: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/SessionScopedBeanInterceptorHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: openwebbeans/trunk/webbeans-impl/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/resources/META-INF/openwebbeans/openwebbeans.properties?rev=1681656&r1=1681655&r2=1681656&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
Mon May 25 21:41:51 2015
@@ -122,6 +122,10 @@ org.apache.webbeans.useBDABeansXMLScanne
 #
 # org.apache.webbeans.proxy.mapping.javax.enterprise.context.RequestScoped=org.apache.webbeans.intercept.NormalScopedBeanInterceptorHandler
 org.apache.webbeans.proxy.mapping.javax.enterprise.context.ApplicationScoped=org.apache.webbeans.intercept.ApplicationScopedBeanInterceptorHandler
+org.apache.webbeans.proxy.mapping.javax.enterprise.context.RequestScoped=org.apache.webbeans.intercept.RequestScopedBeanInterceptorHandler
+org.apache.webbeans.proxy.mapping.javax.enterprise.context.SessionScoped=org.apache.webbeans.intercept.SessionScopedBeanInterceptorHandler
+################################################################################################
+
 ################################################################################################
 
 ############################ Eager Session Initialisation ######################################

Modified: 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=1681656&r1=1681655&r2=1681656&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-tck/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
(original)
+++ openwebbeans/trunk/webbeans-tck/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
Mon May 25 21:41:51 2015
@@ -33,5 +33,5 @@ org.apache.webbeans.spi.ConversationServ
 org.apache.webbeans.application.supportsConversation=true
 
 
-# we have to switch back to the un-cached version of the normal scoping handler 
+# 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

Modified: openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/context/WebContextsService.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/context/WebContextsService.java?rev=1681656&r1=1681655&r2=1681656&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/context/WebContextsService.java
(original)
+++ openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/context/WebContextsService.java
Mon May 25 21:41:51 2015
@@ -33,8 +33,9 @@ import org.apache.webbeans.context.Singl
 import org.apache.webbeans.conversation.ConversationManager;
 import org.apache.webbeans.el.ELContextStore;
 import org.apache.webbeans.event.NotificationManager;
+import org.apache.webbeans.intercept.SessionScopedBeanInterceptorHandler;
 import org.apache.webbeans.logger.WebBeansLoggerFacade;
-import org.apache.webbeans.web.intercept.RequestScopedBeanInterceptorHandler;
+import org.apache.webbeans.intercept.RequestScopedBeanInterceptorHandler;
 
 import javax.enterprise.context.ApplicationScoped;
 import javax.enterprise.context.ContextException;
@@ -436,6 +437,10 @@ public class WebContextsService extends
                 payload != null ? payload : new Object(), DestroyedLiteral.INSTANCE_REQUEST_SCOPED);
         }
 
+        // clean the proxy cache ThreadLocals
+        RequestScopedBeanInterceptorHandler.removeThreadLocals();
+        SessionScopedBeanInterceptorHandler.removeThreadLocals();
+
         //Clear thread locals
         conversationContexts.set(null);
         conversationContexts.remove();
@@ -548,6 +553,7 @@ public class WebContextsService extends
             }
         }
 
+        SessionScopedBeanInterceptorHandler.removeThreadLocals();
     }
 
 

Modified: openwebbeans/trunk/webbeans-web/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-web/src/main/resources/META-INF/openwebbeans/openwebbeans.properties?rev=1681656&r1=1681655&r2=1681656&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-web/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
(original)
+++ openwebbeans/trunk/webbeans-web/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
Mon May 25 21:41:51 2015
@@ -48,13 +48,6 @@ org.apache.webbeans.spi.ContextsService=
 org.apache.webbeans.application.jsp=false
 ################################################################################################
 
-########################### Proxy Implmenentation Mapping ######################################
-# This allows mapping a Scope Annotation class to a specific InterceptorProxy which are
-# typically sub classes of NormalScopedBeanInterceptorHandler
-#
-org.apache.webbeans.proxy.mapping.javax.enterprise.context.RequestScoped=org.apache.webbeans.web.intercept.RequestScopedBeanInterceptorHandler
-################################################################################################
-
 ################################### Default Conversation Service ###############################
 # Servlet related implementation of org.apache.webbeans.corespi.ConversationService.
 # This one does support conversation propagation via cid request parameter.



Mime
View raw message