You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by rj...@apache.org on 2011/09/18 13:44:46 UTC

svn commit: r1172259 - in /tomcat/tc7.0.x/trunk: ./ java/org/apache/catalina/ha/session/ java/org/apache/catalina/session/ webapps/docs/ webapps/docs/config/

Author: rjung
Date: Sun Sep 18 11:44:45 2011
New Revision: 1172259

URL: http://svn.apache.org/viewvc?rev=1172259&view=rev
Log:
1) Allow to overwrite check for distributability
of session attributes by session implementations.
Backport of r1172233 from trunk.

2) Support a regexp based filter of attribute
names in ClusterManagerBase and DeltaSession.

Only attributes whose names match will be
distributed. An empty filter means all attributes
will be distributed (unchanged default behaviour).
Backport of r1172234 from trunk.

3) Document new "sessionAttributeFilter" for cluster
managers.
Backport of r1172236 from trunk.


Modified:
    tomcat/tc7.0.x/trunk/   (props changed)
    tomcat/tc7.0.x/trunk/java/org/apache/catalina/ha/session/ClusterManagerBase.java
    tomcat/tc7.0.x/trunk/java/org/apache/catalina/ha/session/DeltaSession.java
    tomcat/tc7.0.x/trunk/java/org/apache/catalina/session/StandardSession.java
    tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
    tomcat/tc7.0.x/trunk/webapps/docs/config/cluster-manager.xml

Propchange: tomcat/tc7.0.x/trunk/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sun Sep 18 11:44:45 2011
@@ -1 +1 @@
-/tomcat/trunk:1156171,1156276,1156304,1156530,1156602,1157015,1157018,1157151,1157198,1157204,1157810,1157832,1157834,1157847,1157908,1157939,1158155,1158160,1158176,1158195,1158198-1158199,1158227,1158331,1158334-1158335,1158426,1160347,1160592,1160611,1160619,1160626,1160639,1160652,1160720-1160721,1160772,1160774,1160776,1161303,1161310,1161322,1161339,1161486,1161540,1161549,1161584,1162082,1162149,1162169,1162721,1162769,1162836,1162932,1163630,1164419,1164438,1164469,1164480,1164567,1165234,1165247-1165248,1165253,1165273,1165282,1165309,1165331,1165338,1165347,1165360-1165361,1165367-1165368,1165602,1165608,1165677,1165693,1165721,1165723,1165728,1165730,1165738,1165746,1165765,1165777,1165918,1165921,1166077,1166150-1166151,1166290,1166366,1166620,1166686,1166752,1166757,1167368,1167394,1169447,1171692
+/tomcat/trunk:1156171,1156276,1156304,1156530,1156602,1157015,1157018,1157151,1157198,1157204,1157810,1157832,1157834,1157847,1157908,1157939,1158155,1158160,1158176,1158195,1158198-1158199,1158227,1158331,1158334-1158335,1158426,1160347,1160592,1160611,1160619,1160626,1160639,1160652,1160720-1160721,1160772,1160774,1160776,1161303,1161310,1161322,1161339,1161486,1161540,1161549,1161584,1162082,1162149,1162169,1162721,1162769,1162836,1162932,1163630,1164419,1164438,1164469,1164480,1164567,1165234,1165247-1165248,1165253,1165273,1165282,1165309,1165331,1165338,1165347,1165360-1165361,1165367-1165368,1165602,1165608,1165677,1165693,1165721,1165723,1165728,1165730,1165738,1165746,1165765,1165777,1165918,1165921,1166077,1166150-1166151,1166290,1166366,1166620,1166686,1166752,1166757,1167368,1167394,1169447,1171692,1172233-1172234,1172236

Modified: tomcat/tc7.0.x/trunk/java/org/apache/catalina/ha/session/ClusterManagerBase.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/ha/session/ClusterManagerBase.java?rev=1172259&r1=1172258&r2=1172259&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/catalina/ha/session/ClusterManagerBase.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/ha/session/ClusterManagerBase.java Sun Sep 18 11:44:45 2011
@@ -19,6 +19,7 @@ package org.apache.catalina.ha.session;
 
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
+import java.util.regex.Pattern;
 
 import org.apache.catalina.Container;
 import org.apache.catalina.Loader;
@@ -35,6 +36,64 @@ import org.apache.catalina.tribes.io.Rep
 public abstract class ClusterManagerBase extends ManagerBase
         implements ClusterManager {
 
+    /**
+     * The pattern used for including session attributes to
+     *  replication, e.g. <code>^(userName|sessionHistory)$</code>.
+     *  If not set, all session attributes will be eligible for replication.
+     */
+    private String sessionAttributeFilter = null;
+
+    /**
+     * The compiled pattern used for including session attributes to
+     * replication, e.g. <code>^(userName|sessionHistory)$</code>.
+     * If not set, all session attributes will be eligible for replication.
+     */
+    private Pattern sessionAttributePattern = null;
+
+
+    /**
+     * Return the string pattern used for including session attributes
+     * to replication.
+     *
+     * @return the sessionAttributeFilter
+     */
+    public String getSessionAttributeFilter() {
+        return sessionAttributeFilter;
+    }
+
+    /**
+     * Set the pattern used for including session attributes to replication.
+     * If not set, all session attributes will be eligible for replication.
+     * <p>
+     * E.g. <code>^(userName|sessionHistory)$</code>
+     * </p>
+     *
+     * @param sessionAttributeFilter
+     *            the filter name pattern to set
+     */
+    public void setSessionAttributeFilter(String sessionAttributeFilter) {
+        if (sessionAttributeFilter == null
+            || sessionAttributeFilter.trim().equals("")) {
+            this.sessionAttributeFilter = null;
+            sessionAttributePattern = null;
+        } else {
+            this.sessionAttributeFilter = sessionAttributeFilter;
+            sessionAttributePattern = Pattern.compile(sessionAttributeFilter);
+        }
+    }
+
+    /**
+     * Check whether the given session attribute should be distributed
+     *
+     * @return true if the attribute should be distributed
+     */
+    public boolean willAttributeDistribute(String name) {
+        if (sessionAttributePattern == null) {
+            return true;
+        }
+        return sessionAttributePattern.matcher(name).matches();
+    }
+
     public static ClassLoader[] getClassLoaders(Container container) {
         Loader loader = null;
         ClassLoader classLoader = null;
@@ -88,4 +147,4 @@ public abstract class ClusterManagerBase
     public void unload() {
         // NOOP
     }
-}
\ No newline at end of file
+}

Modified: tomcat/tc7.0.x/trunk/java/org/apache/catalina/ha/session/DeltaSession.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/ha/session/DeltaSession.java?rev=1172259&r1=1172258&r2=1172259&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/catalina/ha/session/DeltaSession.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/ha/session/DeltaSession.java Sun Sep 18 11:44:45 2011
@@ -559,6 +559,35 @@ public class DeltaSession extends Standa
 
 
     /**
+     * Check whether the Object can be distributed.
+     * The object is always distributable, if the cluster manager
+     * decides to never distribute it.
+     * @param name The name of the attribute to check
+     * @param value The value of the attribute to check
+     * @return true if the attribute is distributable, false otherwise
+     */
+    protected boolean isAttributeDistributable(String name, Object value) {
+        if (manager instanceof ClusterManagerBase &&
+            !((ClusterManagerBase)manager).willAttributeDistribute(name))
+            return true;
+        return super.isAttributeDistributable(name, value);
+    }
+
+    /**
+     * Exclude attributes from replication.
+     * @param name the attribute's name
+     * @return true is attribute should not be replicated
+     */
+    protected boolean exclude(String name) {
+
+        if (super.exclude(name))
+            return true;
+        if (manager instanceof ClusterManagerBase)
+            return !((ClusterManagerBase)manager).willAttributeDistribute(name);
+        return false;
+    }
+
+    /**
      * Remove the object bound with the specified name from this session. If the
      * session does not have an object bound with this name, this method does
      * nothing.
@@ -635,6 +664,7 @@ public class DeltaSession extends Standa
 
     // -------------------------------------------- HttpSession Private Methods
 
+
     /**
      * Read a serialized version of this session object from the specified
      * object input stream.

Modified: tomcat/tc7.0.x/trunk/java/org/apache/catalina/session/StandardSession.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/session/StandardSession.java?rev=1172259&r1=1172258&r2=1172259&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/catalina/session/StandardSession.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/session/StandardSession.java Sun Sep 18 11:44:45 2011
@@ -1449,7 +1449,7 @@ public class StandardSession implements 
             throw new IllegalStateException(sm.getString(
                     "standardSession.setAttribute.ise", getIdInternal()));
         if ((manager != null) && manager.getDistributable() &&
-          !(value instanceof Serializable))
+          !isAttributeDistributable(name, value))
             throw new IllegalArgumentException
                 (sm.getString("standardSession.setAttribute.iae", name));
         // Construct an event with the new value
@@ -1558,6 +1558,19 @@ public class StandardSession implements 
         return (this.isValid || this.expiring);
     }
 
+    /**
+     * Check whether the Object can be distributed. This implementation
+     * simply checks for serializability. Derived classes might use other
+     * distribution technology not based on serialization and can extend
+     * this check.
+     * @param name The name of the attribute to check
+     * @param value The value of the attribute to check
+     * @return true if the attribute is distributable, false otherwise
+     */
+    protected boolean isAttributeDistributable(String name, Object value) {
+        return value instanceof Serializable;
+    }
+
 
     /**
      * Read a serialized version of this session object from the specified
@@ -1694,7 +1707,7 @@ public class StandardSession implements 
 
 
     /**
-     * Exclude attribute that cannot be serialized.
+     * Exclude standard attributes that cannot be serialized.
      * @param name the attribute's name
      */
     protected boolean exclude(String name){

Modified: tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml?rev=1172259&r1=1172258&r2=1172259&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Sun Sep 18 11:44:45 2011
@@ -100,6 +100,10 @@
         <code>javax.servlet.request.ssl_session_id</code> to access the SSL
         session ID and deprecated the Tomcat specific request attribute. (markt)
       </fix>
+      <add>
+        Allow to overwrite the check for distributability
+        of session attributes by session implementations. (rjung)
+      </add>
     </changelog>
   </subsection>
   <subsection name="Coyote">
@@ -121,6 +125,15 @@
       </scode>
     </changelog>
   </subsection>
+  <subsection name="Cluster">
+    <changelog>
+      <add>
+        New cluster manager attribute <code>sessionAttributeFilter</code>
+        allows to filter which session attributes are replicated using a
+        regular expression applied to the attribute name. (rjung)
+      </add>
+    </changelog>
+  </subsection>
   <subsection name="Web applications">
     <changelog>
       <fix>

Modified: tomcat/tc7.0.x/trunk/webapps/docs/config/cluster-manager.xml
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/config/cluster-manager.xml?rev=1172259&r1=1172258&r2=1172259&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/config/cluster-manager.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/config/cluster-manager.xml Sun Sep 18 11:44:45 2011
@@ -83,6 +83,15 @@
         sessions to expire on all nodes when a shutdown occurs on one node, set
         this value to <code>true</code>. Default value is <code>false</code>.
       </attribute>
+      <attribute name="sessionAttributeFilter" required="false">
+        A regular expression used to filter, which session attributes will
+        be replicated. An attribute will only be replicated, if its name
+        matches this pattern. If the pattern is not set (default), all
+        attributes are eligible for replication. As an example, the value
+        <code>^(userName|sessionHistory)$</code> will onlyreplicate the two
+        session attributes named <code>userName</code> and
+        <code>sessionHistory</code>.
+      </attribute>
     </attributes>
   </subsection> 
   <subsection name="org.apache.catalina.ha.session.DeltaManager Attributes">



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