[jboss-cvs] JBossAS SVN: r92157 - in trunk: tomcat/src/main/org/jboss/web/tomcat/service/session and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Aug 7 18:25:26 EDT 2009


Author: bstansberry at jboss.com
Date: 2009-08-07 18:25:26 -0400 (Fri, 07 Aug 2009)
New Revision: 92157

Added:
   trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/StoppedManagerUnitTestCase.java
Modified:
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/JBossCacheManager.java
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/SessionReplicationContext.java
Log:
[JBAS-7123] JBossCacheManager remains open to requests after shutdown

Added: trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/StoppedManagerUnitTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/StoppedManagerUnitTestCase.java	                        (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/StoppedManagerUnitTestCase.java	2009-08-07 22:25:26 UTC (rev 92157)
@@ -0,0 +1,179 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, 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 java.util.HashSet;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+import org.apache.catalina.Manager;
+import org.apache.catalina.Session;
+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.SessionTestUtil;
+import org.jboss.web.tomcat.service.session.JBossCacheManager;
+
+/**
+ * Tests that a stopped session manager reacts correctly to Manager API calls.
+ * Used to validate that races during undeploy will not lead to errors.
+ * 
+ * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
+ * @version $Revision: 85945 $
+ */
+public class StoppedManagerUnitTestCase extends TestCase
+{
+   private static final Logger log = Logger.getLogger(StoppedManagerUnitTestCase.class);
+   
+   private static long testCount = System.currentTimeMillis();
+   
+   private Set<PojoCache> caches = new HashSet<PojoCache>();
+   
+   /**
+    * Create a new SessionCountUnitTestCase.
+    * 
+    * @param name
+    */
+   public StoppedManagerUnitTestCase(String name)
+   {
+      super(name);
+   } 
+
+   @Override
+   protected void tearDown() throws Exception
+   {
+      try
+      {
+         super.tearDown();
+      }
+      finally
+      {      
+         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();
+      }
+   }
+
+   public void testStoppedManager() throws Exception
+   {
+      log.info("Enter testStoppedManager");
+      
+      ++testCount;
+      
+      JBossCacheManager jbcm = SessionTestUtil.createManager("test" + testCount, 30, true, null, false, false, null, caches);
+       
+      JBossWebMetaData webMetaData = SessionTestUtil.createWebMetaData(100);
+      jbcm.init("test.war", webMetaData);
+      
+      jbcm.start();
+      
+      // Set up a session
+      Session sess1 = createAndUseSession(jbcm, "1", true, true);      
+      Session sess2 = createAndUseSession(jbcm, "2", true, true);
+      
+      // Sanity check
+      Session[] sessions = jbcm.findSessions();
+      assertNotNull(sessions);
+      assertEquals(2, sessions.length);
+      
+      jbcm.stop();
+      
+      assertNull(jbcm.findSession("1"));
+      assertNull(jbcm.findSession("2"));
+      assertNull(jbcm.findSessions());
+      assertNull(jbcm.createEmptySession());
+      assertNull(jbcm.createSession());
+      assertNull(jbcm.createSession("3"));
+      
+      assertFalse(sess1.isValid());
+      assertFalse(sess2.isValid());
+      jbcm.add(sess1); // shouldn't blow up
+      assertFalse(sess1.isValid());
+      
+      jbcm.remove(sess2);
+   }
+   
+   private Session createAndUseSession(JBossCacheManager jbcm, String id, 
+                           boolean canCreate, boolean access)
+         throws Exception
+   {
+      //    Shift to Manager interface when we simulate Tomcat
+      Manager mgr = jbcm;
+      Session sess = mgr.findSession(id);
+      assertNull("session does not exist", sess);
+      try
+      {
+         sess = mgr.createSession(id);
+         if (!canCreate)
+            fail("Could not create session" + id);
+      }
+      catch (IllegalStateException ise)
+      {
+         if (canCreate)
+         {
+            log.error("Failed to create session " + id, ise);
+            fail("Could create session " + id);
+         }
+      }
+      
+      if (access)
+      {
+         sess.access();
+         sess.getSession().setAttribute("test", "test");
+         
+         jbcm.storeSession(sess);
+         
+         sess.endAccess();
+      }
+      
+      return sess;
+   }
+}


Property changes on: trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/StoppedManagerUnitTestCase.java
___________________________________________________________________
Name: svn:executable
   + *
Name: svn:keywords
   + 

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	2009-08-07 22:18:33 UTC (rev 92156)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/JBossCacheManager.java	2009-08-07 22:25:26 UTC (rev 92157)
@@ -157,6 +157,8 @@
 
    private OutdatedSessionChecker outdatedSessionChecker;
    
+   private volatile boolean stopping;
+   
    //  ----------------------------------------------------------  Constructors
 
    public JBossCacheManager() throws ClusteringNotSupportedException
@@ -339,19 +341,75 @@
                session.getClass().getName());
       }
 
-      add(uncheckedCastSession(session), false); // wait to replicate until req end
+      try
+      {
+         // [JBAS-7123] Make sure we're either in the call stack where LockingValve has
+         // a lock, or that we acquire one ourselves
+         boolean inLockingValve = SessionReplicationContext.isLocallyActive();
+         if (inLockingValve || this.valveLock.tryLock(0, TimeUnit.SECONDS))
+         {
+            try
+            {
+               add(uncheckedCastSession(session), false); // wait to replicate until req end
+            }
+            finally
+            {
+               if (!inLockingValve)
+               {
+                  this.valveLock.unlock();
+               }
+            }
+         }
+         else if (trace_)
+         {
+            log_.trace("add(): ignoring add -- Manager is not actively handling requests");
+         }
+      }
+      catch (InterruptedException e)
+      {
+         Thread.currentThread().interrupt();
+      }
    }
 
    // Satisfy the Manager interface.  Internally we use
    // createEmptyClusteredSession to avoid a cast
    public Session createEmptySession()
    {
-      if (trace_)
+      Session session = null;
+      try
       {
-         log_.trace("Creating an empty ClusteredSession");
+         // [JBAS-7123] Make sure we're either in the call stack where LockingValve has
+         // a lock, or that we acquire one ourselves
+         boolean inLockingValve = SessionReplicationContext.isLocallyActive();
+         if (inLockingValve || this.valveLock.tryLock(0, TimeUnit.SECONDS))
+         {
+            try
+            {
+               if (trace_)
+               {
+                  log_.trace("Creating an empty ClusteredSession");
+               }
+               session = createEmptyClusteredSession();
+            }
+            finally
+            {
+               if (!inLockingValve)
+               {
+                  this.valveLock.unlock();
+               }
+            }
+         }
+         else if (trace_)
+         {
+            log_.trace("createEmptySession(): Manager is not handling requests; returning null");
+         }
       }
+      catch (InterruptedException e)
+      {
+         Thread.currentThread().interrupt();
+      }
       
-      return createEmptyClusteredSession();
+      return session;
    }
    
    /**
@@ -366,7 +424,42 @@
     * {@inheritDoc}
     */
    public Session createSession(String sessionId)
-   {      
+   {  
+      Session session = null;
+      try
+      {
+         // [JBAS-7123] Make sure we're either in the call stack where LockingValve has
+         // a lock, or that we acquire one ourselves
+         boolean inLockingValve = SessionReplicationContext.isLocallyActive();
+         if (inLockingValve || this.valveLock.tryLock(0, TimeUnit.SECONDS))
+         {
+            try
+            {
+               session = createSessionInternal(sessionId);
+            }
+            finally
+            {
+               if (!inLockingValve)
+               {
+                  this.valveLock.unlock();
+               }
+            }
+         }
+         else if (trace_)
+         {
+            log_.trace("createEmptySession(): Manager is not handling requests; returning null");
+         }
+      }
+      catch (InterruptedException e)
+      {
+         Thread.currentThread().interrupt();
+      }
+      
+      return session;
+   }
+
+   private Session createSessionInternal(String sessionId)
+   {
       // First check if we've reached the max allowed sessions, 
       // then try to expire/passivate sessions to free memory
       // maxActiveAllowed_ -1 is unlimited
@@ -399,55 +492,58 @@
 
       ClusteredSession<? extends OutgoingDistributableSessionData> session = createEmptyClusteredSession();
 
-      session.setNew(true);
-      session.setCreationTime(System.currentTimeMillis());
-      session.setMaxInactiveInterval(this.maxInactiveInterval_);
-      session.setValid(true);
-
-      String clearInvalidated = null; // see below
-      
-      if (sessionId == null)
+      if (session != null)
       {
-          sessionId = this.getNextId();
-
-          // We are using mod_jk for load balancing. Append the JvmRoute.
-          if (getUseJK())
-          {
-              if (trace_)
-              {
-                  log_.trace("createSession(): useJK is true. Will append JvmRoute: " + this.getJvmRoute());
-              }
-              sessionId += "." + this.getJvmRoute();
-          }
+         session.setNew(true);
+         session.setCreationTime(System.currentTimeMillis());
+         session.setMaxInactiveInterval(this.maxInactiveInterval_);
+         session.setValid(true);
+   
+         String clearInvalidated = null; // see below
+         
+         if (sessionId == null)
+         {
+             sessionId = this.getNextId();
+   
+             // We are using mod_jk for load balancing. Append the JvmRoute.
+             if (getUseJK())
+             {
+                 if (trace_)
+                 {
+                     log_.trace("createSession(): useJK is true. Will append JvmRoute: " + this.getJvmRoute());
+                 }
+                 sessionId += "." + this.getJvmRoute();
+             }
+         }
+         else
+         {
+            clearInvalidated = sessionId;
+         }
+   
+         session.setId(sessionId); // Setting the id leads to a call to add()
+         
+         getDistributedCacheManager().sessionCreated(session.getRealId());
+         
+         session.tellNew(ClusteredSessionNotificationCause.CREATE);
+   
+         if (trace_)
+         {
+            log_.trace("Created a ClusteredSession with id: " + sessionId);
+         }
+   
+         createdCounter_.incrementAndGet(); // the call to add() handles the other counters 
+         
+         // Add this session to the set of those potentially needing replication
+         SessionReplicationContext.bindSession(session, snapshotManager_);
+         
+         if (clearInvalidated != null)
+         {
+            // We no longer need to track any earlier session w/ same id 
+            // invalidated by this thread
+            SessionInvalidationTracker.clearInvalidatedSession(clearInvalidated, this);
+         }
       }
-      else
-      {
-         clearInvalidated = sessionId;
-      }
-
-      session.setId(sessionId); // Setting the id leads to a call to add()
       
-      getDistributedCacheManager().sessionCreated(session.getRealId());
-      
-      session.tellNew(ClusteredSessionNotificationCause.CREATE);
-
-      if (trace_)
-      {
-         log_.trace("Created a ClusteredSession with id: " + sessionId);
-      }
-
-      createdCounter_.incrementAndGet(); // the call to add() handles the other counters 
-      
-      // Add this session to the set of those potentially needing replication
-      SessionReplicationContext.bindSession(session, snapshotManager_);
-      
-      if (clearInvalidated != null)
-      {
-         // We no longer need to track any earlier session w/ same id 
-         // invalidated by this thread
-         SessionInvalidationTracker.clearInvalidatedSession(clearInvalidated, this);
-      }
-      
       return session;
    }
 
@@ -547,23 +643,49 @@
     */
    public Session[] findSessions()
    {
-      // Need to load all the unloaded sessions
-      if(unloadedSessions_.size() > 0)
+      Session[] sessions = null;
+      try
       {
-         // Make a thread-safe copy of the new id list to work with
-         Set<String> ids = new HashSet<String>(unloadedSessions_.keySet());
-
-         if(trace_) {
-            log_.trace("findSessions: loading sessions from distributed cache: " + ids);
+         // [JBAS-7123] Make sure we're either in the call stack where LockingValve has
+         // a lock, or that we acquire one ourselves
+         boolean inLockingValve = SessionReplicationContext.isLocallyActive();
+         if (inLockingValve || this.valveLock.tryLock(0, TimeUnit.SECONDS))
+         {
+            try
+            {
+               // Need to load all the unloaded sessions
+               if(unloadedSessions_.size() > 0)
+               {
+                  // Make a thread-safe copy of the new id list to work with
+                  Set<String> ids = new HashSet<String>(unloadedSessions_.keySet());
+  
+                  if(trace_) {
+                     log_.trace("findSessions: loading sessions from distributed cache: " + ids);
+                  }
+  
+                  for(String id :  ids) {
+                     loadSession(id);
+                  }
+               }
+  
+               // All sessions are now "local" so just return the local sessions
+               sessions = findLocalSessions();
+            }
+            finally
+            {
+               if (!inLockingValve)
+               {
+                  this.valveLock.unlock();
+               }
+            }
          }
-
-         for(String id :  ids) {
-            loadSession(id);
-         }
       }
-
-      // All sessions are now "local" so just return the local sessions
-      return findLocalSessions();
+      catch (InterruptedException e)
+      {
+         Thread.currentThread().interrupt();
+      }
+      
+      return sessions;
    }
 
    /**
@@ -697,8 +819,27 @@
          throw new IllegalStateException("Manager not started");
       }
       
+      if (stopping)
+      {
+         return;
+      }
+      
       log_.debug("Stopping");
       
+      this.stopping = true;
+      
+      // Disable background work, then block for any ongoing backgroundProcess.
+      // Do this before draining the semaphore so we know draining
+      // won't impact any on-going background processing
+      backgroundProcessAllowed.set(false);
+      synchronized (backgroundProcessAllowed)
+      {
+         if (trace_)
+         {
+            log_.trace("All background processing terminated");
+         }
+      }
+      
       // Handle re-entrance
       if (this.semaphore.tryAcquire())
       {
@@ -713,16 +854,11 @@
          {
             Thread.currentThread().interrupt();
             this.semaphore.release();
+            
             throw new LifecycleException(e);
          }
       }
       
-      // Block for any ongoing backgroundProcess, then disable
-      synchronized (backgroundProcessAllowed)
-      {
-         backgroundProcessAllowed.set(false);
-      }
-      
       // Let subclasses clean up
       stopExtensions();
       
@@ -1536,6 +1672,11 @@
          ClusteredSession<? extends OutgoingDistributableSessionData> sessions[] = findLocalSessions();
          for (int i = 0; i < sessions.length; ++i)
          {
+            if (!backgroundProcessAllowed.get())
+            {
+               return;
+            }
+            
             try
             {
                ClusteredSession<? extends OutgoingDistributableSessionData> session = sessions[i];
@@ -1587,6 +1728,11 @@
                           ex, ex);
             }
          }
+         
+         if (!backgroundProcessAllowed.get())
+         {
+            return;
+         }
 
          // Next, handle any unloaded sessions
 
@@ -1599,7 +1745,12 @@
          
          Map<String, OwnedSessionUpdate> unloaded = getUnloadedSessions();
          for (Map.Entry<String, OwnedSessionUpdate> entry : unloaded.entrySet())
-         {
+         {            
+            if (!backgroundProcessAllowed.get())
+            {
+               return;
+            }
+            
             String realId = entry.getKey();
             OwnedSessionUpdate osu = entry.getValue();
             
@@ -1726,23 +1877,46 @@
 
    private ClusteredSession<? extends OutgoingDistributableSessionData> createEmptyClusteredSession()
    {     
-
-      ClusteredSession<? extends OutgoingDistributableSessionData> session = null;
-      switch (replicationGranularity_)
+      ClusteredSession<? extends OutgoingDistributableSessionData> session = null;   
+      try
       {
-         case ATTRIBUTE:
-            ClusteredManager<OutgoingAttributeGranularitySessionData> amgr = uncheckedCastManager(this);
-            session = new AttributeBasedClusteredSession(amgr);
-            break;
-         case FIELD:
-            ClusteredManager<OutgoingDistributableSessionData> fmgr = uncheckedCastManager(this);
-            session = new FieldBasedClusteredSession(fmgr);
-            break;
-         default:
-            ClusteredManager<OutgoingSessionGranularitySessionData> smgr = uncheckedCastManager(this);
-            session = new SessionBasedClusteredSession(smgr);
-            break;
+         // [JBAS-7123] Make sure we're either in the call stack where LockingValve has
+         // a lock, or that we acquire one ourselves
+         boolean inLockingValve = SessionReplicationContext.isLocallyActive();
+         if (inLockingValve || this.valveLock.tryLock(0, TimeUnit.SECONDS))
+         {
+            try
+            {
+               switch (replicationGranularity_)
+               {
+                  case ATTRIBUTE :
+                     ClusteredManager<OutgoingAttributeGranularitySessionData> amgr = uncheckedCastManager(this);
+                     session = new AttributeBasedClusteredSession(amgr);
+                     break;
+                  case FIELD :
+                     ClusteredManager<OutgoingDistributableSessionData> fmgr = uncheckedCastManager(this);
+                     session = new FieldBasedClusteredSession(fmgr);
+                     break;
+                  default :
+                     ClusteredManager<OutgoingSessionGranularitySessionData> smgr = uncheckedCastManager(this);
+                     session = new SessionBasedClusteredSession(smgr);
+                     break;
+               }
+            }
+            finally
+            {
+               if (!inLockingValve)
+               {
+                  this.valveLock.unlock();
+               }
+            }
+         }
       }
+      catch (InterruptedException e)
+      {
+         Thread.currentThread().interrupt();
+      }
+      
       return session;
    }
 
@@ -1808,126 +1982,150 @@
       {
          return null;
       }
-
-      long begin = System.currentTimeMillis();
-      boolean mustAdd = false;
-      boolean passivated = false;
+      ClusteredSession<? extends OutgoingDistributableSessionData> session = null;
       
-      ClusteredSession<? extends OutgoingDistributableSessionData> session = sessions_.get(realId);
-      boolean initialLoad = false;
-      if (session == null)
-      {                 
-         initialLoad = true;
-         // This is either the first time we've seen this session on this
-         // server, or we previously expired it and have since gotten
-         // a replication message from another server
-         mustAdd = true;
-         session = createEmptyClusteredSession();
-         
-         OwnedSessionUpdate osu = unloadedSessions_.get(realId);
-         passivated = (osu != null && osu.isPassivated());
-      }
-
-      synchronized (session)
+      try
       {
-         ContextClassLoaderSwitcher.SwitchContext switcher = null; 
-         boolean doTx = false; 
-         try
+         // [JBAS-7123] Make sure we're either in the call stack where LockingValve has
+         // a lock, or that we acquire one ourselves
+         boolean inLockingValve = SessionReplicationContext.isLocallyActive();
+         if (inLockingValve || this.valveLock.tryLock(0, TimeUnit.SECONDS))
          {
-            // We need transaction so any data gravitation replication 
-            // is sent in batch.
-            // Don't do anything if there is already transaction context
-            // associated with this thread.
-            if (batchingManager.isBatchInProgress() == false)
-            {
-               batchingManager.startBatch();
-               doTx = true;
-            }
-            
-            // Tomcat calls Manager.findSession before setting the tccl,
-            // so we need to do it :(
-            switcher = getContextClassLoaderSwitcher().getSwitchContext();
-            switcher.setClassLoader(tcl_);
-                        
-            IncomingDistributableSessionData data = proxy_.getSessionData(realId, initialLoad);
-            if (data != null)
-            {
-               session.update(data);
-            }
-            else
-            {
-               // Clunky; we set the session variable to null to indicate
-               // no data so move on
-               session = null;
-            }
-            
-            if (session != null)
-            {
-               ClusteredSessionNotificationCause cause = passivated ? ClusteredSessionNotificationCause.ACTIVATION 
-                                                                    : ClusteredSessionNotificationCause.FAILOVER;
-               session.notifyDidActivate(cause);
-            }
-         }
-         catch (Exception ex)
-         {
             try
             {
-//                  if(doTx)
-               // Let's set it no matter what.
-               batchingManager.setBatchRollbackOnly();
-            }
-            catch (Exception exn)
-            {
-               log_.error("Caught exception rolling back transaction", exn);
-            }
-            // We will need to alert Tomcat of this exception.
-            if (ex instanceof RuntimeException)
-               throw (RuntimeException) ex;
-            
-            throw new RuntimeException("loadSession(): failed to load session " +
-                                       realId, ex);
-         }
-         finally
-         {
-            try {
-               if(doTx)
-               {
-                  batchingManager.endBatch();
+               long begin = System.currentTimeMillis();
+               boolean mustAdd = false;
+               boolean passivated = false;
+               
+               session = sessions_.get(realId);
+               boolean initialLoad = false;
+               if (session == null)
+               {                 
+                  initialLoad = true;
+                  // This is either the first time we've seen this session on this
+                  // server, or we previously expired it and have since gotten
+                  // a replication message from another server
+                  mustAdd = true;
+                  session = createEmptyClusteredSession();
+                  
+                  OwnedSessionUpdate osu = unloadedSessions_.get(realId);
+                  passivated = (osu != null && osu.isPassivated());
                }
-            }
-            finally {
-               if (switcher != null)
+  
+               synchronized (session)
                {
-                  switcher.reset();
+                  ContextClassLoaderSwitcher.SwitchContext switcher = null; 
+                  boolean doTx = false; 
+                  try
+                  {
+                     // We need transaction so any data gravitation replication 
+                     // is sent in batch.
+                     // Don't do anything if there is already transaction context
+                     // associated with this thread.
+                     if (batchingManager.isBatchInProgress() == false)
+                     {
+                        batchingManager.startBatch();
+                        doTx = true;
+                     }
+                     
+                     // Tomcat calls Manager.findSession before setting the tccl,
+                     // so we need to do it :(
+                     switcher = getContextClassLoaderSwitcher().getSwitchContext();
+                     switcher.setClassLoader(tcl_);
+                                 
+                     IncomingDistributableSessionData data = proxy_.getSessionData(realId, initialLoad);
+                     if (data != null)
+                     {
+                        session.update(data);
+                     }
+                     else
+                     {
+                        // Clunky; we set the session variable to null to indicate
+                        // no data so move on
+                        session = null;
+                     }
+                     
+                     if (session != null)
+                     {
+                        ClusteredSessionNotificationCause cause = passivated ? ClusteredSessionNotificationCause.ACTIVATION 
+                                                                             : ClusteredSessionNotificationCause.FAILOVER;
+                        session.notifyDidActivate(cause);
+                     }
+                  }
+                  catch (Exception ex)
+                  {
+                     try
+                     {
+  //                  if(doTx)
+                        // Let's set it no matter what.
+                        batchingManager.setBatchRollbackOnly();
+                     }
+                     catch (Exception exn)
+                     {
+                        log_.error("Caught exception rolling back transaction", exn);
+                     }
+                     // We will need to alert Tomcat of this exception.
+                     if (ex instanceof RuntimeException)
+                        throw (RuntimeException) ex;
+                     
+                     throw new RuntimeException("loadSession(): failed to load session " +
+                                                realId, ex);
+                  }
+                  finally
+                  {
+                     try {
+                        if(doTx)
+                        {
+                           batchingManager.endBatch();
+                        }
+                     }
+                     finally {
+                        if (switcher != null)
+                        {
+                           switcher.reset();
+                        }
+                     }
+                  }
+  
+                  if (session != null)
+                  {            
+                     if (mustAdd)
+                     {
+                        add(session, false); // don't replicate
+                        if (!passivated)
+                        {
+                           session.tellNew(ClusteredSessionNotificationCause.FAILOVER);
+                        }
+                     }
+                     long elapsed = System.currentTimeMillis() - begin;
+                     stats_.updateLoadStats(realId, elapsed);
+  
+                     if (trace_)
+                     {
+                        log_.trace("loadSession(): id= " + realId + ", session=" + session);
+                     }
+                  }
+                  else if (trace_)
+                  {
+                     log_.trace("loadSession(): session " + realId +
+                                " not found in distributed cache");
+                  }
                }
             }
-         }
-
-         if (session != null)
-         {            
-            if (mustAdd)
+            finally
             {
-               add(session, false); // don't replicate
-               if (!passivated)
+               if (!inLockingValve)
                {
-                  session.tellNew(ClusteredSessionNotificationCause.FAILOVER);
+                  this.valveLock.unlock();
                }
             }
-            long elapsed = System.currentTimeMillis() - begin;
-            stats_.updateLoadStats(realId, elapsed);
-
-            if (trace_)
-            {
-               log_.trace("loadSession(): id= " + realId + ", session=" + session);
-            }
          }
-         else if (trace_)
-         {
-            log_.trace("loadSession(): session " + realId +
-                       " not found in distributed cache");
-         }
       }
-
+      catch (InterruptedException e)
+      {
+         Thread.currentThread().interrupt();
+      }
+      
       return session;
    }
 

Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/SessionReplicationContext.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/SessionReplicationContext.java	2009-08-07 22:18:33 UTC (rev 92156)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/SessionReplicationContext.java	2009-08-07 22:25:26 UTC (rev 92157)
@@ -162,10 +162,7 @@
     * the current thread.
     * 
     * @return <code>true</code> if there is a context associated with the thread
-    * 
-    * @deprecated Will be removed in AS 6
     */
-   @Deprecated
    public static boolean isLocallyActive()
    {
       return getCurrentContext() != null;




More information about the jboss-cvs-commits mailing list