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 2014/11/26 18:34:38 UTC

svn commit: r1641866 - in /tomcat/sandbox/tomcat-oacc/trunk: docs/changelog.xml src/share/org/apache/catalina/cluster/session/ClusterManagerBase.java src/share/org/apache/catalina/cluster/session/DeltaSession.java

Author: rjung
Date: Wed Nov 26 17:34:37 2014
New Revision: 1641866

URL: http://svn.apache.org/r1641866
Log:
Fine grained control of session attribute
replication in clusters.

- Allow to overwrite the check for distributability
  of session attributes by session implementations.

- New cluster manager attribute sessionAttributeFilter
  allows to filter which session attributes are
  replicated using a regular expression applied to the
  attribute name.

Merge of r1172233-1172234,r1172236,r1175158,r1175190
from trunk respectively r1172259 and r1175194
from TC7

Backport of r1175196 from TC6.

Modified:
    tomcat/sandbox/tomcat-oacc/trunk/docs/changelog.xml
    tomcat/sandbox/tomcat-oacc/trunk/src/share/org/apache/catalina/cluster/session/ClusterManagerBase.java
    tomcat/sandbox/tomcat-oacc/trunk/src/share/org/apache/catalina/cluster/session/DeltaSession.java

Modified: tomcat/sandbox/tomcat-oacc/trunk/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/sandbox/tomcat-oacc/trunk/docs/changelog.xml?rev=1641866&r1=1641865&r2=1641866&view=diff
==============================================================================
--- tomcat/sandbox/tomcat-oacc/trunk/docs/changelog.xml (original)
+++ tomcat/sandbox/tomcat-oacc/trunk/docs/changelog.xml Wed Nov 26 17:34:37 2014
@@ -31,6 +31,11 @@
 <body>
 <section name="Tomcat OACC 0.1 (rjung)">
   <subsection name="Cluster">
+      <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>
       <fix>
         <bug>50771</bug>: Ensure HttpServletRequest#getAuthType() returns the
         name of the authentication scheme if request has already been

Modified: tomcat/sandbox/tomcat-oacc/trunk/src/share/org/apache/catalina/cluster/session/ClusterManagerBase.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/tomcat-oacc/trunk/src/share/org/apache/catalina/cluster/session/ClusterManagerBase.java?rev=1641866&r1=1641865&r2=1641866&view=diff
==============================================================================
--- tomcat/sandbox/tomcat-oacc/trunk/src/share/org/apache/catalina/cluster/session/ClusterManagerBase.java (original)
+++ tomcat/sandbox/tomcat-oacc/trunk/src/share/org/apache/catalina/cluster/session/ClusterManagerBase.java Wed Nov 26 17:34:37 2014
@@ -17,15 +17,17 @@
 
 package org.apache.catalina.cluster.session;
 
-import org.apache.catalina.cluster.ClusterManager;
 import java.beans.PropertyChangeListener;
-import org.apache.catalina.Lifecycle;
-import org.apache.catalina.session.ManagerBase;
-import org.apache.catalina.Loader;
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
-import org.apache.catalina.cluster.session.ReplicationStream;
+import java.util.regex.Pattern;
+
 import org.apache.catalina.Container;
+import org.apache.catalina.Lifecycle;
+import org.apache.catalina.Loader;
+import org.apache.catalina.ha.ClusterManager;
+import org.apache.catalina.session.ManagerBase;
+import org.apache.catalina.cluster.session.ReplicationStream;
 
 /**
  * 
@@ -36,6 +38,64 @@ import org.apache.catalina.Container;
 public abstract class ClusterManagerBase extends ManagerBase implements Lifecycle, PropertyChangeListener, 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;

Modified: tomcat/sandbox/tomcat-oacc/trunk/src/share/org/apache/catalina/cluster/session/DeltaSession.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/tomcat-oacc/trunk/src/share/org/apache/catalina/cluster/session/DeltaSession.java?rev=1641866&r1=1641865&r2=1641866&view=diff
==============================================================================
--- tomcat/sandbox/tomcat-oacc/trunk/src/share/org/apache/catalina/cluster/session/DeltaSession.java (original)
+++ tomcat/sandbox/tomcat-oacc/trunk/src/share/org/apache/catalina/cluster/session/DeltaSession.java Wed Nov 26 17:34:37 2014
@@ -559,6 +559,37 @@ 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
+     */
+    @Override
+    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 if attribute should not be replicated
+     */
+    @Override
+    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.
@@ -633,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.



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