[jboss-cvs] JBossAS SVN: r80713 - in projects/cluster: ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sat Nov 8 22:13:42 EST 2008


Author: bstansberry at jboss.com
Date: 2008-11-08 22:13:42 -0500 (Sat, 08 Nov 2008)
New Revision: 80713

Added:
   projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/DistributableSessionDataImpl.java
   projects/cluster/ha-server-cache-spi/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/spi/DistributableSessionData.java
Removed:
   projects/cluster/ha-server-cache-spi/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/spi/DistributableSessionTimestamp.java
Modified:
   projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/ha/cachemanager/CacheManagerManagedCache.java
   projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/ha/cachemanager/PojoCacheManagerManagedPojoCache.java
   projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/CacheListener.java
   projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/FieldBasedJBossCacheService.java
   projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/JBossCacheService.java
   projects/cluster/ha-server-cache-spi/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/spi/DistributableSession.java
   projects/cluster/ha-server-cache-spi/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/spi/DistributableSessionMetadata.java
   projects/cluster/ha-server-cache-spi/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/spi/DistributedCacheManager.java
   projects/cluster/ha-server-cache-spi/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/spi/LocalDistributableSessionManager.java
Log:
[JBAS-6183] ATTRIBUTE granularity clustered session should store attribute in same JBC node as metadata
General tidy-up of SPI

Modified: projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/ha/cachemanager/CacheManagerManagedCache.java
===================================================================
--- projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/ha/cachemanager/CacheManagerManagedCache.java	2008-11-09 03:12:34 UTC (rev 80712)
+++ projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/ha/cachemanager/CacheManagerManagedCache.java	2008-11-09 03:13:42 UTC (rev 80713)
@@ -36,6 +36,7 @@
 import org.jboss.cache.NodeNotExistsException;
 import org.jboss.cache.Region;
 import org.jboss.cache.config.Configuration;
+import org.jboss.cache.interceptors.base.CommandInterceptor;
 import org.jboss.logging.Logger;
 import org.jboss.util.loading.ContextClassLoaderSwitcher;
 import org.jgroups.Address;
@@ -129,6 +130,36 @@
       delegate.addCacheListener(arg0);
    }
 
+   public void addInterceptor(CommandInterceptor arg0, Class arg1)
+   {
+      delegate.addInterceptor(arg0, arg1);      
+   }
+
+   public void addInterceptor(CommandInterceptor arg0, int arg1)
+   {
+      delegate.addInterceptor(arg0, arg1); 
+   }
+
+   public void removeInterceptor(Class arg0)
+   {
+      delegate.removeInterceptor(arg0);
+   }
+
+   public void removeInterceptor(int arg0)
+   {
+      delegate.removeInterceptor(arg0);
+   }
+
+   public void startBatch()
+   {
+      delegate.startBatch();      
+   }
+
+   public void endBatch(boolean arg0)
+   {
+      delegate.endBatch(arg0);
+   }
+
    public void clearData(String arg0)
    {
       delegate.clearData(arg0);

Modified: projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/ha/cachemanager/PojoCacheManagerManagedPojoCache.java
===================================================================
--- projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/ha/cachemanager/PojoCacheManagerManagedPojoCache.java	2008-11-09 03:12:34 UTC (rev 80712)
+++ projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/ha/cachemanager/PojoCacheManagerManagedPojoCache.java	2008-11-09 03:13:42 UTC (rev 80713)
@@ -33,6 +33,7 @@
 import org.jboss.cache.pojo.PojoCache;
 import org.jboss.cache.pojo.PojoCacheException;
 import org.jboss.cache.pojo.PojoCacheThreadContext;
+import org.jboss.cache.pojo.Reference;
 import org.jboss.logging.Logger;
 import org.jboss.util.loading.ContextClassLoaderSwitcher;
 
@@ -180,16 +181,21 @@
       return c == null ? null : new CacheManagerManagedCache(c);
    }
 
-   public Collection<Object> getListeners()
+   public Fqn<?> getInternalFqn(Object arg0)
    {
-      return delegate.getListeners();
+      return delegate.getInternalFqn(arg0);
    }
 
-   public String getPojoID(Object arg0)
+   public Collection<Reference> getReferences(Object arg0)
    {
-      return delegate.getPojoID(arg0);
+      return delegate.getReferences(arg0);
    }
 
+   public Collection<Object> getListeners()
+   {
+      return delegate.getListeners();
+   }
+
    public PojoCacheThreadContext getThreadContext()
    {
       return delegate.getThreadContext();

Modified: projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/CacheListener.java
===================================================================
--- projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/CacheListener.java	2008-11-09 03:12:34 UTC (rev 80712)
+++ projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/CacheListener.java	2008-11-09 03:13:42 UTC (rev 80713)
@@ -22,6 +22,8 @@
 package org.jboss.web.tomcat.service.session.distributedcache.impl.jbc;
 
 import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicLong;
 
 import org.jboss.cache.Fqn;
 import org.jboss.cache.notifications.annotation.NodeModified;
@@ -30,8 +32,6 @@
 import org.jboss.cache.notifications.event.NodeRemovedEvent;
 import org.jboss.logging.Logger;
 import org.jboss.web.tomcat.service.session.distributedcache.spi.DistributableSessionMetadata;
-import org.jboss.web.tomcat.service.session.distributedcache.spi.DistributableSessionTimestamp;
-import org.jboss.web.tomcat.service.session.distributedcache.spi.DistributedCacheManager;
 import org.jboss.web.tomcat.service.session.distributedcache.spi.LocalDistributableSessionManager;
 
 /**
@@ -115,32 +115,40 @@
          // Query if we have version value in the distributed cache. 
          // If we have a version value, compare the version and invalidate if necessary.
          Map data = event.getData();
-         Integer version = (Integer) data.get(DistributedCacheManager.VERSION_KEY);
+         AtomicInteger version = (AtomicInteger) data.get(JBossCacheService.VERSION_KEY);
          if(version != null)
          {
             String realId = getIdFromFqn(fqn, isBuddy);
             String owner = isBuddy ? getBuddyOwner(fqn) : null;
-            // Notify the manager that a session has been updated
-            boolean updated = manager_.sessionChangedInDistributedCache(realId, owner, 
-                                               version.intValue(), 
-                                               (DistributableSessionTimestamp) data.get(DistributedCacheManager.TIMESTAMP_KEY), 
-                                               (DistributableSessionMetadata) data.get(DistributedCacheManager.METADATA_KEY));
-            if (!updated && !isBuddy)
+            AtomicLong timestamp = (AtomicLong) data.get(JBossCacheService.TIMESTAMP_KEY);
+            if (timestamp == null)
             {
-               log_.warn("Possible concurrency problem: Replicated version id " + 
-                         version + " is less than or equal to in-memory version for session " + realId); 
+               log_.warn("No timestamp attribute found in " + fqn);
             }
-            /*else 
+            else
             {
-               We have a local session but got a modification for the buddy tree.
-               This means another node is in the process of taking over the session;
-               we don't worry about it
+               // Notify the manager that a session has been updated
+               boolean updated = manager_.sessionChangedInDistributedCache(realId, owner, 
+                                                  version.get(), 
+                                                  timestamp.get(), 
+                                                  (DistributableSessionMetadata) data.get(JBossCacheService.METADATA_KEY));
+               if (!updated && !isBuddy)
+               {
+                  log_.warn("Possible concurrency problem: Replicated version id " + 
+                            version + " is less than or equal to in-memory version for session " + realId); 
+               }
+               /*else 
+               {
+                  We have a local session but got a modification for the buddy tree.
+                  This means another node is in the process of taking over the session;
+                  we don't worry about it
+               }
+                */
             }
-             */
          }
          else
          {
-            log_.warn("No VERSION_KEY attribute found in " + fqn);
+            log_.warn("No version attribute found in " + fqn);
          }
       }
       else if (local && !isBuddy
@@ -184,6 +192,6 @@
    public static boolean isPossibleInternalPojoFqn(Fqn fqn)
    {      
       return (fqn.size() > POJO_INTERNAL_FQN_SIZE 
-            && JBossCacheService.ATTRIBUTE.equals(fqn.get(POJO_INTERNAL_FQN_INDEX)) == false);
+            && FieldBasedJBossCacheService.ATTRIBUTE.equals(fqn.get(POJO_INTERNAL_FQN_INDEX)) == false);
    }
 }

Added: projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/DistributableSessionDataImpl.java
===================================================================
--- projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/DistributableSessionDataImpl.java	                        (rev 0)
+++ projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/DistributableSessionDataImpl.java	2008-11-09 03:13:42 UTC (rev 80713)
@@ -0,0 +1,90 @@
+/*
+ * 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.distributedcache.impl.jbc;
+
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicLong;
+
+import org.jboss.web.tomcat.service.session.distributedcache.spi.DistributableSessionData;
+import org.jboss.web.tomcat.service.session.distributedcache.spi.DistributableSessionMetadata;
+
+/**
+ * Base implementation of {@link DistributableSessionData}.
+ * 
+ * @author Brian Stansberry
+ */
+public class DistributableSessionDataImpl implements DistributableSessionData
+{
+   private final int version;
+   private final long timestamp;
+   private final DistributableSessionMetadata metadata;
+   private final Map<String, Object> attributes;
+   
+   protected DistributableSessionDataImpl(AtomicInteger version, AtomicLong timestamp, 
+                                              DistributableSessionMetadata metadata,
+                                              Map<String, Object> attributes)
+   {
+      if (version == null)
+         throw new IllegalStateException("version is null");
+      if (timestamp == null)
+         throw new IllegalStateException("timestamp is null");
+      if (metadata == null)
+         throw new IllegalStateException("metadata is null");
+      
+      this.version = version.get();
+      this.timestamp = timestamp.get();
+      this.metadata = metadata;
+      this.attributes = attributes;
+   }
+
+   public boolean providesSessionAttributes()
+   {
+      return attributes != null;
+   }
+
+   public Map<String, Object> getSessionAttributes()
+   {
+      if (attributes == null)
+      {
+         throw new IllegalStateException("Not configured to provide session attributes");
+      }
+      return attributes;
+   }   
+   
+   public DistributableSessionMetadata getMetadata()
+   {
+      return metadata;
+   }
+
+   public long getTimestamp()
+   {
+      return timestamp;
+   }
+
+   public int getVersion()
+   {
+      return version;
+   }
+
+}


Property changes on: projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/DistributableSessionDataImpl.java
___________________________________________________________________
Name: svn:mergeinfo
   + 

Modified: projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/FieldBasedJBossCacheService.java
===================================================================
--- projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/FieldBasedJBossCacheService.java	2008-11-09 03:12:34 UTC (rev 80712)
+++ projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/FieldBasedJBossCacheService.java	2008-11-09 03:13:42 UTC (rev 80713)
@@ -23,7 +23,10 @@
 package org.jboss.web.tomcat.service.session.distributedcache.impl.jbc;
 
 import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 import java.util.StringTokenizer;
 
@@ -44,6 +47,14 @@
  */
 public class FieldBasedJBossCacheService extends JBossCacheService implements FieldBasedDistributedCacheManager
 {
+   public static final String ATTRIBUTE = "ATTRIBUTE";
+
+   public static Fqn getAttributeFqn(String hostname, String contextPath, String sessionId)
+   {
+      Object[] objs = new Object[]{SESSION, hostname, contextPath, sessionId, ATTRIBUTE};
+      return Fqn.fromList(Arrays.asList(objs), true);
+   }
+   
    private final PojoCache pojoCache_;
    
    public FieldBasedJBossCacheService(String cacheConfigName) throws ClusteringNotSupportedException
@@ -78,6 +89,23 @@
       return true;
    }
 
+   @Override
+   protected Map<String, Object> getSessionAttributes(String realId, Map<Object, Object> distributedCacheData)
+   {
+      Map<String, Object> attrs = new HashMap<String, Object>();
+      Set<String> keys = getPojoKeys(realId);
+      for (String key : keys)
+      {
+         attrs.put(key, getPojo(realId, key));
+      }
+      return attrs;
+   }
+
+   private Fqn getAttributeFqn(String id)
+   {
+      return getAttributeFqn(hostName_, webAppPath_, id);
+   }
+
    private Fqn getFieldFqn(String id, String key)
    {
       return getFieldFqn(hostName_, webAppPath_, id, key);
@@ -102,12 +130,12 @@
       list.add(ATTRIBUTE);
       // Guard against string with delimiter.
       breakKeys(attributeKey, list);
-      return new Fqn(list);      
+      return Fqn.fromList(list, true);      
    }
 
    /**
     * store the pojo instance in the cache. Note that this is for the aop cache.
-    * THe pojo needs to be "aspectized".
+    * The pojo needs to be "aspectized".
     * 
     * @param realId the session id with any jvmRoute removed
     * @param key    the attribute key

Modified: projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/JBossCacheService.java
===================================================================
--- projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/JBossCacheService.java	2008-11-09 03:12:34 UTC (rev 80712)
+++ projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/JBossCacheService.java	2008-11-09 03:13:42 UTC (rev 80713)
@@ -24,11 +24,14 @@
 import java.io.IOException;
 import java.io.Serializable;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
-import java.util.Map.Entry;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicLong;
 
 import javax.transaction.TransactionManager;
 
@@ -52,8 +55,8 @@
 import org.jboss.web.tomcat.service.session.distributedcache.spi.BatchingManager;
 import org.jboss.web.tomcat.service.session.distributedcache.spi.ClusteringNotSupportedException;
 import org.jboss.web.tomcat.service.session.distributedcache.spi.DistributableSession;
+import org.jboss.web.tomcat.service.session.distributedcache.spi.DistributableSessionData;
 import org.jboss.web.tomcat.service.session.distributedcache.spi.DistributableSessionMetadata;
-import org.jboss.web.tomcat.service.session.distributedcache.spi.DistributableSessionTimestamp;
 import org.jboss.web.tomcat.service.session.distributedcache.spi.DistributedCacheManager;
 import org.jboss.web.tomcat.service.session.distributedcache.spi.LocalDistributableSessionManager;
 import org.jboss.web.tomcat.service.session.distributedcache.spi.SessionSerializationFactory;
@@ -74,8 +77,15 @@
    public static final String BUDDY_BACKUP = BuddyManager.BUDDY_BACKUP_SUBTREE;
    public static final Fqn BUDDY_BACKUP_FQN = BuddyManager.BUDDY_BACKUP_SUBTREE_FQN;
    public static final String SESSION = "JSESSION";
-   public static final String ATTRIBUTE = "ATTRIBUTE";
-      
+   
+   // Use Integers as JBC keys -- replication performant but won't be
+   // confused with String attribute keys for ATTRIBUTE granularity sessions
+   public static final Integer VERSION_KEY = new Integer(0);
+   public static final Integer TIMESTAMP_KEY = new Integer(1);
+   public static final Integer METADATA_KEY = new Integer(2);
+   public static final Integer ATTRIBUTE_KEY = new Integer(3);
+   private static final Set<Integer> INTERNAL_KEYS = new HashSet<Integer>(Arrays.asList(VERSION_KEY, TIMESTAMP_KEY, METADATA_KEY, ATTRIBUTE_KEY)); 
+    
    public static final String FQN_DELIMITER = "/";
    
    private Cache plainCache_;
@@ -337,11 +347,8 @@
       
       setupSessionRegion(toLoad, fqn);
       
-      Integer version = (Integer) sessionData.get(VERSION_KEY);
-      DistributableSessionTimestamp timestamp = (DistributableSessionTimestamp) sessionData.get(TIMESTAMP_KEY);
-      DistributableSessionMetadata metadata = (DistributableSessionMetadata) sessionData.get(METADATA_KEY);
-      Map attrs = (Map) getUnMarshalledValue(sessionData.get(ATTRIBUTE_KEY));
-      toLoad.update(version, timestamp, metadata, attrs);
+      DistributableSessionData dsd = getDistributableSessionData(realId, sessionData, true);
+      toLoad.update(dsd);
       
       return toLoad;
    }
@@ -358,7 +365,7 @@
       setupSessionRegion(session, fqn);
       
       Map map = new HashMap();
-      map.put(VERSION_KEY, new Integer(session.getVersion()));
+      map.put(VERSION_KEY, session.getVersion());
       
       boolean replicateTimestamp = false;
       
@@ -472,21 +479,22 @@
       cacheWrapper_.evictSubtree(fqn);      
    }
    
-   public Map getSessionData(String realId, String dataOwner)
+   public DistributableSessionData getSessionData(String realId, String dataOwner, boolean includeAttributes)
    {
       Fqn fqn = dataOwner == null ? getSessionFqn(realId) : getSessionFqn(realId, dataOwner);
-      return cacheWrapper_.getData(fqn, false);
+      Map<Object, Object> distributedCacheData = cacheWrapper_.getData(fqn, false);
+      return getDistributableSessionData(realId, distributedCacheData, includeAttributes);
    }
 
    public Object getAttribute(String realId, String key)
    {
-      Fqn fqn = getAttributeFqn(realId);
+      Fqn fqn = getSessionFqn(realId);
       return getUnMarshalledValue(cacheWrapper_.get(fqn, key));
    }
 
    public void putAttribute(String realId, String key, Object value)
    {
-      Fqn fqn = getAttributeFqn(realId);
+      Fqn fqn = getSessionFqn(realId);
       cacheWrapper_.put(fqn, key, getMarshalledValue(value));
    }
 
@@ -501,20 +509,14 @@
          marshalled.put(entry.getKey(), getMarshalledValue(entry.getValue()));
       }
       
-      Fqn fqn = getAttributeFqn(realId);
+      Fqn fqn = getSessionFqn(realId);
       cacheWrapper_.put(fqn, marshalled);
       
    }
 
-   public void removeAttributes(String realId)
-   {
-      Fqn fqn = getAttributeFqn(realId);
-      cacheWrapper_.remove(fqn);
-   }
-
    public Object removeAttribute(String realId, String key)
    {
-      Fqn fqn = getAttributeFqn(realId);
+      Fqn fqn = getSessionFqn(realId);
       if (log_.isTraceEnabled())
       {
          log_.trace("Remove attribute from distributed store. Fqn: " + fqn + " key: " + key);
@@ -522,16 +524,6 @@
       return getUnMarshalledValue(cacheWrapper_.remove(fqn, key));
    }
 
-   public void removeAttributesLocal(String realId)
-   {
-      Fqn fqn = getAttributeFqn(realId);
-      if (log_.isTraceEnabled())
-      {
-         log_.trace("Remove attributes from my own distributed store only. Fqn: " + fqn);
-      }
-      cacheWrapper_.removeLocal(fqn);
-   }
-
    /**
     * Obtain the keys associated with this fqn. Note that it is not the fqn children.
     *
@@ -539,12 +531,15 @@
    public Set getAttributeKeys(String realId)
    {
       Set keys = null;
-      Fqn fqn = getAttributeFqn(realId);
+      Fqn fqn = getSessionFqn(realId);
       try
       {
          Node node = plainCache_.getRoot().getChild(fqn);
          if (node != null)
+         {
             keys = node.getKeys();
+            keys.removeAll(INTERNAL_KEYS);
+         }
       }
       catch (CacheException e)
       {
@@ -560,23 +555,16 @@
     * @param realId the session id with any jvmRoute removed
     * @return the attributes, or any empty Map if none are found.
     */
-   public Map getAttributes(String realId)
+   public Map<String, Object> getAttributes(String realId)
    {
-      if (realId == null || realId.length() == 0) return new HashMap();
+      if (realId == null || realId.length() == 0) return Collections.EMPTY_MAP;
       
-      Map attrs = new HashMap();
-      Fqn fqn = getAttributeFqn(realId);
+      Fqn fqn = getSessionFqn(realId);
       
       Node node = plainCache_.getRoot().getChild(fqn);
-      Map rawData = node.getData();
+      Map<Object, Object> rawData = node.getData();
       
-      for (Iterator it = rawData.entrySet().iterator(); it.hasNext();)
-      {
-         Entry entry = (Entry) it.next();
-         attrs.put(entry.getKey(), getUnMarshalledValue(entry.getValue()));
-      }
-      
-      return attrs;
+      return getSessionAttributes(realId, rawData);
    }
 
    /**
@@ -652,6 +640,50 @@
       return getSessionFqn(hostName_, webAppPath_, id);
    }
    
+   /**
+    * Extracts the contents of <code>distributedCacheData</code>.
+    * 
+    * <strong>Note:</strong> This operation may alter the contents of the 
+    * passed in map. If this is unacceptable, pass in a defensive copy.
+    */
+   protected DistributableSessionData getDistributableSessionData(String realId, 
+                                       Map<Object, Object> distributedCacheData, 
+                                       boolean includeAttributes)
+   {
+      AtomicInteger version = (AtomicInteger) distributedCacheData.get(VERSION_KEY);
+      AtomicLong timestamp = (AtomicLong) distributedCacheData.get(TIMESTAMP_KEY);
+      DistributableSessionMetadata metadata = (DistributableSessionMetadata) distributedCacheData.get(METADATA_KEY);
+      Map<String, Object> attrs = includeAttributes ? getSessionAttributes(realId, distributedCacheData) : null;      
+      return new DistributableSessionDataImpl(version, timestamp, metadata, attrs);
+   }
+   
+   /**
+    * Returns the session attributes, possibly using the passed in 
+    * <code>distributedCacheData</code> as a source.
+    * 
+    * <strong>Note:</strong> This operation may alter the contents of the 
+    * passed in map. If this is unacceptable, pass in a defensive copy.
+    */
+   protected Map<String, Object> getSessionAttributes(String realId, Map<Object, Object> distributedCacheData)
+   {
+      // First check for all attributes stored in a single key/value pair
+      Map<String, Object> attrs = (Map) getUnMarshalledValue(distributedCacheData.get(ATTRIBUTE_KEY));
+      if (attrs == null)
+      {
+         // Copy out all the String K/V pairs; those are attributes
+         attrs = new HashMap<String, Object>();         
+         for (Map.Entry<Object, Object> entry : distributedCacheData.entrySet())
+         {
+            if (entry.getKey() instanceof String)
+            {
+               attrs.put((String) entry.getKey(), getUnMarshalledValue(entry.getValue()));
+            }                
+         }
+      }
+      
+      return attrs;
+   }
+   
    public static Fqn getSessionFqn(String hostname, String contextPath, String sessionId)
    {
       Object[] objs = new Object[]{SESSION, hostname, contextPath, sessionId};
@@ -668,17 +700,6 @@
       Object[] objs = new Object[]{BUDDY_BACKUP, dataOwner, SESSION, hostname, contextPath, sessionId};
       return Fqn.fromList(Arrays.asList(objs), true);
    }
-
-   protected Fqn getAttributeFqn(String id)
-   {
-      return getAttributeFqn(hostName_, webAppPath_, id);
-   }
-
-   public static Fqn getAttributeFqn(String hostname, String contextPath, String sessionId)
-   {
-      Object[] objs = new Object[]{SESSION, hostname, contextPath, sessionId, ATTRIBUTE};
-      return Fqn.fromList(Arrays.asList(objs), true);
-   }
    
    protected void releaseCacheToManager(String cacheConfigName)
    {      

Modified: projects/cluster/ha-server-cache-spi/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/spi/DistributableSession.java
===================================================================
--- projects/cluster/ha-server-cache-spi/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/spi/DistributableSession.java	2008-11-09 03:12:34 UTC (rev 80712)
+++ projects/cluster/ha-server-cache-spi/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/spi/DistributableSession.java	2008-11-09 03:13:42 UTC (rev 80713)
@@ -22,6 +22,8 @@
 package org.jboss.web.tomcat.service.session.distributedcache.spi;
 
 import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicLong;
 
 /**
  * Interface implemented by a <code>Session</code> implementation that
@@ -34,17 +36,17 @@
 {
    String getIdInternal();
    
-   int getVersion();
+   AtomicInteger getVersion();
 
    boolean getMustReplicateTimestamp();
 
-   DistributableSessionTimestamp getSessionTimestamp();
+   AtomicLong getSessionTimestamp();
 
    DistributableSessionMetadata getSessionMetadata();
 
    Map<String, Object> getSessionAttributeMap();
 
-   void update(Integer version, DistributableSessionTimestamp timestamp, DistributableSessionMetadata metadata, Map attributes);
+   void update(DistributableSessionData sessionData);
 
    boolean isSessionMetadataDirty();
 

Added: projects/cluster/ha-server-cache-spi/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/spi/DistributableSessionData.java
===================================================================
--- projects/cluster/ha-server-cache-spi/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/spi/DistributableSessionData.java	                        (rev 0)
+++ projects/cluster/ha-server-cache-spi/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/spi/DistributableSessionData.java	2008-11-09 03:13:42 UTC (rev 80713)
@@ -0,0 +1,71 @@
+/*
+ * 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.distributedcache.spi;
+
+import java.util.Map;
+
+/**
+ * Encapsulates the four types of data about a session that are stored
+ * in a distributed cache.
+ * 
+ * @author Brian Stansberry
+ */
+public interface DistributableSessionData
+{
+   /**
+    * Gets the session's version.
+    */
+   int getVersion();
+   
+   /**
+    * Gets the timestamp of the most recent session access.
+    */
+   long getTimestamp();
+   
+   /**
+    * Gets the other session metadata besides the version and timestamp.
+    */
+   DistributableSessionMetadata getMetadata();
+   
+   /**
+    * Gets whether it is safe to invoke {@link #getSessionAttributes()}
+    * on this object.
+    * 
+    * @return <code>true</code> if {@link #getSessionAttributes()} will
+    *         return a map; <code>false</code> if it will throw an
+    *         IllegalStateException.
+    */
+   boolean providesSessionAttributes();
+   
+   /**
+    * Returns the session's attribute map, or throws an
+    * IllegalStateException if {@link #providesSessionAttributes()} would
+    * return <code>false</code>.
+    * 
+    * @return the session attribute map. Will not return <code>null</code>
+    * 
+    * @throws IllegalStateException if {@link #providesSessionAttributes()} would
+    * return <code>false</code>.
+    */
+   Map<String, Object> getSessionAttributes();
+}

Modified: projects/cluster/ha-server-cache-spi/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/spi/DistributableSessionMetadata.java
===================================================================
--- projects/cluster/ha-server-cache-spi/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/spi/DistributableSessionMetadata.java	2008-11-09 03:12:34 UTC (rev 80712)
+++ projects/cluster/ha-server-cache-spi/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/spi/DistributableSessionMetadata.java	2008-11-09 03:13:42 UTC (rev 80713)
@@ -39,7 +39,7 @@
    private long creationTime;
    private int maxInactiveInterval;
    private boolean isNew;
-   private boolean isValid;
+   private boolean isValid;   
    
    public String getId()
    {

Deleted: projects/cluster/ha-server-cache-spi/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/spi/DistributableSessionTimestamp.java
===================================================================
--- projects/cluster/ha-server-cache-spi/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/spi/DistributableSessionTimestamp.java	2008-11-09 03:12:34 UTC (rev 80712)
+++ projects/cluster/ha-server-cache-spi/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/spi/DistributableSessionTimestamp.java	2008-11-09 03:13:42 UTC (rev 80713)
@@ -1,49 +0,0 @@
-/*
- * 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.distributedcache.spi;
-
-import java.io.Serializable;
-
-/**
- * Encapsulates the "thisAccessedTime" timestamp. The wrapped timestamp long
- * can be mutated, allowing the same object to always be stored in 
- * JBoss Cache. Always storing the same object avoids an earlier, no
- * longer accurate, object being reverted into the cache during a 
- * transaction rollback.
- */
-public class DistributableSessionTimestamp implements Serializable
-{
-   /** The serialVersionUID */
-   private static final long serialVersionUID = 2317131983552715467L;
-   
-   private long timestamp = 0L;
-
-   public long getTimestamp()
-   {
-      return timestamp;
-   }
-
-   public void setTimestamp(long timestamp)
-   {
-      this.timestamp = timestamp;
-   }
-}
\ No newline at end of file

Modified: projects/cluster/ha-server-cache-spi/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/spi/DistributedCacheManager.java
===================================================================
--- projects/cluster/ha-server-cache-spi/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/spi/DistributedCacheManager.java	2008-11-09 03:12:34 UTC (rev 80712)
+++ projects/cluster/ha-server-cache-spi/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/spi/DistributedCacheManager.java	2008-11-09 03:13:42 UTC (rev 80713)
@@ -33,15 +33,6 @@
  */
 public interface DistributedCacheManager
 {
-   /** Key in the map returned by {@link #getSessionData(String, String)} */
-   public static final String VERSION_KEY = "V";
-   /** Key in the map returned by {@link #getSessionData(String, String)} */
-   public static final String TIMESTAMP_KEY = "T";
-   /** Key in the map returned by {@link #getSessionData(String, String)} */
-   public static final String METADATA_KEY = "M";
-   /** Key in the map returned by {@link #getSessionData(String, String)} */
-   public static final String ATTRIBUTE_KEY = "A";
-
    /**
     * Configures and starts the distributed caching layer.
     * 
@@ -79,7 +70,7 @@
 
    void evictSession(String realId, String dataOwner);
 
-   Map getSessionData(String realId, String dataOwner);
+   DistributableSessionData getSessionData(String realId, String dataOwner, boolean includeAttributes);
 
    Object getAttribute(String realId, String key);
 
@@ -87,14 +78,10 @@
 
    void putAttribute(String realId, Map map);
 
-   void removeAttributes(String realId);
-
    Object removeAttribute(String realId, String key);
 
-   void removeAttributesLocal(String realId);
-
    /**
-    * Obtain the keys associated with this fqn. Note that it is not the fqn children.
+    * Obtain the attribute keys associated with this session.
     *
     */
    Set getAttributeKeys(String realId);
@@ -117,6 +104,9 @@
     */
    Map<String, String> getSessionIds();
 
+   /**
+    * Gets whether the underlying cache supports passivation.
+    */
    boolean isPassivationEnabled();
 
 }
\ No newline at end of file

Modified: projects/cluster/ha-server-cache-spi/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/spi/LocalDistributableSessionManager.java
===================================================================
--- projects/cluster/ha-server-cache-spi/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/spi/LocalDistributableSessionManager.java	2008-11-09 03:12:34 UTC (rev 80712)
+++ projects/cluster/ha-server-cache-spi/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/spi/LocalDistributableSessionManager.java	2008-11-09 03:13:42 UTC (rev 80713)
@@ -85,6 +85,6 @@
     * @param metadata the session's metadata per the distributed cache
     */
    boolean sessionChangedInDistributedCache(String realId, String dataOwner, int distributedVersion,
-         DistributableSessionTimestamp timestamp, DistributableSessionMetadata metadata);
+         long timestamp, DistributableSessionMetadata metadata);
 
 }
\ No newline at end of file




More information about the jboss-cvs-commits mailing list