openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1151137 - in /openwebbeans/trunk: samples/ samples/jsf2sample/ samples/jsf2sample/src/main/webapp/ samples/jsf2sample/src/main/webapp/WEB-INF/ webbeans-impl/src/main/java/org/apache/webbeans/intercept/ webbeans-impl/src/main/resources/META...
Date Tue, 26 Jul 2011 15:32:36 GMT
Author: struberg
Date: Tue Jul 26 15:32:32 2011
New Revision: 1151137

URL: http://svn.apache.org/viewvc?rev=1151137&view=rev
Log:
OWB-594 create a configurable mapping Scope->ProxyMethodHandlerImplementation

This allows us to have a plugable ProxyMethodHandler mechanism.
E.g. in an EAR or enterprise server scenario, we can use a non-cached
or request-cached ProxyHandler for @ApplicationScoped beans. Wheras
in pure Servlet environments we can use one that caches fully per web application.

Added:
    openwebbeans/trunk/samples/jsf2sample/src/main/webapp/index.html   (props changed)
      - copied unchanged from r1150863, openwebbeans/trunk/samples/jsf2sample/src/main/webapp/index.jsp
    openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/intercept/
    openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/intercept/RequestScopedBeanInterceptorHandler.java
      - copied, changed from r1150947, openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/ApplicationScopedBeanInterceptorHandler.java
    openwebbeans/trunk/webbeans-web/src/test/java/org/
    openwebbeans/trunk/webbeans-web/src/test/java/org/apache/
    openwebbeans/trunk/webbeans-web/src/test/java/org/apache/webbeans/
    openwebbeans/trunk/webbeans-web/src/test/java/org/apache/webbeans/web/
    openwebbeans/trunk/webbeans-web/src/test/java/org/apache/webbeans/web/tests/
    openwebbeans/trunk/webbeans-web/src/test/java/org/apache/webbeans/web/tests/interceptor/
    openwebbeans/trunk/webbeans-web/src/test/java/org/apache/webbeans/web/tests/interceptor/CachedInterceptorHandlerTest.java
      - copied, changed from r1150863, openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/business/tests/InterceptorPerformanceTest.java
    openwebbeans/trunk/webbeans-web/src/test/java/org/apache/webbeans/web/tests/interceptor/MockServletContext.java
    openwebbeans/trunk/webbeans-web/src/test/java/org/apache/webbeans/web/tests/interceptor/MockServletRequest.java
    openwebbeans/trunk/webbeans-web/src/test/resources/
    openwebbeans/trunk/webbeans-web/src/test/resources/META-INF/
    openwebbeans/trunk/webbeans-web/src/test/resources/META-INF/openwebbeans/
    openwebbeans/trunk/webbeans-web/src/test/resources/META-INF/openwebbeans/openwebbeans.properties
      - copied, changed from r1150863, openwebbeans/trunk/webbeans-web/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
Removed:
    openwebbeans/trunk/samples/jsf2sample/src/main/webapp/index.jsp
Modified:
    openwebbeans/trunk/samples/jsf2sample/pom.xml
    openwebbeans/trunk/samples/jsf2sample/src/main/webapp/WEB-INF/web.xml
    openwebbeans/trunk/samples/pom.xml
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/ApplicationScopedBeanInterceptorHandler.java
    openwebbeans/trunk/webbeans-impl/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
    openwebbeans/trunk/webbeans-impl/src/test/resources/META-INF/openwebbeans/openwebbeans.properties
    openwebbeans/trunk/webbeans-web/pom.xml
    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/samples/jsf2sample/pom.xml
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/samples/jsf2sample/pom.xml?rev=1151137&r1=1151136&r2=1151137&view=diff
==============================================================================
--- openwebbeans/trunk/samples/jsf2sample/pom.xml (original)
+++ openwebbeans/trunk/samples/jsf2sample/pom.xml Tue Jul 26 15:32:32 2011
@@ -70,14 +70,14 @@ under the License.
         <dependency>
             <groupId>org.apache.myfaces.core</groupId>
             <artifactId>myfaces-api</artifactId>
-            <version>2.0.0</version>
+            <version>${myfaces2.version}</version>
         </dependency>
 
         <!-- JSF Impl -->
         <dependency>
             <groupId>org.apache.myfaces.core</groupId>
             <artifactId>myfaces-impl</artifactId>
-            <version>2.0.0</version>
+            <version>${myfaces2.version}</version>
         </dependency>
 
         <!-- JSR 299 API -->

Modified: openwebbeans/trunk/samples/jsf2sample/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/samples/jsf2sample/src/main/webapp/WEB-INF/web.xml?rev=1151137&r1=1151136&r2=1151137&view=diff
==============================================================================
--- openwebbeans/trunk/samples/jsf2sample/src/main/webapp/WEB-INF/web.xml (original)
+++ openwebbeans/trunk/samples/jsf2sample/src/main/webapp/WEB-INF/web.xml Tue Jul 26 15:32:32
2011
@@ -1,43 +1,42 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!--
-	
-	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.
+    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.
 -->
 <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
-	version="2.5">
+         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
+         version="2.5">
+
+    <context-param>
+        <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
+        <param-value>.xhtml</param-value>
+    </context-param>
+
+    <listener>
+        <listener-class>
+            org.apache.webbeans.servlet.WebBeansConfigurationListener</listener-class>
+    </listener>
+
+    <servlet>
+        <servlet-name>Faces Servlet</servlet-name>
+        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
+        <load-on-startup>1</load-on-startup>
+    </servlet>
 
-	<context-param>
-		<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
-		<param-value>.xhtml</param-value>
-	</context-param>
-
-	<listener>
-		<listener-class>
-			org.apache.webbeans.servlet.WebBeansConfigurationListener</listener-class>
-	</listener>
-
-	<servlet>
-		<servlet-name>Faces Servlet</servlet-name>
-		<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
-		<load-on-startup>1</load-on-startup>
-	</servlet>
-	
-	<servlet-mapping>
-		<servlet-name>Faces Servlet</servlet-name>
-		<url-pattern>*.jsf</url-pattern>
-	</servlet-mapping>
+    <servlet-mapping>
+        <servlet-name>Faces Servlet</servlet-name>
+        <url-pattern>*.xhtml</url-pattern>
+    </servlet-mapping>
 
-</web-app>
\ No newline at end of file
+</web-app>

Propchange: openwebbeans/trunk/samples/jsf2sample/src/main/webapp/index.html
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: openwebbeans/trunk/samples/pom.xml
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/samples/pom.xml?rev=1151137&r1=1151136&r2=1151137&view=diff
==============================================================================
--- openwebbeans/trunk/samples/pom.xml (original)
+++ openwebbeans/trunk/samples/pom.xml Tue Jul 26 15:32:32 2011
@@ -27,11 +27,15 @@ under the License.
     </parent>
 
     <artifactId>samples</artifactId>
-  <version> 1.1.1-SNAPSHOT</version>
+    <version> 1.1.1-SNAPSHOT</version>
     <packaging>pom</packaging>
     <name>OWB Samples</name>
     <description>Apache OpenWebBeans Samples contains samples project for openwebbeans.</description>
 
+    <properties>
+        <myfaces2.version>2.0.7</myfaces2.version>
+    </properties>
+
     <build>
         <plugins>
             <plugin>

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=1151137&r1=1151136&r2=1151137&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
Tue Jul 26 15:32:32 2011
@@ -44,6 +44,11 @@ public class ApplicationScopedBeanInterc
      * shared instances which span over multiple web-apps.
      */
     private transient Object cachedInstance = null;
+
+    /**
+     * We also cache the CreationalContext of the very bean.
+     */
+    private transient CreationalContext<Object> creationalContext = null;
     
     /**
      * Creates a new handler.
@@ -67,4 +72,15 @@ public class ApplicationScopedBeanInterc
         
         return cachedInstance;
     }
+
+    @Override
+    protected CreationalContext<Object> getContextualCreationalContext()
+    {
+        if (creationalContext == null)
+        {
+            creationalContext = super.getContextualCreationalContext();
+        }
+
+        return creationalContext;
+    }
 }

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=1151137&r1=1151136&r2=1151137&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
Tue Jul 26 15:32:32 2011
@@ -115,7 +115,6 @@ org.apache.webbeans.javassist.useClassLo
 # 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.intercept.NormalScopedBeanInterceptorHandler
+# 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
-
 ################################################################################################

Modified: openwebbeans/trunk/webbeans-impl/src/test/resources/META-INF/openwebbeans/openwebbeans.properties
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/resources/META-INF/openwebbeans/openwebbeans.properties?rev=1151137&r1=1151136&r2=1151137&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/resources/META-INF/openwebbeans/openwebbeans.properties
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/resources/META-INF/openwebbeans/openwebbeans.properties
Tue Jul 26 15:32:32 2011
@@ -15,15 +15,11 @@
 #specific language governing permissions and limitations
 #under the License.
 #---------------------------------------------------------------
-# The default configuration for OpenWebBeans
-#
-# The default configuration is intended for a JDK and a simple ServletContainer
-# like jetty, resin or tomcat.
-# 
+# The configuration for OpenWebBeans internal tests
 #---------------------------------------------------------------
 
 #general configuration section
-
+configuration.ordinal=11
 
 # the service section:
 # The key is the Interface, the value the implementation of the service

Modified: openwebbeans/trunk/webbeans-web/pom.xml
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-web/pom.xml?rev=1151137&r1=1151136&r2=1151137&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-web/pom.xml (original)
+++ openwebbeans/trunk/webbeans-web/pom.xml Tue Jul 26 15:32:32 2011
@@ -60,6 +60,14 @@
         </dependency>
 
         <dependency>
+            <groupId>org.apache.openwebbeans</groupId>
+            <artifactId>openwebbeans-impl</artifactId>
+            <version>${project.version}</version>
+            <classifier>tests</classifier>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
             <groupId>org.apache.geronimo.specs</groupId>
             <artifactId>geronimo-jsp_2.1_spec</artifactId>
             <optional>true</optional>
@@ -82,6 +90,11 @@
             <optional>true</optional>
         </dependency>
 
+        <dependency>
+            <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-interceptor_1.1_spec</artifactId>
+            <optional>true</optional>
+        </dependency>
 
     </dependencies>
     

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=1151137&r1=1151136&r2=1151137&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
Tue Jul 26 15:32:32 2011
@@ -31,6 +31,7 @@ import org.apache.webbeans.conversation.
 import org.apache.webbeans.el.ELContextStore;
 import org.apache.webbeans.logger.WebBeansLogger;
 import org.apache.webbeans.spi.FailOverService;
+import org.apache.webbeans.web.intercept.RequestScopedBeanInterceptorHandler;
 
 import javax.enterprise.context.ApplicationScoped;
 import javax.enterprise.context.ContextException;
@@ -115,6 +116,7 @@ public class WebContextsService extends 
         applicationContext.remove();
         conversationContext.remove();
         singletonContext.remove();
+        RequestScopedBeanInterceptorHandler.removeThreadLocals();
     }
     
     /**
@@ -708,4 +710,4 @@ public class WebContextsService extends 
         }
         return webContext;
     }
-}
\ No newline at end of file
+}

Copied: openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/intercept/RequestScopedBeanInterceptorHandler.java
(from r1150947, openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/ApplicationScopedBeanInterceptorHandler.java)
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/intercept/RequestScopedBeanInterceptorHandler.java?p2=openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/intercept/RequestScopedBeanInterceptorHandler.java&p1=openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/ApplicationScopedBeanInterceptorHandler.java&r1=1150947&r2=1151137&rev=1151137&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/ApplicationScopedBeanInterceptorHandler.java
(original)
+++ openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/intercept/RequestScopedBeanInterceptorHandler.java
Tue Jul 26 15:32:32 2011
@@ -16,41 +16,46 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.webbeans.intercept;
-
-import javax.enterprise.context.spi.CreationalContext;
+package org.apache.webbeans.web.intercept;
 
 import org.apache.webbeans.component.OwbBean;
+import org.apache.webbeans.intercept.NormalScopedBeanInterceptorHandler;
+
+import javax.enterprise.context.spi.CreationalContext;
+import java.util.HashMap;
 
 
 /**
  * <p>This is a {@link javassist.util.proxy.MethodHandler} especially
- * made for &#064;ApplicationScoped beans.</p>
+ * made for &#064;RequestScoped beans used in web applications.</p>
  * 
- * <p>Since there is only one single contextual instance of an &#064;ApplicationScoped
bean,
+ * <p>Since there is only one single contextual instance of an &#064;RequestScoped
bean per thread,
  * 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>

+ * if it is null or if the thread ends.</p>
  */
-public class ApplicationScopedBeanInterceptorHandler extends NormalScopedBeanInterceptorHandler
+public class RequestScopedBeanInterceptorHandler extends NormalScopedBeanInterceptorHandler
 {
     /**default serial id*/
     private static final long serialVersionUID = 1L;
 
     /**
-     * Cached bean instance. Please note that it is only allowed to
-     * use this special proxy if you don't use OpenWebBeans in an EAR
-     * scenario. In this case we must not cache &#064;ApplicationScoped
-     * contextual instances because they could be injected into EJBs or other
-     * shared instances which span over multiple web-apps.
+     * Cached bean instance for each thread
      */
-    private transient Object cachedInstance = null;
-    
+    private static ThreadLocal<HashMap<OwbBean<?>, CacheEntry>> cachedInstances
= new ThreadLocal<HashMap<OwbBean<?>, CacheEntry>>();
+
+
+    public static void removeThreadLocals()
+    {
+        cachedInstances.set(null);
+        cachedInstances.remove();
+    }
+
     /**
      * Creates a new handler.
      * @param bean bean
      * @param creationalContext creaitonal context
      */
-    public ApplicationScopedBeanInterceptorHandler(OwbBean<?> bean, CreationalContext<?>
creationalContext)
+    public RequestScopedBeanInterceptorHandler(OwbBean<?> bean, CreationalContext<?>
creationalContext)
     {
         super(bean, creationalContext);
     }
@@ -60,11 +65,46 @@ public class ApplicationScopedBeanInterc
      */
     protected Object getContextualInstance()
     {
-        if (cachedInstance == null) 
+        HashMap<OwbBean<?>, CacheEntry> beanMap = cachedInstances.get();
+        if (beanMap == null)
+        {
+            beanMap = new HashMap<OwbBean<?>, CacheEntry>();
+            cachedInstances.set(beanMap);
+        }
+
+        CacheEntry cachedEntry = beanMap.get(bean);
+        if (cachedEntry == null)
         {
-            cachedInstance = super.getContextualInstance();
+            cachedEntry = new CacheEntry();
+            cachedEntry.creationalContext = super.getContextualCreationalContext();
+            cachedEntry.instance = super.getContextualInstance();
+            beanMap.put(bean, cachedEntry);
         }
-        
-        return cachedInstance;
+
+        return cachedEntry.instance;
+    }
+
+    protected CreationalContext<Object> getContextualCreationalContext()
+    {
+        HashMap<OwbBean<?>, CacheEntry> beanMap = cachedInstances.get();
+        if (beanMap != null)
+        {
+            CacheEntry cachedEntry = beanMap.get(bean);
+            if (cachedEntry != null)
+            {
+                return cachedEntry.creationalContext;
+            }
+        }
+
+        return super.getContextualCreationalContext();
+    }
+
+    /**
+     * This will store the cached contextual instance and it's CreationalContext
+     */
+    private static final class CacheEntry
+    {
+        CreationalContext<Object> creationalContext;
+        Object instance;
     }
 }

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=1151137&r1=1151136&r2=1151137&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
Tue Jul 26 15:32:32 2011
@@ -15,11 +15,7 @@
 #specific language governing permissions and limitations
 #under the License.
 #---------------------------------------------------------------
-# The default configuration for OpenWebBeans
-#
-# The default configuration is intended for a JDK and a simple ServletContainer
-# like jetty, resin or tomcat.
-# 
+# The configuration for OpenWebBeans Web container integration
 #---------------------------------------------------------------
 
 ################################################################################################
@@ -67,3 +63,10 @@ org.apache.webbeans.spi.FailOverService=
 org.apache.webbeans.web.failover.issupportfailover=false
 org.apache.webbeans.web.failover.issupportpassivation=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
+################################################################################################

Copied: openwebbeans/trunk/webbeans-web/src/test/java/org/apache/webbeans/web/tests/interceptor/CachedInterceptorHandlerTest.java
(from r1150863, openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/business/tests/InterceptorPerformanceTest.java)
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-web/src/test/java/org/apache/webbeans/web/tests/interceptor/CachedInterceptorHandlerTest.java?p2=openwebbeans/trunk/webbeans-web/src/test/java/org/apache/webbeans/web/tests/interceptor/CachedInterceptorHandlerTest.java&p1=openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/business/tests/InterceptorPerformanceTest.java&r1=1150863&r2=1151137&rev=1151137&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/business/tests/InterceptorPerformanceTest.java
(original)
+++ openwebbeans/trunk/webbeans-web/src/test/java/org/apache/webbeans/web/tests/interceptor/CachedInterceptorHandlerTest.java
Tue Jul 26 15:32:32 2011
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.webbeans.newtests.interceptors.business.tests;
+package org.apache.webbeans.web.tests.interceptor;
 
 import junit.framework.Assert;
 import org.apache.webbeans.config.WebBeansContext;
@@ -27,8 +27,10 @@ import org.apache.webbeans.newtests.inte
 import org.apache.webbeans.newtests.interceptors.common.TransactionInterceptor;
 import org.junit.Test;
 
+import javax.enterprise.context.RequestScoped;
 import javax.enterprise.context.spi.CreationalContext;
 import javax.enterprise.inject.spi.Bean;
+import javax.servlet.ServletRequestEvent;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Set;
@@ -38,119 +40,72 @@ import java.util.Set;
  * It is usually enabled with only a few iteration cycles.
  */
 @SuppressWarnings("unchecked")
-public class InterceptorPerformanceTest extends AbstractUnitTest
+public class CachedInterceptorHandlerTest extends AbstractUnitTest
 {
-    private static final String PACKAGE_NAME = DependingInterceptorTest.class.getPackage().getName();
 
-    private static final int ITERATIONS = 700;
-    private static final int NUM_THREADS = 50;
+    private static final int ITERATIONS = 100000;
 
-    private static WebBeansLogger logger = WebBeansLogger.getLogger(InterceptorPerformanceTest.class);
+    private static WebBeansLogger logger = WebBeansLogger.getLogger(CachedInterceptorHandlerTest.class);
 
 
     @Test
     public void testInterceptorPerformance() throws Exception
     {
-        Collection<String> beanXmls = new ArrayList<String>();
-        beanXmls.add(getXmlPath(PACKAGE_NAME, "DependingInterceptorTest"));
-
         Collection<Class<?>> beanClasses = new ArrayList<Class<?>>();
-        beanClasses.add(TransactionInterceptor.class);
         beanClasses.add(ApplicationScopedBean.class);
         beanClasses.add(RequestScopedBean.class);
 
         TransactionInterceptor.count = 0;
 
-        startContainer(beanClasses, beanXmls);
+        startContainer(beanClasses, null);
 
-        long start = System.nanoTime();
+        MockServletContext mockServletContext = new MockServletContext();
+        MockServletRequest mockServletRequest = new MockServletRequest();
+        ServletRequestEvent servletRequestEvent = new ServletRequestEvent(mockServletContext,
mockServletRequest);
 
-        //X TODO START THREADS
-        CalculationRunner[] threads = new CalculationRunner[NUM_THREADS];
-        for (int i= 0 ; i < NUM_THREADS; i++)
-        {
-            threads[i] = new CalculationRunner("t" + i);
-            threads[i].start();
-        }
 
-        for (int i= 0 ; i < NUM_THREADS; i++)
-        {
-            threads[i].join();
-            Assert.assertFalse(threads[i].isFailed());
-        }
-
-
-        long end = System.nanoTime();
-
-        logger.info("Executing {0} iterations took {1} ns", ITERATIONS, end - start);
 
-        shutDownContainer();
+        long start = System.nanoTime();
 
-        if ((end - start) / 1e6 > ITERATIONS*10)
+        for (int req = 0; req < 10; req++)
         {
-            // if it takes longer than 1ms for each iteration, then this is really a performance
blocker! 
-            Assert.fail("Performance test took more than 20 times longer than it should");
-        }
+            getWebBeansContext().getContextsService().startContext(RequestScoped.class, servletRequestEvent);
 
-    }
+            Set<Bean<?>> beans = getBeanManager().getBeans(RequestScopedBean.class);
+            Assert.assertNotNull(beans);
+            Bean<RequestScopedBean> bean = (Bean<RequestScopedBean>)beans.iterator().next();
 
-    public class CalculationRunner extends Thread
-    {
-        private String threadName;
+            CreationalContext<RequestScopedBean> ctx = getBeanManager().createCreationalContext(bean);
 
-        private boolean failed = false;
+            Object reference1 = getBeanManager().getReference(bean, RequestScopedBean.class,
ctx);
+            Assert.assertNotNull(reference1);
 
-        public CalculationRunner(String name)
-        {
-            super(name);
-            threadName = name;
-        }
+            Assert.assertTrue(reference1 instanceof RequestScopedBean);
 
-        public boolean isFailed() {
-            return failed;
-        }
-
-        @Override
-        public void run()
-        {
-            try
-            {
-                for (int req = 0; req < 5; req++)
-                {
-                    WebBeansContext.currentInstance().getContextFactory().initRequestContext(null);
-
-                    Set<Bean<?>> beans = getBeanManager().getBeans(RequestScopedBean.class);
-                    Assert.assertNotNull(beans);
-                    Bean<RequestScopedBean> bean = (Bean<RequestScopedBean>)beans.iterator().next();
+            RequestScopedBean beanInstance1 = (RequestScopedBean)reference1;
 
-                    CreationalContext<RequestScopedBean> ctx = getBeanManager().createCreationalContext(bean);
+            TransactionInterceptor.count = 0;
 
-                    Object reference1 = getBeanManager().getReference(bean, RequestScopedBean.class,
ctx);
-                    Assert.assertNotNull(reference1);
-
-                    Assert.assertTrue(reference1 instanceof RequestScopedBean);
+            for (int i= 1; i < ITERATIONS; i++)
+            {
+                beanInstance1.getMyService();
+            }
 
-                    RequestScopedBean beanInstance1 = (RequestScopedBean)reference1;
+            getWebBeansContext().getContextsService().endContext(RequestScoped.class, servletRequestEvent);
+        }
 
-                    TransactionInterceptor.count = 0;
+        long end = System.nanoTime();
 
-                    long start = System.nanoTime();
+        logger.info("Executing {0} iterations took {1} ns", ITERATIONS, end - start);
 
-                    long startDek = start;
-                    for (int i= 1; i < ITERATIONS; i++)
-                    {
-                        beanInstance1.getMyService().getJ();
-                    }
+        shutDownContainer();
 
-                    WebBeansContext.currentInstance().getContextFactory().destroyRequestContext(null);
-                }
-            }
-            catch (Exception e)
-            {
-                logger.error("Concurrency problem in InterceptorPerformanceTest detected
in thread " + threadName, e);
-                failed = true;
-            }
+        if ((end - start) / 1e6 > ITERATIONS*10)
+        {
+            // if it takes longer than 1ms for each iteration, then this is really a performance
blocker! 
+            Assert.fail("Performance test took more than 20 times longer than it should");
         }
+
     }
 
-}
\ No newline at end of file
+}

Added: openwebbeans/trunk/webbeans-web/src/test/java/org/apache/webbeans/web/tests/interceptor/MockServletContext.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-web/src/test/java/org/apache/webbeans/web/tests/interceptor/MockServletContext.java?rev=1151137&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-web/src/test/java/org/apache/webbeans/web/tests/interceptor/MockServletContext.java
(added)
+++ openwebbeans/trunk/webbeans-web/src/test/java/org/apache/webbeans/web/tests/interceptor/MockServletContext.java
Tue Jul 26 15:32:32 2011
@@ -0,0 +1,180 @@
+/*
+ * 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.web.tests.interceptor;
+
+import javax.servlet.RequestDispatcher;
+import javax.servlet.Servlet;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.Set;
+
+/**
+ * @author <a href="mailto:struberg@yahoo.de">Mark Struberg</a>
+ */
+public class MockServletContext implements ServletContext
+{
+    @Override
+    public Object getAttribute(String name)
+    {
+        return null;
+    }
+
+    @Override
+    public ServletContext getContext(String uripath)
+    {
+        return null;
+    }
+
+    @Override
+    public String getContextPath()
+    {
+        return null;
+    }
+
+    @Override
+    public int getMajorVersion()
+    {
+        return 0;
+    }
+
+    @Override
+    public int getMinorVersion()
+    {
+        return 0;
+    }
+
+    @Override
+    public String getMimeType(String file)
+    {
+        return null;
+    }
+
+    @Override
+    public Set getResourcePaths(String path)
+    {
+        return null;
+    }
+
+    @Override
+    public URL getResource(String path) throws MalformedURLException
+    {
+        return null;
+    }
+
+    @Override
+    public InputStream getResourceAsStream(String path)
+    {
+        return null;
+    }
+
+    @Override
+    public RequestDispatcher getRequestDispatcher(String path)
+    {
+        return null;
+    }
+
+    @Override
+    public RequestDispatcher getNamedDispatcher(String name)
+    {
+        return null;
+    }
+
+    @Override
+    public Servlet getServlet(String name) throws ServletException
+    {
+        return null;
+    }
+
+    @Override
+    public Enumeration getServlets()
+    {
+        return null;
+    }
+
+    @Override
+    public Enumeration getServletNames()
+    {
+        return null;
+    }
+
+    @Override
+    public void log(String msg)
+    {
+    }
+
+    @Override
+    public void log(Exception exception, String msg)
+    {
+    }
+
+    @Override
+    public void log(String message, Throwable throwable)
+    {
+    }
+
+    @Override
+    public String getRealPath(String path)
+    {
+        return null;
+    }
+
+    @Override
+    public String getServerInfo()
+    {
+        return null;
+    }
+
+    @Override
+    public String getInitParameter(String name)
+    {
+        return null;
+    }
+
+    @Override
+    public Enumeration getInitParameterNames()
+    {
+        return null;
+    }
+
+    @Override
+    public Enumeration getAttributeNames()
+    {
+        return null;
+    }
+
+    @Override
+    public void setAttribute(String name, Object object)
+    {
+    }
+
+    @Override
+    public void removeAttribute(String name)
+    {
+    }
+
+    @Override
+    public String getServletContextName()
+    {
+        return null;
+    }
+}

Added: openwebbeans/trunk/webbeans-web/src/test/java/org/apache/webbeans/web/tests/interceptor/MockServletRequest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-web/src/test/java/org/apache/webbeans/web/tests/interceptor/MockServletRequest.java?rev=1151137&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-web/src/test/java/org/apache/webbeans/web/tests/interceptor/MockServletRequest.java
(added)
+++ openwebbeans/trunk/webbeans-web/src/test/java/org/apache/webbeans/web/tests/interceptor/MockServletRequest.java
Tue Jul 26 15:32:32 2011
@@ -0,0 +1,360 @@
+/*
+ * 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.web.tests.interceptor;
+
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletInputStream;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.security.Principal;
+import java.util.Enumeration;
+import java.util.Locale;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:struberg@yahoo.de">Mark Struberg</a>
+ */
+public class MockServletRequest implements HttpServletRequest
+{
+
+    @Override
+    public Object getAttribute(String name)
+    {
+        return null;
+    }
+
+    @Override
+    public Enumeration getAttributeNames()
+    {
+        return null;
+    }
+
+    @Override
+    public String getCharacterEncoding()
+    {
+        return null;
+    }
+
+    @Override
+    public void setCharacterEncoding(String env) throws UnsupportedEncodingException
+    {
+    }
+
+    @Override
+    public int getContentLength()
+    {
+        return 0;
+    }
+
+    @Override
+    public String getContentType()
+    {
+        return null;
+    }
+
+    @Override
+    public ServletInputStream getInputStream() throws IOException
+    {
+        return null;
+    }
+
+    @Override
+    public String getParameter(String name)
+    {
+        return null;
+    }
+
+    @Override
+    public Enumeration getParameterNames()
+    {
+        return null;
+    }
+
+    @Override
+    public String[] getParameterValues(String name)
+    {
+        return new String[0];
+    }
+
+    @Override
+    public Map getParameterMap()
+    {
+        return null;
+    }
+
+    @Override
+    public String getProtocol()
+    {
+        return null;
+    }
+
+    @Override
+    public String getScheme()
+    {
+        return null;
+    }
+
+    @Override
+    public String getServerName()
+    {
+        return null;
+    }
+
+    @Override
+    public int getServerPort()
+    {
+        return 0;
+    }
+
+    @Override
+    public BufferedReader getReader() throws IOException
+    {
+        return null;
+    }
+
+    @Override
+    public String getRemoteAddr()
+    {
+        return null;
+    }
+
+    @Override
+    public String getRemoteHost()
+    {
+        return null;
+    }
+
+    @Override
+    public void setAttribute(String name, Object o)
+    {
+    }
+
+    @Override
+    public void removeAttribute(String name)
+    {
+    }
+
+    @Override
+    public Locale getLocale()
+    {
+        return null;
+    }
+
+    @Override
+    public Enumeration getLocales()
+    {
+        return null;
+    }
+
+    @Override
+    public boolean isSecure()
+    {
+        return false;
+    }
+
+    @Override
+    public RequestDispatcher getRequestDispatcher(String path)
+    {
+        return null;
+    }
+
+    @Override
+    public String getRealPath(String path)
+    {
+        return null;
+    }
+
+    @Override
+    public int getRemotePort()
+    {
+        return 0;
+    }
+
+    @Override
+    public String getLocalName()
+    {
+        return null;
+    }
+
+    @Override
+    public String getLocalAddr()
+    {
+        return null;
+    }
+
+    @Override
+    public int getLocalPort()
+    {
+        return 0;
+    }
+
+    @Override
+    public String getAuthType()
+    {
+        return null;
+    }
+
+    @Override
+    public Cookie[] getCookies()
+    {
+        return new Cookie[0];
+    }
+
+    @Override
+    public long getDateHeader(String name)
+    {
+        return 0;
+    }
+
+    @Override
+    public String getHeader(String name)
+    {
+        return null;
+    }
+
+    @Override
+    public Enumeration getHeaders(String name)
+    {
+        return null;
+    }
+
+    @Override
+    public Enumeration getHeaderNames()
+    {
+        return null;
+    }
+
+    @Override
+    public int getIntHeader(String name)
+    {
+        return 0;
+    }
+
+    @Override
+    public String getMethod()
+    {
+        return null;
+    }
+
+    @Override
+    public String getPathInfo()
+    {
+        return null;
+    }
+
+    @Override
+    public String getPathTranslated()
+    {
+        return null; 
+    }
+
+    @Override
+    public String getContextPath()
+    {
+        return null;
+    }
+
+    @Override
+    public String getQueryString()
+    {
+        return null;
+    }
+
+    @Override
+    public String getRemoteUser()
+    {
+        return null;
+    }
+
+    @Override
+    public boolean isUserInRole(String role)
+    {
+        return false;
+    }
+
+    @Override
+    public Principal getUserPrincipal()
+    {
+        return null;
+    }
+
+    @Override
+    public String getRequestedSessionId()
+    {
+        return null;
+    }
+
+    @Override
+    public String getRequestURI()
+    {
+        return null;
+    }
+
+    @Override
+    public StringBuffer getRequestURL()
+    {
+        return null;
+    }
+
+    @Override
+    public String getServletPath()
+    {
+        return null;
+    }
+
+    @Override
+    public HttpSession getSession(boolean create)
+    {
+        return null;
+    }
+
+    @Override
+    public HttpSession getSession()
+    {
+        return null;
+    }
+
+    @Override
+    public boolean isRequestedSessionIdValid()
+    {
+        return false;
+    }
+
+    @Override
+    public boolean isRequestedSessionIdFromCookie()
+    {
+        return false;
+    }
+
+    @Override
+    public boolean isRequestedSessionIdFromURL()
+    {
+        return false;
+    }
+
+    @Override
+    public boolean isRequestedSessionIdFromUrl()
+    {
+        return false;
+    }
+}

Copied: openwebbeans/trunk/webbeans-web/src/test/resources/META-INF/openwebbeans/openwebbeans.properties
(from r1150863, openwebbeans/trunk/webbeans-web/src/main/resources/META-INF/openwebbeans/openwebbeans.properties)
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-web/src/test/resources/META-INF/openwebbeans/openwebbeans.properties?p2=openwebbeans/trunk/webbeans-web/src/test/resources/META-INF/openwebbeans/openwebbeans.properties&p1=openwebbeans/trunk/webbeans-web/src/main/resources/META-INF/openwebbeans/openwebbeans.properties&r1=1150863&r2=1151137&rev=1151137&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-web/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
(original)
+++ openwebbeans/trunk/webbeans-web/src/test/resources/META-INF/openwebbeans/openwebbeans.properties
Tue Jul 26 15:32:32 2011
@@ -15,55 +15,19 @@
 #specific language governing permissions and limitations
 #under the License.
 #---------------------------------------------------------------
-# The default configuration for OpenWebBeans
-#
-# The default configuration is intended for a JDK and a simple ServletContainer
-# like jetty, resin or tomcat.
-# 
+# The configuration for OpenWebBeans Web tests
 #---------------------------------------------------------------
 
 ################################################################################################
 ################################### WEB SPI CONFIGURATION SECTION ##########################
 ################################################################################################

 
-configuration.ordinal=11
-
-################################### WEB Container Lifecycle ################################
-#Default implementation of org.apache.webbeans.corespi.ContainerLifecycle.
-org.apache.webbeans.spi.ContainerLifecycle=org.apache.webbeans.web.lifecycle.WebContainerLifecycle
-################################################################################################
-
-################################### WEB Scanner Service ####################################
-#Default implementation of org.apache.webbeans.corespi.ScannerService.
-org.apache.webbeans.spi.ScannerService=org.apache.webbeans.web.scanner.WebScannerService
-################################################################################################
-
-################################### WEB Contexts Service ####################################
-#Default implementation of org.apache.webbeans.corespi.ContextsService.
-org.apache.webbeans.spi.ContextsService=org.apache.webbeans.web.context.WebContextsService
-################################################################################################
-
-################################### Default Resource Injection Service #########################
-#Default implementation of org.apache.webbeans.corespi.ResourceInjectionService
-org.apache.webbeans.spi.ResourceInjectionService=org.apache.webbeans.resource.spi.se.StandaloneResourceInjectionService
-################################################################################################
-
-################################################################################################

-#################################### SEVERAL WEB CONFIGURATION PARAMETERS ######################
-################################################################################################
-
-################################## Application Development is JSP ##############################
-#Used to register WebBeansELResolver with JSP EL
-org.apache.webbeans.application.jsp=false
-################################################################################################
+configuration.ordinal=15
 
-################################# Application Development JSF Version is 2.0 ###################
-#Add extra extensions for JSF2, for example adding ViewScope
-org.apache.webbeans.application.useJSF2Extensions=false
+########################### Proxy Implmenentation Mapping ######################################
+# This allows mapping a Scope Annotation class to a specific InterceptorProxy which are
+# typically sub classes of NormalScopedBeanInterceptorHandler
+# We need to register this with a higher ordinal again, since webbeans-impl/tests have ordinal
11 too!
+#
+org.apache.webbeans.proxy.mapping.javax.enterprise.context.RequestScoped=org.apache.webbeans.web.intercept.RequestScopedBeanInterceptorHandler
 ################################################################################################
-
-################################ Failover Service #############################################
-org.apache.webbeans.spi.FailOverService=org.apache.webbeans.web.failover.DefaultOwbFailOverService
-org.apache.webbeans.web.failover.issupportfailover=false
-org.apache.webbeans.web.failover.issupportpassivation=false
-##############################################################################################



Mime
View raw message