openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1675996 - in /openwebbeans/trunk: ./ webbeans-clustering/ webbeans-tomcat7/src/main/java/org/apache/webbeans/web/tomcat7/ webbeans-web/src/main/java/org/apache/webbeans/servlet/ webbeans-web/src/main/java/org/apache/webbeans/web/context/
Date Sat, 25 Apr 2015 05:45:14 GMT
Author: struberg
Date: Sat Apr 25 05:45:14 2015
New Revision: 1675996

URL: http://svn.apache.org/r1675996
Log:
OWB-1048 OWB-1049 store @SessionScoped beans in real Http Session. 

And also remove the clustering module as we don't need it anymore.
The clustering is now fully a concern of the web container and not of OWB anymore.

Removed:
    openwebbeans/trunk/webbeans-clustering/
Modified:
    openwebbeans/trunk/pom.xml
    openwebbeans/trunk/webbeans-tomcat7/src/main/java/org/apache/webbeans/web/tomcat7/TomcatContainerListener.java
    openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/servlet/WebBeansConfigurationListener.java
    openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/context/SessionContextManager.java
    openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/context/WebContextsService.java

Modified: openwebbeans/trunk/pom.xml
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/pom.xml?rev=1675996&r1=1675995&r2=1675996&view=diff
==============================================================================
--- openwebbeans/trunk/pom.xml (original)
+++ openwebbeans/trunk/pom.xml Sat Apr 25 05:45:14 2015
@@ -490,7 +490,6 @@
         <module>webbeans-jms</module>       
         <module>webbeans-jsf</module>
         <module>webbeans-jsf12</module>
-        <module>webbeans-clustering</module>
         <module>webbeans-el10</module>
         <module>webbeans-el22</module>		
         <module>webbeans-resource</module>

Modified: openwebbeans/trunk/webbeans-tomcat7/src/main/java/org/apache/webbeans/web/tomcat7/TomcatContainerListener.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-tomcat7/src/main/java/org/apache/webbeans/web/tomcat7/TomcatContainerListener.java?rev=1675996&r1=1675995&r2=1675996&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-tomcat7/src/main/java/org/apache/webbeans/web/tomcat7/TomcatContainerListener.java
(original)
+++ openwebbeans/trunk/webbeans-tomcat7/src/main/java/org/apache/webbeans/web/tomcat7/TomcatContainerListener.java
Sat Apr 25 05:45:14 2015
@@ -20,19 +20,13 @@ package org.apache.webbeans.web.tomcat7;
 
 import org.apache.catalina.ContainerEvent;
 import org.apache.catalina.ContainerListener;
-import org.apache.catalina.Context;
-import org.apache.webbeans.config.WebBeansContext;
-import org.apache.webbeans.context.SessionContext;
-import org.apache.webbeans.spi.ContextsService;
-import org.apache.webbeans.web.context.SessionContextManager;
-import org.apache.webbeans.web.context.WebContextsService;
 
 /**
  * Container listener that propagates the change of a session id (e. g. during an authentication
through the container)
  * to the session context manager. Otherwise a new session context for the same session is
created, because the session
  * id is used to identify the session context. <br/> Adapted from OpenEJB tomee/tomee-catalina
and updated.
  *
- * @version $Rev$ $Date$
+ * @deprecated we do not use the sessionId anymore since owb-1.5.1, so we do not need any
sessionId change listener
  */
 public class TomcatContainerListener implements ContainerListener
 {
@@ -40,29 +34,7 @@ public class TomcatContainerListener imp
     @Override
     public void containerEvent(ContainerEvent containerEvent)
     {
-        if (Context.CHANGE_SESSION_ID_EVENT.equals(containerEvent.getType())
-                && (containerEvent.getData() instanceof String[]))
-        {
-            String[] ids = (String[]) containerEvent.getData();
-
-            if (ids.length >= 2)
-            {
-                WebBeansContext webBeansContext = WebBeansContext.currentInstance();
-                ContextsService contextsService = webBeansContext.getContextsService();
-
-                if (contextsService instanceof WebContextsService)
-                {
-                    WebContextsService webContextsService = (WebContextsService) contextsService;
-                    SessionContextManager sessionContextManager = webContextsService.getSessionContextManager();
-
-                    SessionContext sessionContext = sessionContextManager.getSessionContextWithSessionId(ids[0]);
-                    if (sessionContext != null)
-                    {
-                        sessionContextManager.removeSessionContextWithSessionId(ids[0]);
-                        sessionContextManager.addNewSessionContext(ids[1], sessionContext);
-                    }
-                }
-            }
-        }
+        // nothing to do anymore.
+        // we do not use the sessionId anymore since owb-1.5.1
     }
 }

Modified: openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/servlet/WebBeansConfigurationListener.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/servlet/WebBeansConfigurationListener.java?rev=1675996&r1=1675995&r2=1675996&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/servlet/WebBeansConfigurationListener.java
(original)
+++ openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/servlet/WebBeansConfigurationListener.java
Sat Apr 25 05:45:14 2015
@@ -23,7 +23,6 @@ import org.apache.webbeans.config.WebBea
 import org.apache.webbeans.el.ELContextStore;
 import org.apache.webbeans.logger.WebBeansLoggerFacade;
 import org.apache.webbeans.spi.ContainerLifecycle;
-import org.apache.webbeans.spi.FailOverService;
 import org.apache.webbeans.util.WebBeansUtil;
 import org.apache.webbeans.web.context.WebContextsService;
 import org.apache.webbeans.web.util.ServletCompatibilityUtil;
@@ -61,7 +60,6 @@ public class WebBeansConfigurationListen
     /**Manages the container lifecycle*/
     protected ContainerLifecycle lifeCycle = null;
 
-    protected FailOverService failoverService = null;
     private WebBeansContext webBeansContext;
 
     /**
@@ -70,7 +68,6 @@ public class WebBeansConfigurationListen
     public WebBeansConfigurationListener()
     {
         webBeansContext = WebBeansContext.getInstance();
-        failoverService = webBeansContext.getService(FailOverService.class);
     }
 
     /**

Modified: openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/context/SessionContextManager.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/context/SessionContextManager.java?rev=1675996&r1=1675995&r2=1675996&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/context/SessionContextManager.java
(original)
+++ openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/context/SessionContextManager.java
Sat Apr 25 05:45:14 2015
@@ -31,6 +31,7 @@ import org.apache.webbeans.util.Asserts;
  * </p>
  * @version $Rev$ $Date$
  *
+ * @deprecated This is NOT being used anymore by OWB! We just keep it for binary backward
compat with TomEE! We can remove it once TomEE switches to real sessions.
  */
 public class SessionContextManager
 {

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=1675996&r1=1675995&r2=1675996&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
Sat Apr 25 05:45:14 2015
@@ -33,8 +33,6 @@ import org.apache.webbeans.conversation.
 import org.apache.webbeans.conversation.ConversationManager;
 import org.apache.webbeans.el.ELContextStore;
 import org.apache.webbeans.logger.WebBeansLoggerFacade;
-import org.apache.webbeans.spi.FailOverService;
-import org.apache.webbeans.util.WebBeansUtil;
 import org.apache.webbeans.web.intercept.RequestScopedBeanInterceptorHandler;
 
 import javax.enterprise.context.ApplicationScoped;
@@ -51,10 +49,8 @@ import javax.servlet.ServletRequestEvent
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpSession;
 import java.lang.annotation.Annotation;
-import java.util.Collection;
 import java.util.Map;
 import java.util.Map.Entry;
-import java.util.concurrent.ConcurrentHashMap;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -67,6 +63,8 @@ public class WebContextsService extends
     /**Logger instance*/
     private static final Logger logger = WebBeansLoggerFacade.getLogger(WebContextsService.class);
 
+    private static final String OWB_SESSION_CONTEXT_ATTRIBUTE = "OPENWEBBEANS_SESSION_CONTEXT";
+
     /**Current request context*/
     private static ThreadLocal<RequestContext> requestContexts = null;
 
@@ -74,7 +72,7 @@ public class WebContextsService extends
     private static ThreadLocal<SessionContext> sessionContexts = null;
 
     /**
-     * This applicationContext will be used for all non servlet-request threads
+     * A single applicationContext
      */
     private ApplicationContext sharedApplicationContext ;
 
@@ -86,24 +84,11 @@ public class WebContextsService extends
     /**Current dependent context*/
     private static DependentContext dependentContext;
 
-    /**Current application contexts*/
-    private static Map<ServletContext, ApplicationContext> currentApplicationContexts
= new ConcurrentHashMap<ServletContext, ApplicationContext>();
-    
-    /**Current singleton contexts*/
-    private static Map<ServletContext, SingletonContext> currentSingletonContexts =
new ConcurrentHashMap<ServletContext, SingletonContext>();
-
-    private static Map<ClassLoader, ServletContext> classLoaderToServletContextMapping
= new ConcurrentHashMap<ClassLoader, ServletContext>();
-
-    /**Session context manager*/
-    private final SessionContextManager sessionCtxManager = new SessionContextManager();
-
     /**Conversation context manager*/
     private final ConversationManager conversationManager;
 
     private boolean supportsConversation = false;
     
-    protected FailOverService failoverService = null;
-
     private WebBeansContext webBeansContext;
 
     /**Initialize thread locals*/
@@ -136,18 +121,12 @@ public class WebContextsService extends
     {
         this.webBeansContext = webBeansContext;
         supportsConversation =  webBeansContext.getOpenWebBeansConfiguration().supportsConversation();
-        failoverService = webBeansContext.getService(FailOverService.class);
         conversationManager = webBeansContext.getConversationManager();
 
         sharedApplicationContext = new ApplicationContext();
         sharedApplicationContext.setActive(true);
     }
 
-    public SessionContextManager getSessionContextManager()
-    {
-        return sessionCtxManager;
-    }
-
     /**
      * {@inheritDoc}
      */
@@ -180,11 +159,6 @@ public class WebContextsService extends
             sharedSingletonContext.destroy();
         }
 
-        //Clear saved contexts related with 
-        //this servlet context
-        currentApplicationContexts.clear();
-        currentSingletonContexts.clear();
-        
         //Thread local values to null
         requestContexts.set(null);
         sessionContexts.set(null);
@@ -252,13 +226,7 @@ public class WebContextsService extends
         }
         else if(scopeType.equals(ApplicationScoped.class))
         {
-            ServletContext servletContext = classLoaderToServletContextMapping.get(WebBeansUtil.getCurrentClassLoader());
-
-            if (servletContext == null)
-            {
-                return null;
-            }
-            return currentApplicationContexts.get(servletContext);
+            return sharedApplicationContext;
         }
         else if(supportsConversation && scopeType.equals(ConversationScoped.class))
         {
@@ -270,13 +238,7 @@ public class WebContextsService extends
         }
         else if (scopeType.equals(Singleton.class))
         {
-            ServletContext servletContext = classLoaderToServletContextMapping.get(WebBeansUtil.getCurrentClassLoader());
-
-            if (servletContext == null)
-            {
-                return null;
-            }
-            return currentSingletonContexts.get(servletContext);
+            return sharedSingletonContext;
         }
 
         return null;
@@ -359,12 +321,6 @@ public class WebContextsService extends
                 {
                     initSessionContext(session);    
                 }
-                            
-                //Init thread local application context
-                initApplicationContext(event.getServletContext());
-                
-                //Init thread local singleton context
-                initSingletonContext(event.getServletContext());
 
                 initConversationContext(request);
 
@@ -373,11 +329,6 @@ public class WebContextsService extends
         }
         else
         {
-            //Init thread local application context
-            initApplicationContext(null);
-
-            //Init thread local singleton context
-            initSingletonContext(null);
             webBeansContext.getBeanManagerImpl().fireEvent(new Object(), InitializedLiteral.INSTANCE_REQUEST_SCOPED);
         }
     }
@@ -411,15 +362,18 @@ public class WebContextsService extends
             elStore.destroyELContextStore();
         }
 
+        Object payload = requestEvent != null && requestEvent.getServletRequest()
!= null ? requestEvent.getServletRequest() : new Object();
+        webBeansContext.getBeanManagerImpl().fireEvent(payload, DestroyedLiteral.INSTANCE_REQUEST_SCOPED);
+
         //Clear thread locals
+        conversationContexts.set(null);
+        conversationContexts.remove();
+        sessionContexts.set(null);
+        sessionContexts.remove();
         requestContexts.set(null);
         requestContexts.remove();
 
         RequestScopedBeanInterceptorHandler.removeThreadLocals();
-
-        Object payload = requestEvent != null && requestEvent.getServletRequest()
!= null ? requestEvent.getServletRequest() : new Object();
-
-        webBeansContext.getBeanManagerImpl().fireEvent(payload, DestroyedLiteral.INSTANCE_REQUEST_SCOPED);
     }
 
     private void cleanupConversations()
@@ -458,7 +412,8 @@ public class WebContextsService extends
     }
 
     /**
-     * Creates the session context at the session start. 
+     * Creates the session context at the session start.
+     * Or assign a
      * @param session http session object
      */
     private void initSessionContext(HttpSession session)
@@ -475,22 +430,30 @@ public class WebContextsService extends
         }
         else
         {
-            String sessionId = session.getId();
+            // we need to get it latest here to make sure we work on the same instance
+            currentSessionContext = (SessionContext) session.getAttribute(OWB_SESSION_CONTEXT_ATTRIBUTE);
 
-            //Current context
-            currentSessionContext = sessionCtxManager.getSessionContextWithSessionId(sessionId);
-
-            //No current context
             if (currentSessionContext == null)
             {
-                currentSessionContext = new SessionContext();
-                sessionCtxManager.addNewSessionContext(sessionId, currentSessionContext);
-                webBeansContext.getBeanManagerImpl().fireEvent(session, InitializedLiteral.INSTANCE_SESSION_SCOPED);
+                // no current context, so lets create a new one
+                synchronized (OWB_SESSION_CONTEXT_ATTRIBUTE)
+                {
+                    currentSessionContext = (SessionContext) session.getAttribute(OWB_SESSION_CONTEXT_ATTRIBUTE);
+                    if (currentSessionContext == null)
+                    {
+                        currentSessionContext = new SessionContext();
+                        //Activate
+                        currentSessionContext.setActive(true);
+                        webBeansContext.getBeanManagerImpl().fireEvent(session, InitializedLiteral.INSTANCE_SESSION_SCOPED);
+                    }
+                }
             }
+
+            // we do that in any case.
+            // This is needed to trigger delta-replication on most servers
+            session.setAttribute(OWB_SESSION_CONTEXT_ATTRIBUTE, currentSessionContext);
         }
 
-        //Activate
-        currentSessionContext.setActive(true);
 
         //Set thread local
         sessionContexts.set(currentSessionContext);
@@ -513,9 +476,6 @@ public class WebContextsService extends
                 initSessionContext(session);
                 context = sessionContexts.get();
             }
-
-            //Remove session from manager
-            sessionCtxManager.removeSessionContextWithSessionId(session.getId());
         }
 
         //Destroy context
@@ -537,12 +497,7 @@ public class WebContextsService extends
      */
     private void initApplicationContext(ServletContext servletContext)
     {
-        if (servletContext != null && currentApplicationContexts.containsKey(servletContext))
-        {
-            return;
-        }
-
-        if (sharedApplicationContext != null && servletContext == null)
+        if (sharedApplicationContext != null)
         {
             return;
         }
@@ -550,23 +505,11 @@ public class WebContextsService extends
         ApplicationContext newApplicationContext = new ApplicationContext();
         newApplicationContext.setActive(true);
 
-        if (servletContext != null)
-        {
-            currentApplicationContexts.put(servletContext, newApplicationContext);
-
-            ClassLoader currentClassLoader = WebBeansUtil.getCurrentClassLoader();
-            if (!classLoaderToServletContextMapping.containsKey(currentClassLoader))
-            {
-                classLoaderToServletContextMapping.put(currentClassLoader, servletContext);
-            }
-        }
-
         if (sharedApplicationContext == null)
         {
             sharedApplicationContext = newApplicationContext;
+            webBeansContext.getBeanManagerImpl().fireEvent(servletContext != null ? servletContext
: new Object(), InitializedLiteral.INSTANCE_APPLICATION_SCOPED);
         }
-
-        webBeansContext.getBeanManagerImpl().fireEvent(servletContext != null ? servletContext
: new Object(), InitializedLiteral.INSTANCE_APPLICATION_SCOPED);
     }
 
     /**
@@ -578,74 +521,18 @@ public class WebContextsService extends
     {
         //look for thread local
         //this can be set by initRequestContext
-        ApplicationContext context = null;
-        
-        //Looking the context from saved context
-        //This is used in real web applications
-        if(servletContext != null)
-        {
-            context = currentApplicationContexts.get(servletContext);   
-        }
-        
-        //using in tests
-        if(context == null)
-        {
-            context = this.sharedApplicationContext;
-        }
-        
+        ApplicationContext context = sharedApplicationContext;
+        sharedSingletonContext = null;
+
         //Destroy context
         if(context != null)
         {
             context.destroy();
         }
-        
-        //Remove from saved contexts
-        if(servletContext != null)
-        {
-            currentApplicationContexts.remove(servletContext);   
-        }
-        
-        //destroyDependents all sessions
-        Collection<SessionContext> allSessionContexts = sessionCtxManager.getAllSessionContexts().values();
-        if (allSessionContexts != null && allSessionContexts.size() > 0)
-        {
-            for (SessionContext sessionContext : allSessionContexts)
-            {
-                sessionContexts.set(sessionContext);
-                
-                sessionContext.destroy();
-
-                sessionContexts.set(null);
-                sessionContexts.remove();
-            }
-
-            //Clear map
-            allSessionContexts.clear();
-        }
-        
-        //destroyDependents all conversations
-        Collection<ConversationContext> allConversationContexts = conversationManager.getAllConversationContexts().values();
-        if (allConversationContexts != null && allConversationContexts.size() >
0)
-        {
-            for (ConversationContext conversationContext : allConversationContexts) 
-            {
-                conversationContexts.set(conversationContext);
-                
-                conversationContext.destroy();
-
-                conversationContexts.set(null);
-                conversationContexts.remove();
-            }
-
-            //Clear conversations
-            allConversationContexts.clear();
-        }
 
         // this is needed to get rid of ApplicationScoped beans which are cached inside the
proxies...
         webBeansContext.getBeanManagerImpl().clearCacheProxies();
 
-        classLoaderToServletContextMapping.remove(WebBeansUtil.getCurrentClassLoader());
-
         webBeansContext.getBeanManagerImpl().fireEvent(servletContext != null ? servletContext
: new Object(), DestroyedLiteral.INSTANCE_APPLICATION_SCOPED);
     }
     
@@ -655,12 +542,7 @@ public class WebContextsService extends
      */
     private void initSingletonContext(ServletContext servletContext)
     {
-        if (servletContext != null && currentSingletonContexts.containsKey(servletContext))
-        {
-            return;
-        }
-
-        if (currentSingletonContexts != null && servletContext == null)
+        if (sharedSingletonContext != null)
         {
             return;
         }
@@ -668,17 +550,6 @@ public class WebContextsService extends
         SingletonContext newSingletonContext = new SingletonContext();
         newSingletonContext.setActive(true);
 
-        if (servletContext != null)
-        {
-            currentSingletonContexts.put(servletContext, newSingletonContext);
-
-            ClassLoader currentClassLoader = WebBeansUtil.getCurrentClassLoader();
-            if (!classLoaderToServletContextMapping.containsKey(currentClassLoader))
-            {
-                classLoaderToServletContextMapping.put(currentClassLoader, servletContext);
-            }
-        }
-
         if (sharedSingletonContext == null)
         {
             sharedSingletonContext = newSingletonContext;
@@ -693,35 +564,13 @@ public class WebContextsService extends
      */
     private void destroySingletonContext(ServletContext servletContext)
     {
-        SingletonContext context = null;
+        SingletonContext context = sharedSingletonContext;
 
-        //look for saved context
-        if(servletContext != null)
-        {
-            context = currentSingletonContexts.get(servletContext);
-        }
-        
-        //using in tests
-        if(context == null)
-        {
-            context = this.sharedSingletonContext;
-        }        
-        
-        //context is not null
-        //destroyDependents it
-        if(context != null)
+        if (context != null)
         {
             context.destroy();
         }
 
-        //remove it from saved contexts
-        if(servletContext != null)
-        {
-            currentSingletonContexts.remove(servletContext);   
-        }
-
-        classLoaderToServletContextMapping.remove(WebBeansUtil.getCurrentClassLoader());
-
         webBeansContext.getBeanManagerImpl().fireEvent(servletContext != null ? servletContext
: new Object(), DestroyedLiteral.INSTANCE_SINGLETON_SCOPED);
     }
 
@@ -828,7 +677,10 @@ public class WebContextsService extends
         return conversationContexts.get();
     }
 
-    private Context lazyStartSessionContext()
+    /**
+     * Try to lazily start the sessionContext
+     */
+    private void lazyStartSessionContext()
     {
 
         if (logger.isLoggable(Level.FINE))
@@ -836,7 +688,6 @@ public class WebContextsService extends
             logger.log(Level.FINE, ">lazyStartSessionContext");
         }
 
-        Context webContext = null;
         Context context = getCurrentContext(RequestScoped.class);
         if (context instanceof ServletRequestContext)
         {
@@ -846,12 +697,8 @@ public class WebContextsService extends
             { // this could be null if there is no active request context
                 try
                 {
-                    HttpSession currentSession = servletRequest.getSession();
+                    HttpSession currentSession = servletRequest.getSession(true);
                     initSessionContext(currentSession);
-                    if (failoverService != null && failoverService.isSupportFailOver())
-                    {
-                        failoverService.sessionIsInUse(currentSession);
-                    }
 
                     if (logger.isLoggable(Level.FINE))
                     {
@@ -873,12 +720,6 @@ public class WebContextsService extends
         {
             logger.log(Level.WARNING, "Could NOT lazily initialize session context because
of "+context+" RequestContext");
         }
-
-        if (logger.isLoggable(Level.FINE))
-        {
-            logger.log(Level.FINE, "<lazyStartSessionContext "+ webContext);
-        }
-        return webContext;
     }
 
 



Mime
View raw message