openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gerdo...@apache.org
Subject svn commit: r939042 - /openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/context/WebContextsService.java
Date Wed, 28 Apr 2010 18:25:37 GMT
Author: gerdogdu
Date: Wed Apr 28 18:25:36 2010
New Revision: 939042

URL: http://svn.apache.org/viewvc?rev=939042&view=rev
Log:
update threadlocal usage of application and singleton contexts

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=939042&r1=939041&r2=939042&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
Wed Apr 28 18:25:36 2010
@@ -108,7 +108,10 @@ public class WebContextsService extends 
     @Override
     public void init(Object initializeObject)
     {        
+        //Start application context
         startContext(ApplicationScoped.class, initializeObject);
+        
+        //Start signelton context
         startContext(Singleton.class, initializeObject);
     }    
     
@@ -301,7 +304,10 @@ public class WebContextsService extends 
                     initSessionContext(session);    
                 }
                             
-                initApplicationContext(event.getServletContext());                
+                //Init thread local application context
+                initApplicationContext(event.getServletContext());
+                
+                //Init thread local sigleton context
                 initSingletonContext(event.getServletContext());
             }            
         }
@@ -313,17 +319,26 @@ public class WebContextsService extends 
      */
     private void destroyRequestContext(ServletRequestEvent request)
     {
-        if (requestContext != null)
-        {
-            RequestContext context = getRequestContext();
+        //Get context
+        RequestContext context = getRequestContext();
 
-            if (context != null)
-            {
-                context.destroy();
-            }
-            
-            requestContext.set(null);            
+        //Destroy context
+        if (context != null)
+        {
+            context.destroy();
         }
+        
+        //Clear thread locals
+        requestContext.set(null);
+        requestContext.remove();
+        
+        //Also clear application and singleton context
+        applicationContext.set(null);
+        applicationContext.remove();
+        
+        //Singleton context
+        singletonContext.set(null);
+        singletonContext.remove();
     }
 
     /**
@@ -333,16 +348,20 @@ public class WebContextsService extends 
     private void initSessionContext(HttpSession session)
     {
         String sessionId = session.getId();
+        //Current context
         SessionContext currentSessionContext = sessionCtxManager.getSessionContextWithSessionId(sessionId);
-
+        
+        //No current context
         if (currentSessionContext == null)
         {
             currentSessionContext = new SessionContext();
             sessionCtxManager.addNewSessionContext(sessionId, currentSessionContext);
         }
 
+        //Activate
         currentSessionContext.setActive(true);
-
+        
+        //Set thread local
         sessionContext.set(currentSessionContext);
     }
 
@@ -353,19 +372,20 @@ public class WebContextsService extends 
      */
     private void destroySessionContext(HttpSession session)
     {
-        if (sessionContext != null)
+        //Get current session context
+        SessionContext context = getSessionContext();
+        
+        //Destroy context
+        if (context != null)
         {
-            SessionContext context = getSessionContext();
-
-            if (context != null)
-            {
-                context.destroy();
-            }
-
-            sessionContext.set(null);
-
+            context.destroy();
         }
 
+        //Clear thread locals
+        sessionContext.set(null);
+        sessionContext.remove();
+        
+        //Remove session from manager
         sessionCtxManager.destroySessionContextWithSessionId(session.getId());
 
     }
@@ -394,7 +414,6 @@ public class WebContextsService extends 
             }
             
             applicationContext.set(currentApplicationContext);
-   
         }
     }
 
@@ -407,16 +426,12 @@ public class WebContextsService extends 
     {
         //look for thread local
         //this can be set by initRequestContext
-        ApplicationContext context = applicationContext.get();
+        ApplicationContext context = null;
         
-        //no context set
-        //look for saved application context
-        if(context == null)
+        //Looking the context from saved context
+        if(servletContext != null)
         {
-            if(servletContext != null)
-            {
-                context = currentApplicationContexts.get(servletContext);   
-            }
+            context = currentApplicationContexts.get(servletContext);   
         }
         
         //Destroy context
@@ -433,6 +448,7 @@ public class WebContextsService extends 
         
         //destroy all sessions
         sessionCtxManager.destroyAllSessions();
+        
         //destroy all conversations
         conversationManager.destroyAllConversations();
     }
@@ -470,16 +486,12 @@ public class WebContextsService extends 
      */
     private void destroySingletonContext(ServletContext servletContext)
     {
-        SingletonContext context = getSingletonContext();
-        
-        //no context set by initRequestContext
-        if(context == null)
+        SingletonContext context = null;
+
+        //look for saved context
+        if(servletContext != null)
         {
-            //look for saved context
-            if(servletContext != null)
-            {
-                context = currentSingletonContexts.get(servletContext);
-            }
+            context = currentSingletonContexts.get(servletContext);
         }
         
         //context is not null
@@ -529,17 +541,15 @@ public class WebContextsService extends 
      */
     private void destroyConversationContext()
     {
-        if (conversationContext != null)
-        {
-            ConversationContext context = getConversationContext();
+        ConversationContext context = getConversationContext();
 
-            if (context != null)
-            {
-                context.destroy();
-            }
-
-            conversationContext.set(null);
+        if (context != null)
+        {
+            context.destroy();
         }
+
+        conversationContext.set(null);
+        conversationContext.remove();
     }
 
     /**



Mime
View raw message