[jboss-cvs] JBossAS SVN: r73113 - trunk/tomcat/src/main/org/jboss/web/tomcat/service/session.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed May 7 11:47:47 EDT 2008
Author: bstansberry at jboss.com
Date: 2008-05-07 11:47:47 -0400 (Wed, 07 May 2008)
New Revision: 73113
Modified:
trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/CacheListener.java
trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/JBossCacheManager.java
trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/JBossCacheService.java
Log:
[JBAS-4639] Optimized replication of ClusteredSession metadata
[JBAS-5404] Updated session maxInactiveInterval not respected on backup nodes
Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/CacheListener.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/CacheListener.java 2008-05-07 15:46:40 UTC (rev 73112)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/CacheListener.java 2008-05-07 15:47:47 UTC (rev 73113)
@@ -21,6 +21,8 @@
*/
package org.jboss.web.tomcat.service.session;
+import java.util.Map;
+
import org.jboss.cache.Fqn;
import org.jboss.cache.notifications.annotation.CacheStarted;
import org.jboss.cache.notifications.annotation.CacheStopped;
@@ -32,6 +34,8 @@
import org.jboss.cache.notifications.event.NodeRemovedEvent;
import org.jboss.logging.Logger;
import org.jboss.metadata.web.jboss.ReplicationGranularity;
+import org.jboss.web.tomcat.service.session.ClusteredSession.SessionMetadata;
+import org.jboss.web.tomcat.service.session.ClusteredSession.SessionTimestamp;
@org.jboss.cache.notifications.annotation.CacheListener
public class CacheListener extends CacheListenerBase
@@ -99,7 +103,8 @@
// Query if we have version value in the distributed cache.
// If we have a version value, compare the version and invalidate if necessary.
- Integer version = (Integer) event.getData().get(JBossCacheService.VERSION_KEY);
+ Map data = event.getData();
+ Integer version = (Integer) data.get(JBossCacheService.VERSION_KEY);
if(version != null)
{
String realId = getIdFromFqn(fqn, isBuddy);
@@ -109,7 +114,9 @@
{
String owner = isBuddy ? getBuddyOwner(fqn) : null;
// Notify the manager that an unloaded session has been updated
- manager_.unloadedSessionChanged(realId, owner);
+ manager_.unloadedSessionChanged(realId, owner,
+ (SessionTimestamp) data.get(JBossCacheService.TIMESTAMP_KEY),
+ (SessionMetadata) data.get(JBossCacheService.METADATA_KEY));
}
else if (session.isNewData(version.intValue()))
{
Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/JBossCacheManager.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/JBossCacheManager.java 2008-05-07 15:46:40 UTC (rev 73112)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/JBossCacheManager.java 2008-05-07 15:47:47 UTC (rev 73113)
@@ -62,6 +62,8 @@
import org.jboss.metadata.web.jboss.SnapshotMode;
import org.jboss.mx.util.MBeanServerLocator;
import org.jboss.util.loading.ContextClassLoaderSwitcher;
+import org.jboss.web.tomcat.service.session.ClusteredSession.SessionMetadata;
+import org.jboss.web.tomcat.service.session.ClusteredSession.SessionTimestamp;
/**
* Implementation of a clustered session manager for
@@ -1464,7 +1466,6 @@
return;
}
- long expirationInterval = maxInactiveInterval_ * 1000L;
long passivationMax = passivationMaxIdleTime_ * 1000L;
long passivationMin = passivationMinIdleTime_ * 1000L;
@@ -1562,12 +1563,13 @@
String realId = (String) entry.getKey();
OwnedSessionUpdate osu = (OwnedSessionUpdate) entry.getValue();
// Ignore marker entries for our own passivated sessions
- if (osu.passivated)
+ // Also skip if the session isn't configured to expire
+ if (osu.passivated || osu.maxInactive < 1)
continue;
long elapsed = (now - osu.updateTime);
try
{
- if (expire && elapsed >= expirationInterval)
+ if (expire && elapsed >= (osu.maxInactive * 1000L))
{
proxy_.removeSessionLocal(realId, osu.owner);
unloadedSessions_.remove(realId);
@@ -1782,7 +1784,7 @@
// Put the session in the unloadedSessions map. This will
// expose the session to regular invalidation.
Object obj = unloadedSessions_.put(realId,
- new OwnedSessionUpdate(null, session.getLastAccessedTime(), true));
+ new OwnedSessionUpdate(null, session.getLastAccessedTime(), session.getMaxInactiveInterval(), true));
if (log_.isTraceEnabled())
{
if (obj == null)
@@ -1850,10 +1852,15 @@
* @param dataOwner the owner of the session. Can be <code>null</code> if
* the owner is unknown.
*/
- protected void unloadedSessionChanged(String realId, String dataOwner)
+ protected void unloadedSessionChanged(String realId,
+ String dataOwner,
+ SessionTimestamp timestamp,
+ SessionMetadata metadata)
{
+ long lastMod = timestamp == null ? System.currentTimeMillis() : timestamp.timestamp;
+ int maxLife = metadata == null ? getMaxInactiveInterval() : metadata.maxInactiveInterval;
Object obj = unloadedSessions_.put(realId,
- new OwnedSessionUpdate(dataOwner, System.currentTimeMillis(), false));
+ new OwnedSessionUpdate(dataOwner, lastMod, maxLife, false));
if (log_.isTraceEnabled())
{
if (obj == null)
@@ -2099,32 +2106,66 @@
/**
* Gets the ids of all sessions in the distributed cache and adds
- * them to the unloaded sessions map, with the current time as the
- * last replication time. This means these sessions may not be
- * evicted from the cache for a period well beyond when they would
- * normally expire, but this is a necessary tradeoff to avoid
- * deserializing them all to check their lastAccessedTime.
+ * them to the unloaded sessions map, along with their lastAccessedTime
+ * and their maxInactiveInterval. Passivates overage or excess sessions.
*/
private void initializeUnloadedSessions() throws CacheException
{
Map<String, String> sessions = proxy_.getSessionIds();
if (sessions != null)
{
- boolean passivateExcess = isPassivationEnabled()
- && maxActive_ > 0
- && passivationMinIdleTime_ >= 0;
- long now = System.currentTimeMillis();
- for (Iterator<Map.Entry<String, String>> it = sessions.entrySet().iterator(); it.hasNext(); )
+ boolean passivate = isPassivationEnabled();
+
+ long passivationMax = passivationMaxIdleTime_ * 1000L;
+ long passivationMin = passivationMinIdleTime_ * 1000L;
+
+ for (Map.Entry<String, String> entry : sessions.entrySet())
{
- Map.Entry<String, String> entry = it.next();
String realId = entry.getKey();
- OwnedSessionUpdate osu = new OwnedSessionUpdate(entry.getValue(), now, false);
+ String owner = entry.getValue();
+
+ SessionTimestamp ts = null;
+ SessionMetadata md = null;
+ try
+ {
+ Map sessionData = proxy_.getSessionData(realId, owner);
+ ts = (SessionTimestamp) sessionData.get(JBossCacheService.TIMESTAMP_KEY);
+ md = (SessionMetadata) sessionData.get(JBossCacheService.METADATA_KEY);
+ }
+ catch (Exception e)
+ {
+ // most likely a lock conflict if the session is being updated remotely;
+ // ignore it and use default values for timstamp and maxInactive
+ log_.debug("Problem reading metadata for session " + realId + " -- " + e.toString());
+ }
+
+ long lastMod = ts == null ? System.currentTimeMillis() : ts.timestamp;
+ int maxLife = md == null ? getMaxInactiveInterval() : md.maxInactiveInterval;
+
+ OwnedSessionUpdate osu = new OwnedSessionUpdate(owner, lastMod, maxLife, false);
unloadedSessions_.put(realId, osu);
- if (passivateExcess && calcActiveSessions() > maxActive_)
+ if (passivate)
{
try
{
- processUnloadedSessionPassivation(realId, osu);
+ long elapsed = System.currentTimeMillis() - lastMod;
+ // if maxIdle time configured, means that we need to passivate sessions that have
+ // exceeded the max allowed idle time
+ if (passivationMax >= 0
+ && elapsed > passivationMax)
+ {
+ processUnloadedSessionPassivation(realId, osu);
+ }
+ // If the session didn't exceed the passivationMaxIdleTime_, see
+ // if the number of sessions managed by this manager greater than the max allowed
+ // active sessions, passivate the session if it exceed passivationMinIdleTime_
+ else if (maxActive_ > 0
+ && passivationMin >= 0
+ && calcActiveSessions() >= maxActive_
+ && elapsed >= passivationMin)
+ {
+ processUnloadedSessionPassivation(realId, osu);
+ }
}
catch (Exception e)
{
@@ -2361,12 +2402,14 @@
{
String owner;
long updateTime;
+ int maxInactive;
boolean passivated;
- OwnedSessionUpdate(String owner, long updateTime, boolean passivated)
+ OwnedSessionUpdate(String owner, long updateTime, int maxInactive, boolean passivated)
{
this.owner = owner;
this.updateTime = updateTime;
+ this.maxInactive = maxInactive;
this.passivated = passivated;
}
}
Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/JBossCacheService.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/JBossCacheService.java 2008-05-07 15:46:40 UTC (rev 73112)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/JBossCacheService.java 2008-05-07 15:47:47 UTC (rev 73113)
@@ -376,6 +376,12 @@
Fqn fqn = getSessionFqn(realId);
return plainCache_.getRoot().hasChild(fqn);
}
+
+ public Map getSessionData(String realId, String dataOwner)
+ {
+ Fqn fqn = dataOwner == null ? getSessionFqn(realId) : getSessionFqn(realId, dataOwner);
+ return cacheWrapper_.getData(fqn, false);
+ }
public Object getAttribute(String realId, String key)
{
More information about the jboss-cvs-commits
mailing list