DeltaManager needs to replicate changed attributes even if session
authorrjung <rjung@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 23 Sep 2009 11:28:14 +0000 (11:28 +0000)
committerrjung <rjung@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 23 Sep 2009 11:28:14 +0000 (11:28 +0000)
gets invalidated. Otherwise session listeners will not see the right
data on the secondary nodes.

Port of r818061 from TC 5.5.x.

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@818062 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/ha/session/DeltaManager.java
java/org/apache/catalina/ha/session/DeltaSession.java

index 3eeab77..de0be54 100644 (file)
@@ -1108,6 +1108,25 @@ public class DeltaManager extends ClusterManagerBase{
      * @return a SessionMessage to be sent,
      */
     public ClusterMessage requestCompleted(String sessionId) {
+         return requestCompleted(sessionId, false);
+     }
+
+     /**
+      * When the request has been completed, the replication valve will notify
+      * the manager, and the manager will decide whether any replication is
+      * needed or not. If there is a need for replication, the manager will
+      * create a session message and that will be replicated. The cluster
+      * determines where it gets sent.
+      * 
+      * Session expiration also calls this method, but with expires == true.
+      * 
+      * @param sessionId -
+      *            the sessionId that just completed.
+      * @param expires -
+      *            whether this method has been called during session expiration
+      * @return a SessionMessage to be sent,
+      */
+     public ClusterMessage requestCompleted(String sessionId, boolean expires) {
         DeltaSession session = null;
         try {
             session = (DeltaSession) findSession(sessionId);
@@ -1129,7 +1148,7 @@ public class DeltaManager extends ClusterManagerBase{
                 }  
             }
             if(!isDeltaRequest) {
-                if(!session.isPrimarySession()) {               
+                if(!expires && !session.isPrimarySession()) {
                     counterSend_EVT_SESSION_ACCESSED++;
                     msg = new SessionMessageImpl(getName(),
                                                  SessionMessage.EVT_SESSION_ACCESSED, 
@@ -1145,9 +1164,10 @@ public class DeltaManager extends ClusterManagerBase{
                     log.debug(sm.getString("deltaManager.createMessage.delta",getName(), sessionId));
                 }
             }
-            session.setPrimarySession(true);
+            if (!expires)
+                session.setPrimarySession(true);
             //check to see if we need to send out an access message
-            if ((msg == null)) {
+            if (!expires && (msg == null)) {
                 long replDelta = System.currentTimeMillis() - session.getLastTimeReplicated();
                 if (replDelta > (getMaxInactiveInterval() * 1000)) {
                     counterSend_EVT_SESSION_ACCESSED++;
index 3429ee0..ea4dd7a 100644 (file)
@@ -38,7 +38,9 @@ import javax.servlet.http.HttpSessionContext;
 import org.apache.catalina.Manager;
 import org.apache.catalina.SessionListener;
 import org.apache.catalina.ha.ClusterManager;
+import org.apache.catalina.ha.CatalinaCluster;
 import org.apache.catalina.ha.ClusterSession;
+import org.apache.catalina.ha.ClusterMessage;
 import org.apache.catalina.realm.GenericPrincipal;
 import org.apache.catalina.session.StandardSession;
 import org.apache.catalina.tribes.io.ReplicationStream;
@@ -373,7 +375,24 @@ public class DeltaSession extends StandardSession implements Externalizable,Clus
     }
 
     public void expire(boolean notify, boolean notifyCluster) {
+        if (expiring)
+            return;
         String expiredId = getIdInternal();
+
+        if(expiredId != null && manager != null &&
+           manager instanceof DeltaManager) {
+            DeltaManager dmanager = (DeltaManager)manager;
+            CatalinaCluster cluster = dmanager.getCluster();
+            ClusterMessage msg = dmanager.requestCompleted(expiredId, true);
+            if (msg != null) {
+                if(dmanager.doDomainReplication()) {
+                    cluster.sendClusterDomain(msg);
+                } else {
+                    cluster.send(msg);
+                }
+            }
+        }
+
         super.expire(notify);
 
         if (notifyCluster) {