portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From woon...@apache.org
Subject svn commit: r591920 - /portals/jetspeed-2/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/container/session/PortalSessionsManagerImpl.java
Date Mon, 05 Nov 2007 09:03:46 GMT
Author: woonsan
Date: Mon Nov  5 01:03:45 2007
New Revision: 591920

URL: http://svn.apache.org/viewvc?rev=591920&view=rev
Log:
[JS2-795] Deadlock while release session on Websphere Release 6.0.2.19

Applied Joachim Müller's patch.
I've done some load testings under Tomcat and WebSphere 6.1.0.11 and confirmed no side effect.

Modified:
    portals/jetspeed-2/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/container/session/PortalSessionsManagerImpl.java

Modified: portals/jetspeed-2/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/container/session/PortalSessionsManagerImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/container/session/PortalSessionsManagerImpl.java?rev=591920&r1=591919&r2=591920&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/container/session/PortalSessionsManagerImpl.java
(original)
+++ portals/jetspeed-2/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/container/session/PortalSessionsManagerImpl.java
Mon Nov  5 01:03:45 2007
@@ -16,6 +16,8 @@
  */
 package org.apache.jetspeed.container.session;
 
+import java.util.Arrays;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -68,9 +70,15 @@
     /* (non-Javadoc)
      * @see org.apache.jetspeed.container.session.PortalSessionsManager#portalSessionCreated(javax.servlet.http.HttpSession)
      */
-    public synchronized void portalSessionCreated(HttpSession portalSession)
+    public void portalSessionCreated(HttpSession portalSession)
     {
-        PortalSessionMonitor psm = new PortalSessionMonitorImpl(++portalSessionKeySequence,
forceInvalidate);
+        PortalSessionMonitor psm = null;
+        
+        synchronized (this) 
+        {
+            psm = new PortalSessionMonitorImpl(++portalSessionKeySequence, forceInvalidate);
+        }
+        
         portalSession.setAttribute(PortalSessionMonitor.SESSION_KEY, psm);
         // register it as if activated
         portalSessionDidActivate(psm);
@@ -79,7 +87,7 @@
     /* (non-Javadoc)
      * @see org.apache.jetspeed.container.session.PortalSessionsManager#portalSessionWillPassivate(org.apache.jetspeed.container.session.PortalSessionMonitor)
      */
-    public synchronized void portalSessionWillPassivate(PortalSessionMonitor psm)
+    public void portalSessionWillPassivate(PortalSessionMonitor psm)
     {
         portalSessionsRegistry.remove(psm.getSessionId());
     }
@@ -87,7 +95,7 @@
     /* (non-Javadoc)
      * @see org.apache.jetspeed.container.session.PortalSessionsManager#portalSessionDidActivate(org.apache.jetspeed.container.session.PortalSessionMonitor)
      */
-    public synchronized void portalSessionDidActivate(PortalSessionMonitor restoredPsm)
+    public void portalSessionDidActivate(PortalSessionMonitor restoredPsm)
     {
         PortalSessionRegistry psr = (PortalSessionRegistry)portalSessionsRegistry.get(restoredPsm.getSessionId());
         if ( psr != null && psr.portalSessionKey != -1 && psr.portalSessionKey
!= restoredPsm.getSessionKey() )
@@ -106,7 +114,8 @@
         psr.psm = restoredPsm;
         psr.portalSessionKey = restoredPsm.getSessionKey();
         // validate registered paSessions are in sync
-        Iterator iter = psr.sessionMonitors.values().iterator();
+        // we iterate with shallow copy of paSessions to avoid conflicts with concurrent
updates of paSessions
+        Iterator iter = valuesShallowCopy(psr.sessionMonitors.values()).iterator();
         PortletApplicationSessionMonitor pasm;
         while (iter.hasNext())
         {
@@ -114,7 +123,8 @@
             if ( pasm.getPortalSessionKey() != psr.portalSessionKey )
             {
                 pasm.invalidateSession();
-                iter.remove();
+                // remove from original map !
+                psr.sessionMonitors.remove(pasm.getContextPath());
             }
         }
     }
@@ -122,26 +132,35 @@
     /* (non-Javadoc)
      * @see org.apache.jetspeed.container.session.PortalSessionsManager#portalSessionDestroyed(org.apache.jetspeed.container.session.PortalSessionMonitor)
      */
-    public synchronized void portalSessionDestroyed(PortalSessionMonitor psm)
+    public void portalSessionDestroyed(PortalSessionMonitor psm)
     {
         PortalSessionRegistry psr = (PortalSessionRegistry)portalSessionsRegistry.remove(psm.getSessionId());
         if ( psr != null )
         {
-            Iterator iter = psr.sessionMonitors.values().iterator();
+            // we iterate with shallow copy of paSessions to avoid conflicts with concurrent
updates of paSessions
+            Iterator iter = valuesShallowCopy(psr.sessionMonitors.values()).iterator();
             while (iter.hasNext())
             {
-                ((PortletApplicationSessionMonitor)iter.next()).invalidateSession();
+                ((PortletApplicationSessionMonitor) iter.next()).invalidateSession();
+            }
+            
+            try
+            {
+                // To make sure its gone.
+                // You better not remove the psm from the portal session yourself ;)
+                psm.invalidateSession();
+            }
+            catch (IllegalStateException ise)
+            {
+                // pSession already invalid, ignore
             }
-            // To make sure its gone.
-            // You better not remove the psm from the portal session yourself ;)
-            psm.invalidateSession();
         }
     }
 
     /* (non-Javadoc)
      * @see org.apache.jetspeed.container.session.PortalSessionsManager#checkMonitorSession(java.lang.String,
javax.servlet.http.HttpSession, javax.servlet.http.HttpSession)
      */
-    public synchronized void checkMonitorSession(String contextPath, HttpSession portalSession,
HttpSession paSession)
+    public void checkMonitorSession(String contextPath, HttpSession portalSession, HttpSession
paSession)
     {
         if ( portalSession != null && paSession != null )
         {
@@ -225,7 +244,7 @@
     /* (non-Javadoc)
      * @see org.apache.jetspeed.container.session.PortalSessionsManager#sessionDidActivate(org.apache.jetspeed.container.session.PortletApplicationSessionMonitor)
      */
-    public synchronized void sessionDidActivate(PortletApplicationSessionMonitor restoredPasm)
+    public void sessionDidActivate(PortletApplicationSessionMonitor restoredPasm)
     {
         PortalSessionRegistry psr = (PortalSessionRegistry)portalSessionsRegistry.get(restoredPasm.getPortalSessionId());
         if ( psr == null )
@@ -247,15 +266,23 @@
     /* (non-Javadoc)
      * @see org.apache.jetspeed.container.session.PortalSessionsManager#sessionDestroyed(org.apache.jetspeed.container.session.PortletApplicationSessionMonitor)
      */
-    public synchronized void sessionDestroyed(PortletApplicationSessionMonitor pasm)
+    public void sessionDestroyed(PortletApplicationSessionMonitor pasm)
     {
         PortalSessionRegistry psr = (PortalSessionRegistry)portalSessionsRegistry.get(pasm.getPortalSessionId());
         if ( psr != null )
         {
             psr.sessionMonitors.remove(pasm.getContextPath());
-            // To make sure its gone.
-            // You better not remove the pasm from the session yourself ;)
-            pasm.invalidateSession();
+
+            try
+            {
+                // To make sure its gone.
+                // You better not remove the pasm from the session yourself ;)
+                pasm.invalidateSession();
+            }
+            catch (IllegalStateException ise)
+            {
+                // paSession already invalid, ignore
+            }
         }
     }
 
@@ -266,4 +293,13 @@
 		
 		return portalSessionsRegistry.size();
 	}
+
+    /**
+     * Returns a shallow copy of the given Collection.
+     * @param inValues
+     * @return shallow copy
+     */
+    private Collection valuesShallowCopy(Collection inValues) {
+        return Arrays.asList(inValues.toArray());
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message