[jboss-cvs] JBossAS SVN: r82253 - branches/JBoss_4_0_5_GA_ASPATCH-405/tomcat/src/main/org/jboss/web/tomcat/tc5/session.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sat Dec 13 01:53:29 EST 2008


Author: jiwils
Date: 2008-12-13 01:53:29 -0500 (Sat, 13 Dec 2008)
New Revision: 82253

Modified:
   branches/JBoss_4_0_5_GA_ASPATCH-405/tomcat/src/main/org/jboss/web/tomcat/tc5/session/SessionBasedClusteredSession.java
   branches/JBoss_4_0_5_GA_ASPATCH-405/tomcat/src/main/org/jboss/web/tomcat/tc5/session/Util.java
Log:
Fix for ASPATCH-405.

Modified: branches/JBoss_4_0_5_GA_ASPATCH-405/tomcat/src/main/org/jboss/web/tomcat/tc5/session/SessionBasedClusteredSession.java
===================================================================
--- branches/JBoss_4_0_5_GA_ASPATCH-405/tomcat/src/main/org/jboss/web/tomcat/tc5/session/SessionBasedClusteredSession.java	2008-12-12 22:52:59 UTC (rev 82252)
+++ branches/JBoss_4_0_5_GA_ASPATCH-405/tomcat/src/main/org/jboss/web/tomcat/tc5/session/SessionBasedClusteredSession.java	2008-12-13 06:53:29 UTC (rev 82253)
@@ -24,6 +24,7 @@
 import java.io.IOException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
+import java.util.Hashtable;
 import java.util.Map;
 
 
@@ -45,7 +46,7 @@
  *
  * @author Ben Wang
  * @author Brian Stansberry
- * 
+ *
  * @version $Revision$
  */
 class SessionBasedClusteredSession
@@ -57,6 +58,13 @@
     */
    protected static final String info = "SessionBasedClusteredSession/1.0";
 
+   /**
+    * Whether or not to copy the attribute map before serialization in order
+    * to prevent deadlock as described in JIRA ASPATCH-405.
+    */
+   protected static final boolean copyAttributeMap =
+      Util.getBooleanProperty("jboss.web.clustered.session.copy.attribute.map");
+
    public SessionBasedClusteredSession(JBossCacheManager manager)
    {
       super(manager);
@@ -88,7 +96,7 @@
    }
 
    // ----------------------------------------------HttpSession Public Methods
-   
+
    /**
     * Does nothing -- all attributes are populated already
     */
@@ -112,8 +120,8 @@
 
    }
 
-   protected Object removeJBossInternalAttribute(String name, 
-                                                 boolean localCall, 
+   protected Object removeJBossInternalAttribute(String name,
+                                                 boolean localCall,
                                                  boolean localOnly)
    {
       if (localCall)
@@ -133,15 +141,15 @@
    }
 
    /**
-    * Overrides the superclass version by additionally reading the 
+    * Overrides the superclass version by additionally reading the
     * attributes map.
-    * 
+    *
     * <p>
     * This method is deliberately public so it can be used to reset
     * the internal state of a session object using serialized
     * contents replicated from another JVM via JBossCache.
     * </p>
-    * 
+    *
     * @see org.jboss.web.tomcat.tc5.session.ClusteredSession#readExternal(java.io.ObjectInput)
     */
    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
@@ -150,16 +158,16 @@
       {
          // Let superclass read in everything but the attribute map
          super.readExternal(in);
-      
-         attributes = (Map) in.readObject();      
+
+         attributes = (Map) in.readObject();
       }
    }
 
    /**
     * Overrides the superclass version by appending the attributes map. Does
-    * not write any attributes whose names are found in 
+    * not write any attributes whose names are found in
     * {@link ClusteredSession#excludedAttributes}.
-    * 
+    *
     * @see org.jboss.web.tomcat.tc5.session.ClusteredSession#writeExternal(java.io.ObjectOutput)
     */
    public void writeExternal(ObjectOutput out) throws IOException
@@ -168,20 +176,27 @@
       {
          // Let superclass write out everything but the attribute map
          super.writeExternal(out);
-         
+
          // Don't replicate any excluded attributes
          Map excluded = removeExcludedAttributes(attributes);
-        
-         out.writeObject(attributes);
-        
+
+         if (copyAttributeMap)
+         {
+            out.writeObject(new Hashtable(attributes));
+         }
+         else
+         {
+            out.writeObject(attributes);
+         }
+
          // Restore any excluded attributes
          if (excluded != null)
             attributes.putAll(excluded);
-      }   
-   
+      }
+
    }
-   
 
+
    /**
     * Overrides the superclass version to return <code>true</code> if either
     * the metadata or the attributes are dirty.

Modified: branches/JBoss_4_0_5_GA_ASPATCH-405/tomcat/src/main/org/jboss/web/tomcat/tc5/session/Util.java
===================================================================
--- branches/JBoss_4_0_5_GA_ASPATCH-405/tomcat/src/main/org/jboss/web/tomcat/tc5/session/Util.java	2008-12-12 22:52:59 UTC (rev 82252)
+++ branches/JBoss_4_0_5_GA_ASPATCH-405/tomcat/src/main/org/jboss/web/tomcat/tc5/session/Util.java	2008-12-13 06:53:29 UTC (rev 82253)
@@ -34,7 +34,7 @@
 
 /**
  * Utility methods related to JBoss distributed sessions.
- * 
+ *
  * @author Brian Stansberry
  * @version $Revision$
  */
@@ -62,9 +62,9 @@
 
    /**
     * Returns a session id with any trailing jvmRoute removed.
-    * 
+    *
     * @param sessionId the raw session id
-    * 
+    *
     * @return <code>sessionId</code> with the final '.' and any
     *         characters thereafter removed.
     */
@@ -82,9 +82,9 @@
    }
 
    /**
-    * Checks whether the given object is usable for FIELD granularity 
+    * Checks whether the given object is usable for FIELD granularity
     * replication.
-    * 
+    *
     * @param pojo  the pojo
     * @return <code>true</code> if the attribute type is acceptable,
     *         <code>false</code> otherwise
@@ -92,28 +92,28 @@
    public static boolean checkPojoType(Object pojo)
    {
       return (   (pojo instanceof Serializable)
-              || (pojo instanceof Collection) 
-              || (pojo instanceof Map) 
+              || (pojo instanceof Collection)
+              || (pojo instanceof Map)
               || (pojo instanceof Advised)
               || (immediates.contains(pojo.getClass())));
    }
-   
+
    public static Set parseComplexFields(Class clazz)
    {
       Set result = new HashSet();
-      
+
       while (clazz != null)
       {
          Field[] fields = clazz.getDeclaredFields();
          for (int i = 0; i < fields.length; i++)
          {
-            if (!immediates.contains(fields[i].getType()) 
+            if (!immediates.contains(fields[i].getType())
                   && isReplicatable(fields[i]))
             {
                result.add(fields[i].getName());
             }
          }
-         
+
          clazz = clazz.getSuperclass();
       }
       return result;
@@ -121,7 +121,7 @@
 
    /**
     * Returns false if the given field is static, transient or final.
-    * 
+    *
     * @param f the field
     * @return
     */
@@ -140,6 +140,27 @@
    }
 
    /**
+    * Retrieves a boolean value from the specified system property.
+    *
+    * @param systemProperty the system property from which to retrieve the boolean value.
+    *
+    * @return <code>true</code> if the system property's value is equal to 'true'
+    * ignoring case; <code>false</code> otherwise.
+    */
+   public static boolean getBooleanProperty(String systemProperty)
+   {
+      boolean returnValue = false;
+      String str = System.getProperty(systemProperty);
+
+      if (str != null && str.equalsIgnoreCase("true"))
+      {
+         returnValue = true;
+      }
+
+      return returnValue;
+   }
+
+   /**
     * Prevent instantiation.
     */
    private Util() {}




More information about the jboss-cvs-commits mailing list