import java.io.ByteArrayInputStream;
import java.io.IOException;
+import java.util.regex.Pattern;
import org.apache.catalina.Container;
import org.apache.catalina.Loader;
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;
public void unload() {
// NOOP
}
-}
\ No newline at end of file
+}
/**
+ * 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.
// -------------------------------------------- HttpSession Private Methods
+
/**
* Read a serialized version of this session object from the specified
* object input stream.