backport from trunk, prevent premature session expiration
authorfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 9 Aug 2007 23:46:47 +0000 (23:46 +0000)
committerfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 9 Aug 2007 23:46:47 +0000 (23:46 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk@564428 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/ha/context/ReplicatedContext.java
java/org/apache/catalina/ha/session/BackupManager.java
java/org/apache/catalina/tribes/tipis/AbstractReplicatedMap.java
java/org/apache/catalina/tribes/tipis/LazyReplicatedMap.java
java/org/apache/catalina/tribes/tipis/ReplicatedMap.java

index 370b054..402ea41 100644 (file)
@@ -36,12 +36,14 @@ import org.apache.catalina.LifecycleListener;
 import java.util.Enumeration;
 import java.util.concurrent.ConcurrentHashMap;
 import org.apache.catalina.util.Enumerator;
+import org.apache.catalina.tribes.tipis.AbstractReplicatedMap.MapOwner;
+import org.apache.catalina.ha.session.DeltaSession;
 
 /**
  * @author Filip Hanik
  * @version 1.0
  */
-public class ReplicatedContext extends StandardContext implements LifecycleListener {
+public class ReplicatedContext extends StandardContext implements LifecycleListener,MapOwner {
     private int mapSendOptions = Channel.SEND_OPTIONS_DEFAULT;
     public static org.apache.juli.logging.Log log = org.apache.juli.logging.LogFactory.getLog( ReplicatedContext.class );
     protected boolean startComplete = false;
@@ -193,5 +195,10 @@ public class ReplicatedContext extends StandardContext implements LifecycleListe
 
         }
     }
+    
+    public void objectMadePrimay(Object key, Object value) {
+        //noop
+    }
+
 
 }
\ No newline at end of file
index c4bc697..7e84a3a 100644 (file)
@@ -28,12 +28,14 @@ import org.apache.catalina.session.StandardManager;
 import org.apache.catalina.tribes.Channel;
 import org.apache.catalina.tribes.io.ReplicationStream;
 import org.apache.catalina.tribes.tipis.LazyReplicatedMap;
+import org.apache.catalina.tribes.tipis.AbstractReplicatedMap.MapOwner;
+import org.apache.catalina.tribes.tipis.AbstractReplicatedMap;
 
 /**
  *@author Filip Hanik
  *@version 1.0
  */
-public class BackupManager extends StandardManager implements ClusterManager
+public class BackupManager extends StandardManager implements ClusterManager, MapOwner
 {
     public static org.apache.juli.logging.Log log = org.apache.juli.logging.LogFactory.getLog( BackupManager.class );
 
@@ -133,6 +135,15 @@ public class BackupManager extends StandardManager implements ClusterManager
 //=========================================================================
 // OVERRIDE THESE METHODS TO IMPLEMENT THE REPLICATION
 //=========================================================================
+    public void objectMadePrimay(Object key, Object value) {
+        if (value!=null && value instanceof DeltaSession) {
+            DeltaSession session = (DeltaSession)value;
+            synchronized (session) {
+                session.access();
+                session.endAccess();
+            }
+        }
+    }
 
     public Session createEmptySession() {
         return new DeltaSession(this);
index 3ad4fa4..f8ba082 100644 (file)
@@ -113,7 +113,7 @@ public abstract class AbstractReplicatedMap extends ConcurrentHashMap implements
     /**
      * The owner of this map, ala a SessionManager for example
      */
-    protected transient Object mapOwner;
+    protected transient MapOwner mapOwner;
     /**
      * External class loaders if serialization and deserialization is to be performed successfully.
      */
@@ -137,7 +137,14 @@ public abstract class AbstractReplicatedMap extends ConcurrentHashMap implements
      * Readable string of the mapContextName value
      */
     protected transient String mapname = "";
+
+//------------------------------------------------------------------------------
+//              map owner interface
+//------------------------------------------------------------------------------
     
+    public static interface MapOwner {
+        public void objectMadePrimay(Object key, Object value);
+    }
 
 //------------------------------------------------------------------------------
 //              CONSTRUCTORS
@@ -152,7 +159,7 @@ public abstract class AbstractReplicatedMap extends ConcurrentHashMap implements
      * @param loadFactor float - load factor, see HashMap
      * @param cls - a list of classloaders to be used for deserialization of objects.
      */
-    public AbstractReplicatedMap(Object owner,
+    public AbstractReplicatedMap(MapOwner owner,
                                  Channel channel, 
                                  long timeout, 
                                  String mapContextName, 
@@ -185,7 +192,7 @@ public abstract class AbstractReplicatedMap extends ConcurrentHashMap implements
      * @param channelSendOptions int
      * @param cls ClassLoader[]
      */
-    protected void init(Object owner, Channel channel, String mapContextName, long timeout, int channelSendOptions,ClassLoader[] cls) {
+    protected void init(MapOwner owner, Channel channel, String mapContextName, long timeout, int channelSendOptions,ClassLoader[] cls) {
         log.info("Initializing AbstractReplicatedMap with context name:"+mapContextName);
         this.mapOwner = owner;
         this.externalLoaders = cls;
@@ -741,6 +748,8 @@ public abstract class AbstractReplicatedMap extends ConcurrentHashMap implements
                     entry.setProxy(false);
                     Member[] backup = publishEntryInfo(entry.getKey(), entry.getValue());
                     entry.setBackupNodes(backup);
+                    mapOwner.objectMadePrimay(entry.getKey(),entry.getValue());
+                    
                 } catch (ChannelException x) {
                     log.error("Unable to relocate[" + entry.getKey() + "] to a new backup node", x);
                 }
@@ -1420,7 +1429,7 @@ public abstract class AbstractReplicatedMap extends ConcurrentHashMap implements
         return stateTransferred;
     }
 
-    public Object getMapOwner() {
+    public MapOwner getMapOwner() {
         return mapOwner;
     }
 
@@ -1436,7 +1445,7 @@ public abstract class AbstractReplicatedMap extends ConcurrentHashMap implements
         return accessTimeout;
     }
 
-    public void setMapOwner(Object mapOwner) {
+    public void setMapOwner(MapOwner mapOwner) {
         this.mapOwner = mapOwner;
     }
 
index 59f2d75..4b8296c 100644 (file)
@@ -26,6 +26,7 @@ import org.apache.catalina.tribes.MembershipListener;
 import org.apache.catalina.tribes.group.RpcCallback;
 import org.apache.catalina.tribes.util.Arrays;
 import org.apache.catalina.tribes.UniqueId;
+import org.apache.catalina.tribes.tipis.AbstractReplicatedMap.MapOwner;
 
 /**
  * A smart implementation of a stateful replicated map. uses primary/secondary backup strategy. 
@@ -68,7 +69,7 @@ public class LazyReplicatedMap extends AbstractReplicatedMap
     implements RpcCallback, ChannelListener, MembershipListener {
     protected static org.apache.juli.logging.Log log = org.apache.juli.logging.LogFactory.getLog(LazyReplicatedMap.class);
     
-    
+
     
 //------------------------------------------------------------------------------    
 //              CONSTRUCTORS / DESTRUCTORS
@@ -81,7 +82,7 @@ public class LazyReplicatedMap extends AbstractReplicatedMap
          * @param initialCapacity int - the size of this map, see HashMap
          * @param loadFactor float - load factor, see HashMap
          */
-        public LazyReplicatedMap(Object owner, Channel channel, long timeout, String mapContextName, int initialCapacity, float loadFactor, ClassLoader[] cls) {
+        public LazyReplicatedMap(MapOwner owner, Channel channel, long timeout, String mapContextName, int initialCapacity, float loadFactor, ClassLoader[] cls) {
             super(owner,channel,timeout,mapContextName,initialCapacity,loadFactor, Channel.SEND_OPTIONS_DEFAULT,cls);
         }
 
@@ -92,7 +93,7 @@ public class LazyReplicatedMap extends AbstractReplicatedMap
          * @param mapContextName String - unique name for this map, to allow multiple maps per channel
          * @param initialCapacity int - the size of this map, see HashMap
          */
-        public LazyReplicatedMap(Object owner, Channel channel, long timeout, String mapContextName, int initialCapacity, ClassLoader[] cls) {
+        public LazyReplicatedMap(MapOwner owner, Channel channel, long timeout, String mapContextName, int initialCapacity, ClassLoader[] cls) {
             super(owner, channel,timeout,mapContextName,initialCapacity, LazyReplicatedMap.DEFAULT_LOAD_FACTOR, Channel.SEND_OPTIONS_DEFAULT, cls);
         }
 
@@ -102,7 +103,7 @@ public class LazyReplicatedMap extends AbstractReplicatedMap
          * @param timeout long - timeout for RPC messags
          * @param mapContextName String - unique name for this map, to allow multiple maps per channel
          */
-        public LazyReplicatedMap(Object owner, Channel channel, long timeout, String mapContextName, ClassLoader[] cls) {
+        public LazyReplicatedMap(MapOwner owner, Channel channel, long timeout, String mapContextName, ClassLoader[] cls) {
             super(owner, channel,timeout,mapContextName, LazyReplicatedMap.DEFAULT_INITIAL_CAPACITY,LazyReplicatedMap.DEFAULT_LOAD_FACTOR,Channel.SEND_OPTIONS_DEFAULT, cls);
         }
 
index d66b3a2..ce63574 100644 (file)
@@ -24,6 +24,7 @@ import org.apache.catalina.tribes.ChannelListener;
 import org.apache.catalina.tribes.Member;
 import org.apache.catalina.tribes.MembershipListener;
 import org.apache.catalina.tribes.group.RpcCallback;
+import org.apache.catalina.tribes.tipis.AbstractReplicatedMap.MapOwner;
 
 /**
  * All-to-all replication for a hash map implementation. Each node in the cluster will carry an identical 
@@ -64,7 +65,7 @@ public class ReplicatedMap extends AbstractReplicatedMap implements RpcCallback,
      * @param initialCapacity int - the size of this map, see HashMap
      * @param loadFactor float - load factor, see HashMap
      */
-    public ReplicatedMap(Object owner, Channel channel, long timeout, String mapContextName, int initialCapacity,float loadFactor, ClassLoader[] cls) {
+    public ReplicatedMap(MapOwner owner, Channel channel, long timeout, String mapContextName, int initialCapacity,float loadFactor, ClassLoader[] cls) {
         super(owner,channel, timeout, mapContextName, initialCapacity, loadFactor, Channel.SEND_OPTIONS_DEFAULT, cls);
     }
 
@@ -75,7 +76,7 @@ public class ReplicatedMap extends AbstractReplicatedMap implements RpcCallback,
      * @param mapContextName String - unique name for this map, to allow multiple maps per channel
      * @param initialCapacity int - the size of this map, see HashMap
      */
-    public ReplicatedMap(Object owner, Channel channel, long timeout, String mapContextName, int initialCapacity, ClassLoader[] cls) {
+    public ReplicatedMap(MapOwner owner, Channel channel, long timeout, String mapContextName, int initialCapacity, ClassLoader[] cls) {
         super(owner,channel, timeout, mapContextName, initialCapacity, AbstractReplicatedMap.DEFAULT_LOAD_FACTOR,Channel.SEND_OPTIONS_DEFAULT, cls);
     }
 
@@ -85,7 +86,7 @@ public class ReplicatedMap extends AbstractReplicatedMap implements RpcCallback,
      * @param timeout long - timeout for RPC messags
      * @param mapContextName String - unique name for this map, to allow multiple maps per channel
      */
-    public ReplicatedMap(Object owner, Channel channel, long timeout, String mapContextName, ClassLoader[] cls) {
+    public ReplicatedMap(MapOwner owner, Channel channel, long timeout, String mapContextName, ClassLoader[] cls) {
         super(owner, channel, timeout, mapContextName,AbstractReplicatedMap.DEFAULT_INITIAL_CAPACITY, AbstractReplicatedMap.DEFAULT_LOAD_FACTOR, Channel.SEND_OPTIONS_DEFAULT, cls);
     }