Return-Path: Delivered-To: apmail-openwebbeans-commits-archive@www.apache.org Received: (qmail 36177 invoked from network); 28 Apr 2010 18:26:30 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 28 Apr 2010 18:26:30 -0000 Received: (qmail 90009 invoked by uid 500); 28 Apr 2010 18:26:30 -0000 Delivered-To: apmail-openwebbeans-commits-archive@openwebbeans.apache.org Received: (qmail 89977 invoked by uid 500); 28 Apr 2010 18:26:30 -0000 Mailing-List: contact commits-help@openwebbeans.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@openwebbeans.apache.org Delivered-To: mailing list commits@openwebbeans.apache.org Received: (qmail 89969 invoked by uid 99); 28 Apr 2010 18:26:30 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 28 Apr 2010 18:26:30 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 28 Apr 2010 18:26:27 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 4CA4F23889B2; Wed, 28 Apr 2010 18:25:37 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@openwebbeans.apache.org From: gerdogdu@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100428182537.4CA4F23889B2@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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(); } /**