[jboss-cvs] JBossAS SVN: r75716 - trunk/tomcat/src/main/org/jboss/web/tomcat/service/session.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Jul 11 14:57:58 EDT 2008


Author: bstansberry at jboss.com
Date: 2008-07-11 14:57:58 -0400 (Fri, 11 Jul 2008)
New Revision: 75716

Removed:
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/BatchReplicationClusteredSessionValve.java
Modified:
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/ClusteredSessionValve.java
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/JBossCacheManager.java
Log:
[JBAS-5735] Intermediate fix

Deleted: trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/BatchReplicationClusteredSessionValve.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/BatchReplicationClusteredSessionValve.java	2008-07-11 18:51:29 UTC (rev 75715)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/BatchReplicationClusteredSessionValve.java	2008-07-11 18:57:58 UTC (rev 75716)
@@ -1,156 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt 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.web.tomcat.service.session;
-
-import java.io.IOException;
-import javax.servlet.ServletException;
-import javax.transaction.TransactionManager;
-
-import org.apache.catalina.Lifecycle;
-import org.apache.catalina.LifecycleException;
-import org.apache.catalina.LifecycleListener;
-import org.apache.catalina.connector.Request;
-import org.apache.catalina.connector.Response;
-import org.apache.catalina.util.LifecycleSupport;
-import org.apache.catalina.valves.ValveBase;
-import org.jboss.logging.Logger;
-
-/**
- * This Valve handles batch replication mode. It uses the cache tm to performa batch replication.
- *
- * @author Ben Wang
- * @version $Revision: 60079 $
- */
-public class BatchReplicationClusteredSessionValve extends ValveBase implements Lifecycle
-{
-   private static Logger log_ = Logger.getLogger(BatchReplicationClusteredSessionValve.class);
-
-   // The info string for this Valve
-   private static final String info = "BatchReplicationClusteredSessionValve/1.0";
-
-   // Valve-lifecycle_ helper object
-   protected LifecycleSupport support = new LifecycleSupport(this);
-
-   protected JBossCacheManager manager_;
-
-   /**
-    * Create a new Valve.
-    *
-    */
-   public BatchReplicationClusteredSessionValve(AbstractJBossManager manager)
-   {
-      super();
-      manager_ = (JBossCacheManager)manager;
-   }
-
-   /**
-    * Get information about this Valve.
-    */
-   public String getInfo()
-   {
-      return info;
-   }
-
-   /**
-    * Valve-chain handler method.
-    * This method gets called when the request goes through the Valve-chain. Our session replication mechanism replicates the
-    * session after request got through the servlet code.
-    *
-    * @param request  The request object associated with this request.
-    * @param response The response object associated with this request.
-    */
-   public void invoke(Request request, Response response) throws IOException, ServletException
-   {
-      // Note: we use specfically the tm in cache.
-      TransactionManager tm = manager_.getCacheService().getTransactionManager();
-      if(tm == null)
-      {
-         throw new RuntimeException("BatchReplicationClusteredSessionValve.invoke(): Obtain null tm");
-      }
-
-      // Before we start a tx, get the session.  If this is a failover
-      // situation, this will cause data gravitation, which will occur 
-      // thus outside of the scope of the tx we are about to start.  
-      // JBossCacheManager will ensure the gravitation is in its own tx
-      request.getSession(false);
-      
-      // Start a new transaction, we need transaction so all the replication are sent in batch.
-      try
-      {
-         tm.begin();
-         
-         // let the servlet invocation go through
-         getNext().invoke(request, response);
-         
-         log_.trace("Ready to commit batch replication for field level granularity");
-         
-         tm.commit();
-      }
-      catch (Exception e)
-      {
-         try
-         {
-            tm.rollback();
-         }
-         catch (Exception exn)
-         {
-            log_.error("Caught exception rolling back transaction", exn);
-         }
-         
-         // We will need to alert Tomcat of this exception.
-         if (e instanceof IOException)
-            throw (IOException) e;
-         if (e instanceof ServletException)
-            throw (ServletException) e;
-         if (e instanceof RuntimeException)
-            throw (RuntimeException) e;
-         throw new RuntimeException(e);
-      }
-   }
-
-   // Lifecylce-interface
-   public void addLifecycleListener(LifecycleListener listener)
-   {
-      support.addLifecycleListener(listener);
-   }
-
-   public void removeLifecycleListener(LifecycleListener listener)
-   {
-      support.removeLifecycleListener(listener);
-   }
-
-   public LifecycleListener[] findLifecycleListeners()
-   {
-      return support.findLifecycleListeners();
-   }
-
-   public void start() throws LifecycleException
-   {
-      support.fireLifecycleEvent(START_EVENT, this);
-   }
-
-   public void stop() throws LifecycleException
-   {
-      support.fireLifecycleEvent(STOP_EVENT, this);
-   }
-
-}

Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/ClusteredSessionValve.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/ClusteredSessionValve.java	2008-07-11 18:51:29 UTC (rev 75715)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/ClusteredSessionValve.java	2008-07-11 18:57:58 UTC (rev 75716)
@@ -1,24 +1,24 @@
 /*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt 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.
-*/
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.web.tomcat.service.session;
 
 import java.io.IOException;
@@ -26,8 +26,13 @@
 import java.util.Map;
 
 import javax.servlet.ServletException;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
 
-import org.apache.catalina.*;
+import org.apache.catalina.Lifecycle;
+import org.apache.catalina.LifecycleException;
+import org.apache.catalina.LifecycleListener;
+import org.apache.catalina.Manager;
 import org.apache.catalina.connector.Request;
 import org.apache.catalina.connector.Response;
 import org.apache.catalina.util.LifecycleSupport;
@@ -50,14 +55,21 @@
    private static final String info = "ClusteredSessionValve/1.0";
 
    // Valve-lifecycle_ helper object
-   private LifecycleSupport support = new LifecycleSupport(this);
+   private final LifecycleSupport support = new LifecycleSupport(this);
 
+   private final Manager manager;
+   
+   private final TransactionManager tm;
+   
    /**
     * Create a new Valve.
     */
-   public ClusteredSessionValve()
+   public ClusteredSessionValve(Manager manager, TransactionManager tm)
    {
-      super();
+      assert manager != null : "manager is null";
+      
+      this.manager = manager;
+      this.tm = tm;
    }
 
    /**
@@ -81,8 +93,17 @@
       // Initialize the context and store the request and response objects 
       // for any clustering code that has no direct access to these objects
       SessionReplicationContext.enterWebapp(request, response, true);
+      
+      Transaction tx = startBatchTransaction();
       try
       {  
+         // Workaround to JBAS-5735. Ensure we get the session from the manager
+         // rather than a cached ref from the Request.
+         String requestedId = request.getRequestedSessionId();
+         if (requestedId != null)
+         {
+            manager.findSession(requestedId);
+         }
          
          
          // let the servlet invocation go through
@@ -117,6 +138,7 @@
          finally
          {
             SessionReplicationContext.finishCacheActivity();
+            commitBatchTransaction(tx);
          }
          
       }
@@ -148,4 +170,46 @@
       support.fireLifecycleEvent(STOP_EVENT, this);
    }
 
+   private Transaction startBatchTransaction() throws ServletException
+   {
+      Transaction result = null;
+      try
+      {
+         if (this.tm != null && this.tm.getTransaction() == null)
+         {
+            this.tm.begin();
+            result = this.tm.getTransaction();
+         }
+      }
+      catch (RuntimeException re)
+      {
+         throw re;
+      }
+      catch (Exception e)
+      {
+         throw new ServletException("Failed to initiate batch replication transaction", e);
+      }
+      
+      return result;
+   }
+
+   private void commitBatchTransaction(Transaction tx) throws ServletException
+   {
+      if (tx != null)
+      {
+         try
+         {
+            tx.commit();
+         }
+         catch (RuntimeException re)
+         {
+            throw re;
+         }
+         catch (Exception e)
+         {
+            throw new ServletException("Failed to commit batch replication transaction", e);
+         }
+      }      
+   }
+
 }

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-07-11 18:51:29 UTC (rev 75715)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/JBossCacheManager.java	2008-07-11 18:57:58 UTC (rev 75716)
@@ -2099,19 +2099,19 @@
          installContextValve(new JvmRouteValve(this));         
       }   
       
-      // Add batch replication valve if needed.
+      // Handle batch replication if needed.
       // TODO -- should we add this even if not FIELD in case a cross-context
-      // call traverses a field-based webapp?     
+      // call traverses a field-based webapp?   
+      TransactionManager valveTM = null;
       if (replicationGranularity_ == ReplicationGranularity.FIELD
             && Boolean.TRUE.equals(replicationFieldBatchMode_))
       {
-         Valve batchValve = new BatchReplicationClusteredSessionValve(this);
-         log_.debug("Adding BatchReplicationClusteredSessionValve for batch replication.");
-         installContextValve(batchValve);
+         valveTM = this.tm;
+         log_.debug("Including transaction manager in ClusteredSessionValve to support batch replication.");
       }
 
       // Add clustered session valve
-      ClusteredSessionValve valve = new ClusteredSessionValve();
+      ClusteredSessionValve valve = new ClusteredSessionValve(this, valveTM);
       log_.debug("Adding ClusteredSessionValve");
       installContextValve(valve);
    }




More information about the jboss-cvs-commits mailing list