[jboss-cvs] JBossAS SVN: r95743 - in trunk: testsuite/src/main/org/jboss/test/cluster/testutil and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Oct 29 06:36:56 EDT 2009
Author: bstansberry at jboss.com
Date: 2009-10-29 06:36:54 -0400 (Thu, 29 Oct 2009)
New Revision: 95743
Added:
trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/FailedExpirationTestCase.java
Modified:
trunk/testsuite/src/main/org/jboss/test/cluster/testutil/SessionTestUtil.java
trunk/tomcat/src/main/java/org/jboss/web/tomcat/service/session/ClusteredSession.java
trunk/tomcat/src/main/java/org/jboss/web/tomcat/service/session/JBossCacheManager.java
Log:
[JBAS-7412] Tighten handling of clustered session expiration
Added: trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/FailedExpirationTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/FailedExpirationTestCase.java (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/FailedExpirationTestCase.java 2009-10-29 10:36:54 UTC (rev 95743)
@@ -0,0 +1,281 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009 Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.test.cluster.defaultcfg.simpleweb.test;
+
+import static org.jboss.test.cluster.testutil.SessionTestUtil.validateExpectedAttributes;
+import static org.jboss.test.cluster.testutil.SessionTestUtil.validateNewSession;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import javax.servlet.http.HttpSessionBindingEvent;
+import javax.servlet.http.HttpSessionBindingListener;
+
+import junit.framework.TestCase;
+
+import org.jboss.cache.Fqn;
+import org.jboss.cache.pojo.PojoCache;
+import org.jboss.logging.Logger;
+import org.jboss.metadata.web.jboss.JBossWebMetaData;
+import org.jboss.test.cluster.testutil.JGroupsSystemPropertySupport;
+import org.jboss.test.cluster.testutil.SessionTestUtil;
+import org.jboss.test.cluster.web.mocks.BasicRequestHandler;
+import org.jboss.test.cluster.web.mocks.InvalidateSessionRequestHandler;
+import org.jboss.test.cluster.web.mocks.SetAttributesRequestHandler;
+import org.jboss.web.tomcat.service.session.JBossCacheManager;
+
+/**
+ * A FailedExpirationTestCase.
+ *
+ * @author Brian Stansberry
+ * @version $Revision: 1.1 $
+ */
+public class FailedExpirationTestCase extends TestCase
+{
+ private static final Logger log = Logger.getLogger(ConcurrentFailoverRequestsTestCase.class);
+
+ private static long testCount = System.currentTimeMillis();
+
+ private final JGroupsSystemPropertySupport jgSupport = new JGroupsSystemPropertySupport();
+ private Set<PojoCache> caches = new HashSet<PojoCache>();
+ private String tempDir;
+
+ /**
+ * Create a new FailedExpirationTestCase.
+ *
+ * @param name
+ */
+ public FailedExpirationTestCase(String name)
+ {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ jgSupport.setUpProperties();
+
+ File tmpDir = new File(System.getProperty("java.io.tmpdir"));
+ File root = new File(tmpDir, getClass().getSimpleName());
+ root.mkdirs();
+ root.deleteOnExit();
+ tempDir = root.getAbsolutePath();
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ try
+ {
+ super.tearDown();
+ }
+ finally
+ {
+ jgSupport.restoreProperties();
+
+ SessionTestUtil.clearDistributedCacheManagerFactory();
+
+ for (PojoCache cache : caches)
+ {
+ // Try to clean up so we avoid loading sessions
+ // from storage in later tests
+ try
+ {
+ log.info("Removing /JSESSION from " + cache.getCache().getLocalAddress());
+ cache.getCache().removeNode(Fqn.fromString("/JSESSION"));
+ }
+ catch (Exception e)
+ {
+ log.error("Cache " + cache.getCache().getLocalAddress() + ": " + e.getMessage(), e);
+ }
+
+ try
+ {
+ cache.stop();
+ cache.destroy();
+ }
+ catch (Exception e)
+ {
+ log.error("Cache " + cache.getCache().getLocalAddress() + ": " + e.getMessage(), e);
+ }
+
+ }
+
+ caches.clear();
+
+ SessionTestUtil.cleanFilesystem(tempDir);
+ }
+ }
+
+ public void testFailedInvalidation() throws Exception
+ {
+ ++testCount;
+
+ JBossWebMetaData webMetaData = SessionTestUtil.createWebMetaData(10, true, 1, -1);
+ webMetaData.getReplicationConfig().setMaxUnreplicatedInterval(0);
+ String warName = "test" + testCount;
+ JBossCacheManager jbcm = SessionTestUtil.createManager(warName, 2, true, null, false, false, null, caches);
+ jbcm.init(warName, webMetaData);
+ jbcm.start();
+
+ assertEquals(0, jbcm.getActiveSessionCount());
+ assertEquals(0, jbcm.getPassivatedSessionCount());
+
+ Map<String, Object> attrs = new HashMap<String, Object>();
+ attrs.put("failInvalid", new FailInvalidationAttribute());
+ attrs.put("failDeserialization", new FailDeserializationAttribute());
+
+ // Establish session.
+ SetAttributesRequestHandler setHandler = new SetAttributesRequestHandler(attrs, false);
+ SessionTestUtil.invokeRequest(jbcm, setHandler, null);
+ validateNewSession(setHandler);
+ String id = setHandler.getSessionId();
+ assertEquals(1, jbcm.getActiveSessionCount());
+ assertEquals(0, jbcm.getPassivatedSessionCount());
+
+ InvalidateSessionRequestHandler invalHandler = new InvalidateSessionRequestHandler(attrs.keySet(), false);
+ try
+ {
+ SessionTestUtil.invokeRequest(jbcm, invalHandler, id);
+ fail("Invalidation not rejected");
+ }
+ catch (RejectedException ok) {}
+ assertEquals(0, jbcm.getActiveSessionCount());
+ assertEquals(0, jbcm.getPassivatedSessionCount());
+ }
+
+ public void testFailedExpiration() throws Exception
+ {
+ ++testCount;
+
+ JBossWebMetaData webMetaData = SessionTestUtil.createWebMetaData(10, true, 1, -1);
+ webMetaData.getReplicationConfig().setMaxUnreplicatedInterval(0);
+ String warName = "test" + testCount;
+ JBossCacheManager jbcm = SessionTestUtil.createManager(warName, 2, true, null, false, false, null, caches);
+ jbcm.init(warName, webMetaData);
+ jbcm.start();
+
+ assertEquals(0, jbcm.getActiveSessionCount());
+ assertEquals(0, jbcm.getPassivatedSessionCount());
+
+ Map<String, Object> attrs = new HashMap<String, Object>();
+ attrs.put("failInvalid", new FailInvalidationAttribute());
+ attrs.put("failDeserialization", new FailDeserializationAttribute());
+
+ // Establish session.
+ SetAttributesRequestHandler setHandler = new SetAttributesRequestHandler(attrs, false);
+ SessionTestUtil.invokeRequest(jbcm, setHandler, null);
+ validateNewSession(setHandler);
+ String id = setHandler.getSessionId();
+ assertEquals(1, jbcm.getActiveSessionCount());
+ assertEquals(0, jbcm.getPassivatedSessionCount());
+
+ SessionTestUtil.sleepThread(2010);
+ jbcm.backgroundProcess();
+ assertEquals(0, jbcm.getActiveSessionCount());
+ assertEquals(0, jbcm.getPassivatedSessionCount());
+ }
+
+ public void testFailedExpirationAfterPassivation() throws Exception
+ {
+ ++testCount;
+
+ String passivationDir = SessionTestUtil.getPassivationDir(tempDir, testCount, 1);
+ JBossWebMetaData webMetaData = SessionTestUtil.createWebMetaData(10, true, 1, -1);
+ webMetaData.getReplicationConfig().setMaxUnreplicatedInterval(0);
+ String warName = "test" + testCount;
+ JBossCacheManager jbcm = SessionTestUtil.createManager(warName, 2, true, passivationDir, false, false, null, caches);
+ jbcm.init(warName, webMetaData);
+ jbcm.start();
+
+ assertEquals(0, jbcm.getActiveSessionCount());
+ assertEquals(0, jbcm.getPassivatedSessionCount());
+
+ Map<String, Object> attrs = new HashMap<String, Object>();
+ attrs.put("failInvalid", new FailInvalidationAttribute());
+ attrs.put("failDeserialization", new FailDeserializationAttribute());
+
+ // Establish session.
+ SetAttributesRequestHandler setHandler = new SetAttributesRequestHandler(attrs, false);
+ SessionTestUtil.invokeRequest(jbcm, setHandler, null);
+ validateNewSession(setHandler);
+ String id = setHandler.getSessionId();
+ assertEquals(1, jbcm.getActiveSessionCount());
+ assertEquals(0, jbcm.getPassivatedSessionCount());
+
+ SessionTestUtil.sleepThread(1010);
+ jbcm.backgroundProcess();
+ assertEquals(0, jbcm.getActiveSessionCount());
+ assertEquals(1, jbcm.getPassivatedSessionCount());
+
+ SessionTestUtil.sleepThread(1010);
+ jbcm.backgroundProcess();
+ assertEquals(0, jbcm.getActiveSessionCount());
+ assertEquals(0, jbcm.getPassivatedSessionCount());
+ }
+
+ public static class FailInvalidationAttribute extends FailDeserializationAttribute
+ implements HttpSessionBindingListener
+ {
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 1L;
+
+ public void valueBound(HttpSessionBindingEvent event)
+ {
+ // no-op
+ }
+
+ public void valueUnbound(HttpSessionBindingEvent arg0)
+ {
+ throw new RejectedException();
+ }
+ }
+
+ public static class FailDeserializationAttribute implements Serializable
+ {
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 1L;
+
+ private void readObject(java.io.ObjectInputStream in)
+ throws IOException, ClassNotFoundException
+ {
+ throw new RejectedException();
+ }
+
+ }
+
+ public static class RejectedException extends RuntimeException
+ {
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 1L;
+
+ }
+
+}
Modified: trunk/testsuite/src/main/org/jboss/test/cluster/testutil/SessionTestUtil.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/testutil/SessionTestUtil.java 2009-10-29 09:37:21 UTC (rev 95742)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/testutil/SessionTestUtil.java 2009-10-29 10:36:54 UTC (rev 95743)
@@ -21,9 +21,16 @@
*/
package org.jboss.test.cluster.testutil;
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.assertNull;
+import static junit.framework.Assert.assertTrue;
+
+import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import javax.management.MBeanServerConnection;
@@ -49,6 +56,7 @@
import org.jboss.cache.loader.FileCacheLoaderConfig;
import org.jboss.cache.pojo.PojoCache;
import org.jboss.cache.pojo.PojoCacheFactory;
+import org.jboss.logging.Logger;
import org.jboss.metadata.javaee.spec.EmptyMetaData;
import org.jboss.metadata.web.jboss.JBossWebMetaData;
import org.jboss.metadata.web.jboss.PassivationConfig;
@@ -57,6 +65,7 @@
import org.jboss.metadata.web.jboss.ReplicationTrigger;
import org.jboss.metadata.web.jboss.SnapshotMode;
import org.jboss.test.cluster.web.CacheHelper;
+import org.jboss.test.cluster.web.mocks.BasicRequestHandler;
import org.jboss.test.cluster.web.mocks.MockEngine;
import org.jboss.test.cluster.web.mocks.MockHost;
import org.jboss.test.cluster.web.mocks.MockRequest;
@@ -76,7 +85,8 @@
* @version $Revision$
*/
public class SessionTestUtil
-{
+{
+ private static final Logger log = Logger.getLogger(SessionTestUtil.class);
private static final String[] STRING_ONLY_TYPES = { String.class.getName() };
private static final String[] STRING_BOOLEAN_TYPES = { String.class.getName(), boolean.class.getName() };
private static final String CONFIG_LOCATION = "cluster/http/jboss-web-test-service.xml";
@@ -517,6 +527,79 @@
sessionID.setDomain(server);
client.getState().addCookie(sessionID);
}
+
+ public static void validateExpectedAttributes(Map<String, Object> expected, BasicRequestHandler handler)
+ {
+ assertFalse(handler.isNewSession());
+
+ if (handler.isCheckAttributeNames())
+ {
+ assertEquals(expected.size(), handler.getAttributeNames().size());
+ }
+ Map<String, Object> checked = handler.getCheckedAttributes();
+ assertEquals(expected.size(), checked.size());
+ for (Map.Entry<String, Object> entry : checked.entrySet())
+ {
+ assertEquals(entry.getKey(), expected.get(entry.getKey()), entry.getValue());
+ }
+
+ }
+
+ public static void validateNewSession(BasicRequestHandler handler)
+ {
+ assertTrue(handler.isNewSession());
+ assertEquals(handler.getCreationTime(), handler.getLastAccessedTime());
+ if (handler.isCheckAttributeNames())
+ {
+ assertEquals(0, handler.getAttributeNames().size());
+ }
+ Map<String, Object> checked = handler.getCheckedAttributes();
+ for (Map.Entry<String, Object> entry : checked.entrySet())
+ assertNull(entry.getKey(), entry.getValue());
+ }
+
+ public static String getPassivationDir(String rootDir, long testCount, int cacheCount)
+ {
+ File dir = new File(rootDir);
+ dir = new File(dir, String.valueOf(testCount));
+ dir.mkdirs();
+ dir.deleteOnExit();
+ dir = new File(dir, String.valueOf(cacheCount));
+ dir.mkdirs();
+ dir.deleteOnExit();
+ return dir.getAbsolutePath();
+ }
+
+ public static void cleanFilesystem(String path)
+ {
+ if (path != null)
+ {
+ File f = new File(path);
+ if (f.exists())
+ {
+ if (f.isDirectory())
+ {
+ File[] children = f.listFiles();
+ for (File child : children)
+ {
+ try
+ {
+ cleanFilesystem(child.getCanonicalPath());
+ }
+ catch (IOException e)
+ {
+ log.warn("Can't clean any possible children of " + f);
+ }
+ }
+ }
+
+ if (!f.delete())
+ {
+ f.delete();
+ }
+ }
+ }
+ }
/**
Modified: trunk/tomcat/src/main/java/org/jboss/web/tomcat/service/session/ClusteredSession.java
===================================================================
--- trunk/tomcat/src/main/java/org/jboss/web/tomcat/service/session/ClusteredSession.java 2009-10-29 09:37:21 UTC (rev 95742)
+++ trunk/tomcat/src/main/java/org/jboss/web/tomcat/service/session/ClusteredSession.java 2009-10-29 10:36:54 UTC (rev 95743)
@@ -496,7 +496,7 @@
public void setManager(Manager manager)
{
- if ((manager instanceof ClusteredManager) == false)
+ if ((manager instanceof ClusteredManager<?>) == false)
throw new IllegalArgumentException("manager must implement ClusteredManager");
@SuppressWarnings("unchecked")
ClusteredManager<O> unchecked = (ClusteredManager) manager;
@@ -1413,81 +1413,112 @@
return;
expiring = true;
-
- // Notify interested application event listeners
- // FIXME - Assumes we call listeners in reverse order
- Context context = (Context) manager.getContainer();
- Object lifecycleListeners[] = context.getApplicationSessionLifecycleListeners();
- if (notify
- && (lifecycleListeners != null)
- && notificationPolicy.isHttpSessionListenerInvocationAllowed(this.clusterStatus, cause, localCall))
- {
- HttpSessionEvent event =
- new HttpSessionEvent(getSession());
- for (int i = 0; i < lifecycleListeners.length; i++)
- {
- int j = (lifecycleListeners.length - 1) - i;
- if (!(lifecycleListeners[j] instanceof HttpSessionListener))
- continue;
- HttpSessionListener listener =
- (HttpSessionListener) lifecycleListeners[j];
- try
- {
- fireContainerEvent(context,
- "beforeSessionDestroyed",
- listener);
- listener.sessionDestroyed(event);
- fireContainerEvent(context,
- "afterSessionDestroyed",
- listener);
- }
- catch (Throwable t)
- {
- try
- {
- fireContainerEvent(context,
- "afterSessionDestroyed",
- listener);
- }
- catch (Exception e)
- {
- ;
- }
- manager.getContainer().getLogger().error(sm.getString("clusteredSession.sessionEvent"), t);
- }
- }
- }
- if (ACTIVITY_CHECK) {
- accessCount.set(0);
- }
-
- // Notify interested session event listeners.
- if (notify)
+ // SRV.10.6 (2.5) 11.6 (3.0) Propagate listener exceptions
+ RuntimeException listenerException = null;
+ try
{
- fireSessionEvent(Session.SESSION_DESTROYED_EVENT, null);
+ // Notify interested application event listeners
+ // FIXME - Assumes we call listeners in reverse order
+ Context context = (Context) manager.getContainer();
+ Object lifecycleListeners[] = context.getApplicationSessionLifecycleListeners();
+ if (notify
+ && (lifecycleListeners != null)
+ && notificationPolicy.isHttpSessionListenerInvocationAllowed(this.clusterStatus, cause, localCall))
+ {
+ HttpSessionEvent event =
+ new HttpSessionEvent(getSession());
+ for (int i = 0; i < lifecycleListeners.length; i++)
+ {
+ int j = (lifecycleListeners.length - 1) - i;
+ if (!(lifecycleListeners[j] instanceof HttpSessionListener))
+ continue;
+ HttpSessionListener listener =
+ (HttpSessionListener) lifecycleListeners[j];
+ try
+ {
+ fireContainerEvent(context,
+ "beforeSessionDestroyed",
+ listener);
+ try
+ {
+ listener.sessionDestroyed(event);
+ }
+ catch (RuntimeException e)
+ {
+ if (listenerException == null)
+ {
+ listenerException = e;
+ }
+ }
+ fireContainerEvent(context,
+ "afterSessionDestroyed",
+ listener);
+ }
+ catch (Throwable t)
+ {
+ try
+ {
+ fireContainerEvent(context,
+ "afterSessionDestroyed",
+ listener);
+ }
+ catch (Exception e)
+ {
+ ;
+ }
+ manager.getContainer().getLogger().error(sm.getString("clusteredSession.sessionEvent"), t);
+ }
+ }
+ }
+
+ if (ACTIVITY_CHECK) {
+ accessCount.set(0);
+ }
+
+ // Notify interested session event listeners.
+ if (notify)
+ {
+ fireSessionEvent(Session.SESSION_DESTROYED_EVENT, null);
+ }
+
+ // JBAS-1360 -- Unbind any objects associated with this session
+ String keys[] = keys();
+ for (int i = 0; i < keys.length; i++)
+ {
+ try
+ {
+ removeAttributeInternal(keys[i], localCall, localOnly, notify, cause);
+ }
+ catch (RuntimeException e)
+ {
+ if (listenerException == null)
+ {
+ listenerException = e;
+ }
+ }
+ }
+
+ // Remove this session from our manager's active sessions
+ // If !localCall, this expire call came from the manager,
+ // so don't recurse
+ if (localCall)
+ {
+ removeFromManager(localOnly);
+ }
+
+ if (listenerException != null)
+ {
+ throw listenerException;
+ }
}
-
- // JBAS-1360 -- Unbind any objects associated with this session
- String keys[] = keys();
- for (int i = 0; i < keys.length; i++)
+ finally
{
- removeAttributeInternal(keys[i], localCall, localOnly, notify, cause);
+ // We have completed expire of this session
+ setValid(false);
+ expiring = false;
}
-
- // Remove this session from our manager's active sessions
- // If !localCall, this expire call came from the manager,
- // so don't recurse
- if (localCall)
- {
- removeFromManager(localOnly);
- }
-
- // We have completed expire of this session
- setValid(false);
- expiring = false;
}
-
}
/**
@@ -1894,43 +1925,62 @@
{
Context context = (Context) manager.getContainer();
Object lifecycleListeners[] = context.getApplicationEventListeners();
- if (lifecycleListeners == null)
- return;
- for (int i = 0; i < lifecycleListeners.length; i++)
+ if (lifecycleListeners != null)
{
- if (!(lifecycleListeners[i] instanceof HttpSessionAttributeListener))
- continue;
- HttpSessionAttributeListener listener =
- (HttpSessionAttributeListener) lifecycleListeners[i];
- try
+ // SRV.10.6 (2.5) 11.6 (3.0) Propagate listener exceptions
+ RuntimeException listenerException = null;
+
+ for (int i = 0; i < lifecycleListeners.length; i++)
{
- fireContainerEvent(context,
- "beforeSessionAttributeRemoved",
- listener);
- if (event == null)
- {
- event = new HttpSessionBindingEvent
- (getSession(), name, value);
- }
- listener.attributeRemoved(event);
- fireContainerEvent(context,
- "afterSessionAttributeRemoved",
- listener);
- }
- catch (Throwable t)
- {
+ if (!(lifecycleListeners[i] instanceof HttpSessionAttributeListener))
+ continue;
+ HttpSessionAttributeListener listener =
+ (HttpSessionAttributeListener) lifecycleListeners[i];
try
{
fireContainerEvent(context,
+ "beforeSessionAttributeRemoved",
+ listener);
+ if (event == null)
+ {
+ event = new HttpSessionBindingEvent
+ (getSession(), name, value);
+ }
+ try
+ {
+ listener.attributeRemoved(event);
+ }
+ catch (RuntimeException e)
+ {
+ if (listenerException == null)
+ {
+ listenerException = e;
+ }
+ }
+ fireContainerEvent(context,
"afterSessionAttributeRemoved",
listener);
}
- catch (Exception e)
+ catch (Throwable t)
{
- ;
+ try
+ {
+ fireContainerEvent(context,
+ "afterSessionAttributeRemoved",
+ listener);
+ }
+ catch (Exception e)
+ {
+ ;
+ }
+ manager.getContainer().getLogger().error(sm.getString("clusteredSession.attributeEvent"), t);
}
- manager.getContainer().getLogger().error(sm.getString("clusteredSession.attributeEvent"), t);
}
+
+ if (listenerException != null)
+ {
+ throw listenerException;
+ }
}
}
}
Modified: trunk/tomcat/src/main/java/org/jboss/web/tomcat/service/session/JBossCacheManager.java
===================================================================
--- trunk/tomcat/src/main/java/org/jboss/web/tomcat/service/session/JBossCacheManager.java 2009-10-29 09:37:21 UTC (rev 95742)
+++ trunk/tomcat/src/main/java/org/jboss/web/tomcat/service/session/JBossCacheManager.java 2009-10-29 10:36:54 UTC (rev 95743)
@@ -342,7 +342,7 @@
if (session == null)
return;
- if (!(session instanceof ClusteredSession))
+ if (!(session instanceof ClusteredSession<?>))
{
throw new IllegalArgumentException("You can only add instances of " +
"type ClusteredSession to this Manager. Session class name: " +
@@ -1684,6 +1684,9 @@
{
return;
}
+
+ boolean likelyExpired = false;
+ String realId = null;
try
{
@@ -1694,17 +1697,22 @@
continue;
}
+ realId = session.getRealId();
+ likelyExpired = expire;
+
if (expire)
{
// JBAS-2403. Check for outdated sessions where we think
// the local copy has timed out. If found, refresh the
// session from the cache in case that might change the timeout
- if (this.outdatedSessionChecker.isSessionOutdated(session) && !(session.isValid(false)))
+ likelyExpired = (session.isValid(false) == false);
+ if (likelyExpired && this.outdatedSessionChecker.isSessionOutdated(session))
{
- // FIXME in AS 5 every time we get a notification from the distributed
+ // With JBC, every time we get a notification from the distributed
// cache of an update, we get the latest timestamp. So
// we shouldn't need to do a full session load here. A load
- // adds a risk of an unintended data gravitation.
+ // adds a risk of an unintended data gravitation. However,
+ // with a database instead of JBC we don't get notifications
// JBAS-2792 don't assign the result of loadSession to session
// just update the object from the cache or fall through if
@@ -1719,6 +1727,8 @@
// properly internally; synchronizing externally can lead
// to deadlocks!!
if (!session.isValid()) continue;
+
+ likelyExpired = false;
}
// we now have a valid session; store it so we can check later
@@ -1731,9 +1741,16 @@
}
catch (Exception ex)
{
- log_.error("processExpirationPassivation(): failed handling " +
- sessions[i].getIdInternal() + " with exception: " +
- ex, ex);
+ if (likelyExpired)
+ {
+ // JBAS-7397 clean up
+ bruteForceCleanup(realId, ex);
+ }
+ else
+ {
+ log_.error("processExpirationPassivation(): failed handling " + realId + " with exception: " + ex, ex);
+ }
+
}
}
@@ -1761,12 +1778,14 @@
String realId = entry.getKey();
OwnedSessionUpdate osu = entry.getValue();
+ boolean likelyExpired = false;
long now = System.currentTimeMillis();
long elapsed = (now - osu.getUpdateTime());
try
{
- if (expire && osu.getMaxInactive() >= 1 && elapsed >= (osu.getMaxInactive() + maxUnrep) * 1000L)
+ likelyExpired = expire && osu.getMaxInactive() >= 1 && elapsed >= (osu.getMaxInactive() + maxUnrep) * 1000L;
+ if (likelyExpired)
{
//if (osu.passivated && osu.owner == null)
if (osu.isPassivated())
@@ -1798,8 +1817,16 @@
}
catch (Exception ex)
{
- log_.error("processExpirationPassivation(): failed handling unloaded session " +
- realId, ex);
+ // JBAS-7397 Don't try forever
+ if (likelyExpired)
+ {
+ // JBAS-7397
+ bruteForceCleanup(realId, ex);
+ }
+ else
+ {
+ log_.error("processExpirationPassivation(): failed handling unloaded session " + realId, ex);
+ }
}
}
@@ -1971,6 +1998,28 @@
}
}
}
+
+ private void bruteForceCleanup(String realId, Exception ex)
+ {
+ log_.warn("Standard expiration of session " + realId
+ + " failed; switching to a brute " + "force cleanup. Problem is" + ex.getLocalizedMessage());
+ try
+ {
+ proxy_.removeSessionLocal(realId, null);
+ }
+ catch (Exception e)
+ {
+ log_.error("processExpirationPassivation(): Caught exception "
+ + "during brute force cleanup of unloaded session " + realId + " session will be removed from Manager "
+ + "but may still exist in distributed cache", e);
+ }
+ finally
+ {
+ // Get rid of our refs even if distributed store fails
+ unloadedSessions_.remove(realId);
+ stats_.removeStats(realId);
+ }
+ }
/**
* Loads a session from the distributed store. If an existing session with
More information about the jboss-cvs-commits
mailing list