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

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Apr 10 19:40:16 EDT 2008


Author: bstansberry at jboss.com
Date: 2008-04-10 19:40:15 -0400 (Thu, 10 Apr 2008)
New Revision: 71986

Added:
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/JBossWebManagedLRUAlgorithm.java
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/JBossWebManagedLRUConfiguration.java
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/JBossWebManagedLRUPolicy.java
Modified:
   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:
Prevent conflicts between manager stop and background processing work

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-04-10 23:39:34 UTC (rev 71985)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/JBossCacheManager.java	2008-04-10 23:40:15 UTC (rev 71986)
@@ -45,11 +45,7 @@
 import org.apache.catalina.Valve;
 import org.apache.catalina.core.ContainerBase;
 import org.jboss.cache.CacheException;
-import org.jboss.cache.config.EvictionPolicyConfig;
-import org.jboss.cache.eviction.LRUConfiguration;
-import org.jboss.cache.eviction.LRUPolicy;
 import org.jboss.cache.pojo.PojoCache;
-import org.jboss.ejb3.cache.tree.AbortableLRUPolicy;
 import org.jboss.metadata.web.jboss.JBossWebMetaData;
 import org.jboss.metadata.web.jboss.PassivationConfig;
 import org.jboss.metadata.web.jboss.ReplicationConfig;
@@ -1354,12 +1350,15 @@
     * Goes through all sessions and look if they have expired.
     * Note this overrides the method in JBossManager.
     */
+   @Override
    protected void processExpires()
    {
       boolean expire = maxInactiveInterval_ >= 0;
       boolean passivate = isPassivationEnabled();
       if (!expire && !passivate)
       {
+         // Let the proxy clean up any pojos
+         proxy_.processEviction();
          return;
       }
       
@@ -1509,6 +1508,9 @@
          log_.error("processExpires: failed with exception: " + ex, ex);
       }
       
+      // Finally, clean up the pojo region
+      proxy_.processEviction();
+      
       if (trace)
       { 
          log_.trace("processExpires(): Completed ...");

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-04-10 23:39:34 UTC (rev 71985)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/JBossCacheService.java	2008-04-10 23:40:15 UTC (rev 71986)
@@ -56,8 +56,8 @@
 import org.jboss.cache.buddyreplication.BuddyManager;
 import org.jboss.cache.config.CacheLoaderConfig;
 import org.jboss.cache.config.EvictionPolicyConfig;
-import org.jboss.cache.eviction.LRUConfiguration;
-import org.jboss.cache.eviction.LRUPolicy;
+import org.jboss.cache.eviction.EvictionException;
+import org.jboss.cache.eviction.EvictionPolicy;
 import org.jboss.cache.transaction.BatchModeTransactionManager;
 import org.jboss.invocation.MarshalledValue;
 import org.jboss.logging.Logger;
@@ -108,6 +108,9 @@
    
    // Are we configured for passivation?
    private boolean usePassivation_ = false;
+   private PassivationListener passivationListener_;
+   private Region evictionRegion_;
+   private JBossWebManagedLRUAlgorithm evictionAlgorithm_;
    private WeakHashMap typeMap = new WeakHashMap();
    
    public JBossCacheService(PojoCache cache)
@@ -235,10 +238,10 @@
       if(manager_.isPassivationEnabled())
       {
          log_.debug("Passivation is enabled");
-         PassivationListener pl = new PassivationListener(manager_, hostName_, webAppPath_);
-         plainCache_.addCacheListener(pl);
+         passivationListener_ = new PassivationListener(manager_, hostName_, webAppPath_);
+         plainCache_.addCacheListener(passivationListener_);
          
-         initializeFieldGranularityEviction();
+         initializeFieldGranularityEviction(tcl);
       }
       else
       {
@@ -248,8 +251,10 @@
 
    public void stop()
    {
-      plainCache_.removeCacheListener(cacheListener_);
-
+      plainCache_.removeCacheListener(cacheListener_);      
+      if (passivationListener_ != null)
+         plainCache_.removeCacheListener(passivationListener_);
+      
       // Construct the fqn
       Object[] objs = new Object[]{SESSION, hostName_, webAppPath_};
       Fqn pathFqn = new Fqn( objs );
@@ -272,10 +277,16 @@
             log_.error("Exception during inactivation of webapp region " + pathFqn + 
                        " or un-registration of its class loader", e);
          }
+      }       
+      
+      if (evictionRegion_ != null)            
+      {
+         plainCache_.removeRegion(evictionRegion_.getFqn());
+         evictionRegion_ = null;
       }
 
       // remove session data
-      // BES 2207/08/18 Can't do this as it will 
+      // BES 2007/08/18 Can't do this as it will 
       // 1) blow away passivated sessions
       // 2) leave the cache in an inconsistent state if the war
       //    is restarted
@@ -1043,6 +1054,21 @@
       return usePassivation_;      
    }
    
+   public void processEviction()
+   {
+      if (evictionAlgorithm_ != null)
+      {
+         try
+         {
+            evictionAlgorithm_.backgroundProcess(evictionRegion_);
+         }
+         catch (EvictionException e)
+         {
+            log_.error("Problem handling eviction for region " + evictionRegion_, e);
+         }
+      }
+   }
+   
    private Fqn getFieldFqn(String id, String key)
    {
       return getFieldFqn(hostName_, webAppPath_, id, key);
@@ -1244,7 +1270,7 @@
       
    }
    
-   private void initializeFieldGranularityEviction()
+   private void initializeFieldGranularityEviction(ClassLoader regionCL)
    {
       if (manager_.getReplicationGranularity() == ReplicationGranularity.FIELD)            
       {
@@ -1253,16 +1279,21 @@
          if (maxNodes > 0 || maxIdle > 0)
          {
             EvictionPolicyConfig epc = getEvictionPolicyConfig(maxIdle, maxNodes);         
-            Region region = plainCache_.getRegion(getWebappFqn(), true);
-            region.setEvictionPolicy(epc);
+            evictionRegion_ = plainCache_.getRegion(getWebappFqn(), true);            
+            evictionRegion_.setEvictionPolicy(epc);
+            EvictionPolicy policy = evictionRegion_.getEvictionPolicy();
+            evictionAlgorithm_ = (JBossWebManagedLRUAlgorithm) policy.getEvictionAlgorithm();
+            
+            // Assign the classloader to this region as well
+            evictionRegion_.registerContextClassLoader(regionCL);
          }
       }
    }
    
    private EvictionPolicyConfig getEvictionPolicyConfig(int timeToLiveSeconds, int maxNodes)
    {
-      LRUConfiguration epc = new LRUConfiguration();
-      epc.setEvictionPolicyClass(LRUPolicy.class.getName());
+      JBossWebManagedLRUConfiguration epc = new JBossWebManagedLRUConfiguration();
+      epc.setEvictionPolicyClass(JBossWebManagedLRUPolicy.class.getName());
       epc.setTimeToLiveSeconds(timeToLiveSeconds);
       epc.setMaxNodes(maxNodes);
       return epc;

Added: trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/JBossWebManagedLRUAlgorithm.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/JBossWebManagedLRUAlgorithm.java	                        (rev 0)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/JBossWebManagedLRUAlgorithm.java	2008-04-10 23:40:15 UTC (rev 71986)
@@ -0,0 +1,54 @@
+/*
+ * 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 org.jboss.cache.Region;
+import org.jboss.cache.eviction.EvictionException;
+import org.jboss.cache.eviction.LRUAlgorithm;
+
+/**
+ * Disables eviction management by the JBoss Cache eviction thread while
+ * exposing a method to allow the JBoss Web background thread to 
+ * process the evictions.
+ * 
+ * @author Brian Stansberry
+ *
+ */
+public class JBossWebManagedLRUAlgorithm extends LRUAlgorithm
+{
+   /**
+    * Turns this method into a no-op, thus disabling eviction
+    * management by the JBC eviction thread.
+    */
+   @Override
+   public void process(Region region) throws EvictionException
+   {
+      // no-op
+   }
+   
+   public void backgroundProcess(Region region) throws EvictionException
+   {
+      super.process(region);
+   }
+
+}

Added: trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/JBossWebManagedLRUConfiguration.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/JBossWebManagedLRUConfiguration.java	                        (rev 0)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/JBossWebManagedLRUConfiguration.java	2008-04-10 23:40:15 UTC (rev 71986)
@@ -0,0 +1,42 @@
+/*
+ * 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 org.jboss.cache.eviction.LRUConfiguration;
+
+/**
+ * @author Brian Stansberry
+ *
+ */
+public class JBossWebManagedLRUConfiguration extends LRUConfiguration
+{
+   /** The serialVersionUID */
+   private static final long serialVersionUID = 3373548962390320982L;
+
+   @Override
+   protected void setEvictionPolicyClassName()
+   {
+      setEvictionPolicyClass(JBossWebManagedLRUPolicy.class.getName());
+   }
+
+}

Added: trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/JBossWebManagedLRUPolicy.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/JBossWebManagedLRUPolicy.java	                        (rev 0)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/JBossWebManagedLRUPolicy.java	2008-04-10 23:40:15 UTC (rev 71986)
@@ -0,0 +1,43 @@
+/*
+ * 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 org.jboss.cache.eviction.LRUPolicy;
+
+/**
+ * Disables eviction management by the JBoss Cache eviction thread while
+ * exposing a method to allow the JBoss Web background thread to 
+ * process the evictions.
+ * 
+ * @author Brian Stansberry
+ */
+public class JBossWebManagedLRUPolicy extends LRUPolicy
+{
+
+   public JBossWebManagedLRUPolicy()
+   {
+      super();
+      this.algorithm = new JBossWebManagedLRUAlgorithm();
+   }   
+
+}




More information about the jboss-cvs-commits mailing list