openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gerdo...@apache.org
Subject svn commit: r937337 - in /openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/context: SessionContextManager.java WebContextsService.java
Date Fri, 23 Apr 2010 15:33:23 GMT
Author: gerdogdu
Date: Fri Apr 23 15:33:22 2010
New Revision: 937337

URL: http://svn.apache.org/viewvc?rev=937337&view=rev
Log:
Update while running sample applications.

Modified:
    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/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=937337&r1=937336&r2=937337&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
Fri Apr 23 15:33:22 2010
@@ -13,31 +13,52 @@
  */
 package org.apache.webbeans.web.context;
 
-import java.util.Iterator;
+import java.util.Collection;
 import java.util.Map;
-import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 
 import org.apache.webbeans.config.WebBeansFinder;
 import org.apache.webbeans.context.SessionContext;
 import org.apache.webbeans.util.Asserts;
 
+/**
+ * Session context manager.
+ * <p>
+ * Each session is identified by the session id.
+ * </p>
+ * @version $Rev$ $Date$
+ *
+ */
 public class SessionContextManager
 {
+    /** Session id to SessionContext map*/
     private Map<String, SessionContext> sessionContexts = null;
 
+    
+    /**
+     * Creates a new session context manager.
+     */
     public SessionContextManager()
     {
         sessionContexts = new ConcurrentHashMap<String, SessionContext>();        
     }
-
+    
+    /**
+     * Gets singleton instance.
+     * @return instance of session context manager
+     */
     public static SessionContextManager getInstance()
     {
         SessionContextManager sessionContextManager = (SessionContextManager)WebBeansFinder.getSingletonInstance(WebBeansFinder.SINGLETON_SESSION_CONTEXT_MANAGER);
       
         
         return sessionContextManager;
     }
-
+    
+    /**
+     * Adds new session context for the given session id.
+     * @param sessionId session id
+     * @param context session context
+     */
     public void addNewSessionContext(String sessionId, SessionContext context)
     {
         Asserts.assertNotNull(sessionId, "sessionId parameter can not be null");
@@ -46,30 +67,47 @@ public class SessionContextManager
         sessionContexts.put(sessionId, context);
     }
 
+    /**
+     * Gets session context related with given session id.
+     * @param sessionId session id
+     * @return session context related with given session id
+     */
     public SessionContext getSessionContextWithSessionId(String sessionId)
     {
         Asserts.assertNotNull(sessionId, "sessionId parameter can not be null");
 
         return sessionContexts.get(sessionId);
     }
-
+    
+    /**
+     * Destroy session context with given id.
+     * @param sessionId session id
+     */
     public void destroySessionContextWithSessionId(String sessionId)
     {
-        Set<String> keySet = sessionContexts.keySet();
-        Iterator<String> it = keySet.iterator();
-
-        while (it.hasNext())
+        SessionContext sessionContext = this.sessionContexts.remove(sessionId);
+        if(sessionContext != null)
         {
-            String id = it.next();
-            if (id.equals(sessionId))
-            {
-                it.remove();
-            }
+            sessionContext.destroy();
         }
     }
-
+    
+    /**
+     * Destroys all sessions.
+     */
     public void destroyAllSessions()
     {
+        //Destroy all contexts
+        Collection<SessionContext> sessionContexts = this.sessionContexts.values();
+        if(sessionContexts != null && sessionContexts.size() > 0)
+        {
+            for(SessionContext sessionContext : sessionContexts)
+            {
+                sessionContext.destroy();
+            }
+        }
+        
+        //Clear map
         sessionContexts.clear();
     }
 }

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=937337&r1=937336&r2=937337&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
Fri Apr 23 15:33:22 2010
@@ -89,7 +89,10 @@ public class WebContextsService extends 
         dependentContext = new ThreadLocal<DependentContext>();
         singletonContext = new ThreadLocal<SingletonContext>();
     }
-
+    
+    /**
+     * Creates a new instance.
+     */
     public WebContextsService()
     {
         supportsConversation =  !OpenWebBeansConfiguration.getInstance().isJspApplication();
@@ -101,7 +104,6 @@ public class WebContextsService extends 
     @Override
     public void init(Object initializeObject)
     {        
-        initializeThreadLocals();
         startContext(ApplicationScoped.class, initializeObject);
         startContext(Singleton.class, initializeObject);
     }    
@@ -112,18 +114,18 @@ public class WebContextsService extends 
     @Override
     public void destroy(Object destroyObject)
     {
+        currentApplicationContexts.clear();
+        currentSingletonContexts.clear();
+
         endContext(ApplicationScoped.class, destroyObject);
         endContext(Singleton.class, destroyObject);
         
-        requestContext.remove();
-        dependentContext.remove();
-        sessionContext.remove();
-        conversationContext.remove();
-        applicationContext.remove();
-        singletonContext.remove();
-
-        currentApplicationContexts.clear();
-        currentSingletonContexts.clear();
+        requestContext.set(null);
+        dependentContext.set(null);
+        sessionContext.set(null);
+        conversationContext.set(null);
+        applicationContext.set(null);
+        singletonContext.set(null);        
     }    
     
     
@@ -257,25 +259,11 @@ public class WebContextsService extends 
     }
     
     /**
-     * Initialize thread locals.
-     */
-    private void initializeThreadLocals()
-    {
-        requestContext.remove();
-        sessionContext.remove();
-        applicationContext.remove();
-        conversationContext.remove();
-        dependentContext.remove();
-        singletonContext.remove();
-    }
-
-    /**
      * Initialize requext context with the given request object.
      * @param event http servlet request event
      */
     private void initRequestContext(ServletRequestEvent event)
     {
-        initializeThreadLocals();
         
         RequestContext rq = new RequestContext();
         rq.setActive(true);
@@ -316,7 +304,7 @@ public class WebContextsService extends 
                 context.destroy();
             }
 
-            requestContext.remove();
+            requestContext.set(null);
             
         }
     }
@@ -357,7 +345,7 @@ public class WebContextsService extends 
                 context.destroy();
             }
 
-            sessionContext.remove();
+            sessionContext.set(null);
 
         }
 
@@ -409,7 +397,7 @@ public class WebContextsService extends 
                 context.destroy();
             }
 
-            applicationContext.remove();
+            applicationContext.set(null);
 
         }
         
@@ -465,7 +453,7 @@ public class WebContextsService extends 
                 context.destroy();
             }
             
-            singletonContext.remove();            
+            singletonContext.set(null);          
 
         }
         
@@ -517,7 +505,7 @@ public class WebContextsService extends 
                 context.destroy();
             }
 
-            conversationContext.remove();
+            conversationContext.set(null);
         }
     }
 



Mime
View raw message