[jboss-cvs] JBossAS SVN: r74413 - 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 Jun 11 15:54:55 EDT 2008


Author: bstansberry at jboss.com
Date: 2008-06-11 15:54:55 -0400 (Wed, 11 Jun 2008)
New Revision: 74413

Modified:
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/AttributeBasedClusteredSession.java
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/ClusteredSession.java
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/FieldBasedClusteredSession.java
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/FieldBasedJBossCacheService.java
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/JBossCacheClusteredSession.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
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/SessionBasedClusteredSession.java
Log:
[JBAS-5618] Scope FIELD granularity web session pojos to the session

Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/AttributeBasedClusteredSession.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/AttributeBasedClusteredSession.java	2008-06-11 19:53:07 UTC (rev 74412)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/AttributeBasedClusteredSession.java	2008-06-11 19:54:55 UTC (rev 74413)
@@ -164,7 +164,7 @@
    public void removeMyself()
    {
       // This is a shortcut to remove session and it's child attributes.
-      proxy_.removeSession(realId);
+      proxy_.removeSession(realId, false);
    }
 
    public void removeMyselfLocal()
@@ -175,7 +175,7 @@
       // Otherwise empty nodes for the session root and child ATTRIBUTE will 
       // remain in the tree and screw up our list of session names.
       proxy_.removeAttributesLocal(realId);
-      proxy_.removeSessionLocal(realId);
+      proxy_.removeSessionLocal(realId, false);
    }
 
    // ------------------------------------------------ JBoss internal abstract method

Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/ClusteredSession.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/ClusteredSession.java	2008-06-11 19:53:07 UTC (rev 74412)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/ClusteredSession.java	2008-06-11 19:54:55 UTC (rev 74413)
@@ -1504,6 +1504,11 @@
    {
       return sessionAttributesDirty;
    }
+   
+   public boolean getCreateRegionForSession()
+   {
+      return false;
+   }
 
    protected boolean isGetDirty(Object attribute)
    {

Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/FieldBasedClusteredSession.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/FieldBasedClusteredSession.java	2008-06-11 19:53:07 UTC (rev 74412)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/FieldBasedClusteredSession.java	2008-06-11 19:54:55 UTC (rev 74413)
@@ -81,6 +81,7 @@
    
    protected transient Map attributes_ = Collections.synchronizedMap(new HashMap());
    protected transient FieldBasedJBossCacheService fieldProxy_;
+   protected transient boolean needRegion_ = true;
    
    public FieldBasedClusteredSession(JBossCacheManager manager)
    {
@@ -103,8 +104,27 @@
       super.recycle();
 
       attributes_.clear();
+      needRegion_ = true;
    }
 
+   @Override
+   public boolean needRegionForSession()
+   {
+      return needRegion_;
+   }
+   
+   @Override
+   public boolean hasRegionForSession()
+   {
+      return !needRegion_;
+   }
+
+   @Override
+   public void createdRegionForSession()
+   {
+      needRegion_ = false;
+   }
+
    /**
     * Return a string representation of this object.
     */
@@ -132,7 +152,7 @@
       // This is a shortcut to remove session and it's child attributes.
       // Note that there is no need to remove attribute first since caller 
       // will do that already.
-      proxy_.removeSession(realId);
+      proxy_.removeSession(realId, true);
    }
 
    public void removeMyselfLocal()
@@ -145,7 +165,7 @@
       // Otherwise empty nodes for the session root and child ATTRIBUTE will 
       // remain in the tree and screw up our list of session names.
       fieldProxy_.removePojosLocal(realId);
-      fieldProxy_.removeSessionLocal(realId);
+      fieldProxy_.removeSessionLocal(realId, true);
    }
 
    // ------------------------------------------------ JBoss internal abstract method
@@ -337,7 +357,7 @@
       Object oldVal = null;
       if (!replicationExcludes.contains(key))
       {   
-         oldVal = fieldProxy_.setPojo(realId, key, value);
+         oldVal = fieldProxy_.setPojo(realId, key, value, this);
          if(oldVal != null)
          {  // We are done with the old one.
             fieldProxy_.removeObserver(this, oldVal);

Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/FieldBasedJBossCacheService.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/FieldBasedJBossCacheService.java	2008-06-11 19:53:07 UTC (rev 74412)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/FieldBasedJBossCacheService.java	2008-06-11 19:54:55 UTC (rev 74413)
@@ -70,12 +70,6 @@
       setCache(pojoCache_.getCache());
    }
    
-   private Fqn getJBossInternalFqn()
-   {
-      Object[] objs = new Object[]{SESSION, hostName_, webAppPath_, InternalConstant.JBOSS_INTERNAL_STRING };
-      return new Fqn(objs);
-   }
-   
    private Fqn getFieldFqn(String id, String key)
    {
       return getFieldFqn(hostName_, webAppPath_, id, key);
@@ -155,19 +149,32 @@
     * @param realId the session id with any jvmRoute removed
     * @param key    the attribute key
     * @param pojo
+    * @param createRegion TODO
     */
-   public Object setPojo(String realId, String key, Object pojo)
+   public Object setPojo(String realId, String key, Object pojo, JBossCacheClusteredSession session)
    {
       if(log_.isTraceEnabled())
       {
          log_.trace("setPojo(): session id: " + realId + " key: " + key + 
                     " object: " + pojo.toString());
+      }      
+      
+      if (session.needRegionForSession())
+      {
+         Fqn sessionRegion = getSessionFqn(realId);
+         getCache().getRegion(sessionRegion, true);
+         session.createdRegionForSession();
+         if (log_.isTraceEnabled())
+         {
+            log_.trace("Created region for session at " + sessionRegion);
+         }         
       }
+      
       // Construct the fqn.
       Fqn fqn = getFieldFqn(realId, key);
       try {
          // Ignore any cache notifications that our own work generates 
-         SessionReplicationContext.startCacheActivity();
+         SessionReplicationContext.startCacheActivity();            
          return pojoCache_.attach(fqn.toString(), pojo);
       } catch (CacheException e) {
          throw new RuntimeException("JBossCacheService: exception occurred in cache setPojo ... ", e);

Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/JBossCacheClusteredSession.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/JBossCacheClusteredSession.java	2008-06-11 19:53:07 UTC (rev 74412)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/JBossCacheClusteredSession.java	2008-06-11 19:54:55 UTC (rev 74413)
@@ -73,6 +73,21 @@
       clearOutdated();
    }
    
+   public boolean needRegionForSession()
+   {
+      return false;
+   }
+   
+   public boolean hasRegionForSession()
+   {
+      return false;
+   }
+   
+   public void createdRegionForSession()
+   {
+      // ignored
+   }
+   
    /**
     * Gets a reference to the JBossCacheService.
     */

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-06-11 19:53:07 UTC (rev 74412)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/JBossCacheManager.java	2008-06-11 19:54:55 UTC (rev 74413)
@@ -753,7 +753,7 @@
             }
             else
             {
-               proxy_.removeSessionLocal(realId);           
+               proxy_.removeSessionLocal(realId, false);           
             }
          }
          catch (Exception e)
@@ -965,10 +965,10 @@
       return createEmptyClusteredSession();
    }
 
-   private ClusteredSession createEmptyClusteredSession()
+   private JBossCacheClusteredSession createEmptyClusteredSession()
    {     
 
-      ClusteredSession session = null;
+      JBossCacheClusteredSession session = null;
       switch (replicationGranularity_)
       {
          case ATTRIBUTE:
@@ -1215,7 +1215,7 @@
 
       long begin = System.currentTimeMillis();
       boolean mustAdd = false;
-      ClusteredSession session = (ClusteredSession) sessions_.get(realId);
+      JBossCacheClusteredSession session = (JBossCacheClusteredSession) sessions_.get(realId);
       
       if (session == null)
       {

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-06-11 19:53:07 UTC (rev 74412)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/JBossCacheService.java	2008-06-11 19:54:55 UTC (rev 74413)
@@ -266,7 +266,7 @@
     *         <code>null</code> if the cache had no data stored
     *         under the given session id.
     */
-   public ClusteredSession loadSession(String realId, ClusteredSession toLoad)
+   public JBossCacheClusteredSession loadSession(String realId, JBossCacheClusteredSession toLoad)
    {
       Fqn fqn = getSessionFqn(realId);
       Map sessionData =  cacheWrapper_.getData(fqn, true);
@@ -276,6 +276,8 @@
          return null;
       }
       
+      setupSessionRegion(toLoad, fqn);
+      
       Integer version = (Integer) sessionData.get(VERSION_KEY);
       SessionTimestamp timestamp = (SessionTimestamp) sessionData.get(TIMESTAMP_KEY);
       SessionMetadata metadata = (SessionMetadata) sessionData.get(METADATA_KEY);
@@ -285,13 +287,17 @@
       return toLoad;
    }
 
-   public void putSession(String realId, ClusteredSession session)
+   public void putSession(String realId, JBossCacheClusteredSession session)
    { 
       if (log_.isTraceEnabled())
       {
          log_.trace("putSession(): putting session " + session.getIdInternal());
       }     
       
+      Fqn fqn = getSessionFqn(realId);
+      
+      setupSessionRegion(session, fqn);
+      
       Map map = new HashMap();
       map.put(VERSION_KEY, new Integer(session.getVersion()));
       map.put(TIMESTAMP_KEY, session.getSessionTimestamp());
@@ -315,27 +321,57 @@
          }
       }
       
-      cacheWrapper_.put(getSessionFqn(realId), map);
+      cacheWrapper_.put(fqn, map);
    }
 
-   public void removeSession(String realId)
+   /**
+    * If the session requires a region in the cache, establishes one.
+    * 
+    * @param session the session
+    * @param fqn the fqn for the session
+    */
+   private void setupSessionRegion(JBossCacheClusteredSession session, Fqn fqn)
    {
+      if (session.needRegionForSession())
+      {
+         plainCache_.getRegion(fqn, true);
+         session.createdRegionForSession();
+         if (log_.isTraceEnabled())
+         {
+            log_.trace("Created region for session at " + fqn);
+         }
+      }
+   }
+
+   public void removeSession(String realId, boolean removeRegion)
+   {
       Fqn fqn = getSessionFqn(realId);
       if (log_.isTraceEnabled())
       {
          log_.trace("Remove session from distributed store. Fqn: " + fqn);
       }
+      
+      if (removeRegion)
+      {
+         plainCache_.removeRegion(fqn);
+      }
 
       cacheWrapper_.remove(fqn);
    }
 
-   public void removeSessionLocal(String realId)
+   public void removeSessionLocal(String realId, boolean removeRegion)
    {
       Fqn fqn = getSessionFqn(realId);
       if (log_.isTraceEnabled())
       {
          log_.trace("Remove session from my own distributed store only. Fqn: " + fqn);
       }
+      
+      if (removeRegion)
+      {
+         plainCache_.removeRegion(fqn);
+      }
+      
       cacheWrapper_.removeLocalSubtree(fqn);
    }
 
@@ -343,7 +379,7 @@
    {
       if (dataOwner == null)
       {
-         removeSessionLocal(realId);
+         removeSessionLocal(realId, false);
       }
       else
       {         
@@ -563,7 +599,7 @@
       return new Fqn(objs);
    }
    
-   private Fqn getSessionFqn(String id)
+   protected Fqn getSessionFqn(String id)
    {
       return getSessionFqn(hostName_, webAppPath_, id);
    }

Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/SessionBasedClusteredSession.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/SessionBasedClusteredSession.java	2008-06-11 19:53:07 UTC (rev 74412)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/SessionBasedClusteredSession.java	2008-06-11 19:54:55 UTC (rev 74413)
@@ -81,12 +81,12 @@
 
    public void removeMyself()
    {
-      proxy_.removeSession(realId);
+      proxy_.removeSession(realId, false);
    }
 
    public void removeMyselfLocal()
    {
-      proxy_.removeSessionLocal(realId);
+      proxy_.removeSessionLocal(realId, false);
    }
 
    // ----------------------------------------------HttpSession Public Methods




More information about the jboss-cvs-commits mailing list