You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by st...@apache.org on 2015/05/25 22:41:26 UTC

svn commit: r1681652 - /openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/context/WebContextsService.java

Author: struberg
Date: Mon May 25 20:41:25 2015
New Revision: 1681652

URL: http://svn.apache.org/r1681652
Log:
OWB-1044 improve lifecycle event caching even further

We cache RequestScoped even more agressively as this gets used
even for resource requests

Modified:
    openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/context/WebContextsService.java

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=1681652&r1=1681651&r2=1681652&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 20:41:25 2015
@@ -32,6 +32,7 @@ import org.apache.webbeans.context.Sessi
 import org.apache.webbeans.context.SingletonContext;
 import org.apache.webbeans.conversation.ConversationManager;
 import org.apache.webbeans.el.ELContextStore;
+import org.apache.webbeans.event.NotificationManager;
 import org.apache.webbeans.logger.WebBeansLoggerFacade;
 import org.apache.webbeans.web.intercept.RequestScopedBeanInterceptorHandler;
 
@@ -96,6 +97,7 @@ public class WebContextsService extends
     protected Pattern eagerSessionPattern = null;
 
 
+    protected Boolean fireRequestLifecycleEvents = null;
 
     /**
      * Creates a new instance.
@@ -359,8 +361,11 @@ public class WebContextsService extends
                 }
             }
         }
-        webBeansContext.getBeanManagerImpl().fireContextLifecyleEvent(
-            payload != null ? payload : new Object(), InitializedLiteral.INSTANCE_REQUEST_SCOPED);
+        if (shouldFireRequestLifecycleEvents())
+        {
+            webBeansContext.getBeanManagerImpl().fireContextLifecyleEvent(
+                payload != null ? payload : new Object(), InitializedLiteral.INSTANCE_REQUEST_SCOPED);
+        }
     }
 
     protected boolean shouldEagerlyInitializeSession(HttpServletRequest request)
@@ -419,14 +424,17 @@ public class WebContextsService extends
             elStore.destroyELContextStore();
         }
 
-        Object payload = null;
-
-        if (endObject != null && endObject instanceof ServletRequestEvent)
+        if (shouldFireRequestLifecycleEvents())
         {
-            payload = ((ServletRequestEvent) endObject).getServletRequest();
+            Object payload = null;
+
+            if (endObject != null && endObject instanceof ServletRequestEvent)
+            {
+                payload = ((ServletRequestEvent) endObject).getServletRequest();
+            }
+            webBeansContext.getBeanManagerImpl().fireContextLifecyleEvent(
+                payload != null ? payload : new Object(), DestroyedLiteral.INSTANCE_REQUEST_SCOPED);
         }
-        webBeansContext.getBeanManagerImpl().fireContextLifecyleEvent(
-            payload != null ? payload : new Object(), DestroyedLiteral.INSTANCE_REQUEST_SCOPED);
 
         //Clear thread locals
         conversationContexts.set(null);
@@ -753,6 +761,18 @@ public class WebContextsService extends
         return conversationContext;
     }
 
+    protected boolean shouldFireRequestLifecycleEvents()
+    {
+        if (fireRequestLifecycleEvents == null)
+        {
+            NotificationManager notificationManager = webBeansContext.getBeanManagerImpl().getNotificationManager();
+            fireRequestLifecycleEvents
+                = notificationManager.hasContextLifecycleObserver(InitializedLiteral.INSTANCE_REQUEST_SCOPED) ||
+                  notificationManager.hasContextLifecycleObserver(DestroyedLiteral.INSTANCE_REQUEST_SCOPED);
+        }
+
+        return fireRequestLifecycleEvents;
+    }
 
 
     /**