[jboss-cvs] JBossAS SVN: r87250 - projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Apr 13 22:52:58 EDT 2009


Author: bstansberry at jboss.com
Date: 2009-04-13 22:52:58 -0400 (Mon, 13 Apr 2009)
New Revision: 87250

Added:
   projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/IncomingDistributableSessionDataImpl.java
Removed:
   projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/DistributableSessionDataImpl.java
Modified:
   projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/AbstractJBossCacheService.java
   projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/AttributeBasedJBossCacheService.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/SessionBasedJBossCacheService.java
Log:
[JBCLUSTER-233] Get rid of DistributableSession
[JBCLUSTER-221] Don't expose Atomic objects for session version and timestamp
[JBCLUSTER-222] For ATTRIBUTE granularity, pass modification maps through to DistributedCacheManager

Modified: projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/AbstractJBossCacheService.java
===================================================================
--- projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/AbstractJBossCacheService.java	2009-04-14 02:52:12 UTC (rev 87249)
+++ projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/AbstractJBossCacheService.java	2009-04-14 02:52:58 UTC (rev 87250)
@@ -30,8 +30,6 @@
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.concurrent.atomic.AtomicLong;
 
 import javax.transaction.TransactionManager;
 
@@ -55,17 +53,17 @@
 import org.jboss.util.loading.ContextClassLoaderSwitcher;
 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.DistributedCacheManager;
+import org.jboss.web.tomcat.service.session.distributedcache.spi.IncomingDistributableSessionData;
 import org.jboss.web.tomcat.service.session.distributedcache.spi.LocalDistributableSessionManager;
+import org.jboss.web.tomcat.service.session.distributedcache.spi.OutgoingDistributableSessionData;
 import org.jboss.web.tomcat.service.session.distributedcache.spi.SessionSerializationFactory;
 
 /**
  * Abstract base implementation of {@link DistributedCacheManager}.
  */
-public abstract class AbstractJBossCacheService implements DistributedCacheManager
+public abstract class AbstractJBossCacheService<T extends OutgoingDistributableSessionData> implements DistributedCacheManager<T>
 {   
    public static final String BUDDY_BACKUP = BuddyManager.BUDDY_BACKUP_SUBTREE;
    @SuppressWarnings("unchecked")
@@ -167,9 +165,6 @@
    {
       this.plainCache_ = cache;
    }
-   
-   protected abstract boolean getStoreAttributesInSingleKey();
-   protected abstract boolean isFieldBased();
 
    public void start()
    {
@@ -337,27 +332,18 @@
       return useTreeCacheMarshalling_;
    }
    
-   
-
-   public void sessionCreated(DistributableSession session)
+   public void sessionCreated(String realId)
    {
-      if (session.needRegionForSession())
-      {
-         Fqn<String> fqn = getSessionFqn(combinedPath_, session.getRealId());
-         setupSessionRegion(session, fqn);
-      }      
+      // no-op by default    
    }
-
-   /**
-    * Loads any serialized data in the cache into the given session
-    * using its <code>readExternal</code> method.
-    *
-    * @return the session passed as <code>toLoad</code>, or
-    *         <code>null</code> if the cache had no data stored
-    *         under the given session id.
-    */
-   public <T extends DistributableSession> T loadSession(String realId, T toLoad)
+   
+   public IncomingDistributableSessionData getSessionData(String realId, boolean initialLoad)
    {
+      if (realId == null)
+      {
+         throw new IllegalArgumentException("Null realId");
+      }
+      
       Fqn<String> fqn = getSessionFqn(combinedPath_, realId);
       Map<Object, Object> sessionData =  cacheWrapper_.getData(fqn, true);
       
@@ -366,12 +352,12 @@
          return null;
       }
       
-      if (toLoad.needRegionForSession())
+      if (initialLoad)
       {
-         setupSessionRegion(toLoad, fqn);
+         setupSessionRegion(fqn);
       }
       
-      DistributableSessionData dsd = null;
+      IncomingDistributableSessionData dsd = null;
       
       try
       {
@@ -380,17 +366,17 @@
       catch (Exception e)
       {
          log_.warn("Problem accessing session data : " + e.getClass() + " " + e.getLocalizedMessage());
+         // Clean up
+         removeSessionLocal(realId);
          return null;
       }
       
-      toLoad.update(dsd);
-      
-      return toLoad;
+      return dsd;
    }
 
-   public void putSession(DistributableSession session)
+   public void storeSessionData(T sessionData)
    { 
-      String realId = session.getRealId();
+      String realId = sessionData.getRealId();
       
       if (log_.isTraceEnabled())
       {
@@ -400,33 +386,22 @@
       Fqn<String> fqn = getSessionFqn(combinedPath_, realId);
       
       Map<Object, Object> map = new HashMap<Object, Object>();
-      map.put(VERSION_KEY, session.getVersion());
+      map.put(VERSION_KEY, Integer.valueOf(sessionData.getVersion()));
       
-      boolean replicateTimestamp = false;
-      
-      if (session.isSessionMetadataDirty())
+      DistributableSessionMetadata dsm = sessionData.getMetadata();
+      if (dsm != null)
       {   
-         map.put(METADATA_KEY, session.getSessionMetadata()); 
-         replicateTimestamp = true;
+         map.put(METADATA_KEY, dsm);
       }
-     
-      if (session.isSessionAttributeMapDirty())
-      {
-         if (getStoreAttributesInSingleKey())
-         {
-            Map<String, Object> attrs = session.getSessionAttributeMap();
-            map.put(ATTRIBUTE_KEY, getMarshalledValue(attrs));
-         }
-         // Whether or not we stored the attributes above, we need
-         // to replicate timestamp
-         replicateTimestamp = true;
-      }
       
-      if (replicateTimestamp || session.getMustReplicateTimestamp())
+      Long timestamp = sessionData.getTimestamp();
+      if (timestamp != null)
       {
-         map.put(TIMESTAMP_KEY, session.getSessionTimestamp());
+         map.put(TIMESTAMP_KEY, timestamp);
       }
       
+      storeSessionAttributes(map, sessionData);
+      
       cacheWrapper_.put(fqn, map);
    }
 
@@ -436,9 +411,11 @@
     * @param session the session
     * @param fqn the fqn for the session
     */
-   protected void setupSessionRegion(DistributableSession session, Fqn<String> fqn)
+   protected void setupSessionRegion(Fqn<String> fqn)
    {      
    }
+   
+   protected abstract void storeSessionAttributes(Map<Object, Object> dataMap, T sessionData);
 
    /**
     * Extension point to allow subclasses to remove per-session JBC regions.
@@ -508,7 +485,7 @@
       cacheWrapper_.evictSubtree(fqn);      
    }
    
-   public DistributableSessionData getSessionData(String realId, String dataOwner, boolean includeAttributes)
+   public IncomingDistributableSessionData getSessionData(String realId, String dataOwner, boolean includeAttributes)
    {
       Fqn<String> fqn = dataOwner == null ? getSessionFqn(combinedPath_, realId) : getBuddyBackupSessionFqn(dataOwner, combinedPath_, realId);
       Map<Object, Object> distributedCacheData = cacheWrapper_.getData(fqn, false);
@@ -594,15 +571,15 @@
     * <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, 
+   protected IncomingDistributableSessionData getDistributableSessionData(String realId, 
                                        Map<Object, Object> distributedCacheData, 
                                        boolean includeAttributes)
    {
-      AtomicInteger version = (AtomicInteger) distributedCacheData.get(VERSION_KEY);
-      AtomicLong timestamp = (AtomicLong) distributedCacheData.get(TIMESTAMP_KEY);
+      Integer version = (Integer) distributedCacheData.get(VERSION_KEY);
+      Long timestamp = (Long) 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);
+      return new IncomingDistributableSessionDataImpl(version, timestamp, metadata, attrs);
    }
    
    /**

Modified: projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/AttributeBasedJBossCacheService.java
===================================================================
--- projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/AttributeBasedJBossCacheService.java	2009-04-14 02:52:12 UTC (rev 87249)
+++ projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/AttributeBasedJBossCacheService.java	2009-04-14 02:52:58 UTC (rev 87250)
@@ -32,11 +32,12 @@
 import org.jboss.cache.Node;
 import org.jboss.web.tomcat.service.session.distributedcache.spi.ClusteringNotSupportedException;
 import org.jboss.web.tomcat.service.session.distributedcache.spi.LocalDistributableSessionManager;
+import org.jboss.web.tomcat.service.session.distributedcache.spi.OutgoingAttributeGranularitySessionData;
 
 /**
  * DistributedCacheManager impl for ReplicationGranularity.ATTRIBUTE.
  */
-public class AttributeBasedJBossCacheService extends AbstractJBossCacheService
+public class AttributeBasedJBossCacheService extends AbstractJBossCacheService<OutgoingAttributeGranularitySessionData>
 {   
    public AttributeBasedJBossCacheService(LocalDistributableSessionManager localManager) throws ClusteringNotSupportedException
    {
@@ -168,15 +169,37 @@
       
       return attrs;
    }
-   
-   protected boolean isFieldBased()
+
+   @Override
+   protected void storeSessionAttributes(Map<Object, Object> dataMap,
+         OutgoingAttributeGranularitySessionData sessionData)
    {
-      return false;
+      Fqn<String> fqn = null;
+      Map<String, Object> map = sessionData.getModifiedSessionAttributes();
+      if (map != null)
+      {
+         // Duplicate the map with marshalled values
+         Map<Object, Object> marshalled = new HashMap<Object, Object>(map.size());
+         for (Map.Entry<String, Object> entry : map.entrySet())
+         {
+            marshalled.put(entry.getKey(), getMarshalledValue(entry.getValue()));
+         }
+         fqn = getSessionFqn(combinedPath_, sessionData.getRealId());
+         cacheWrapper_.put(fqn, marshalled);
+      }
+      
+      Set<String> removed = sessionData.getRemovedSessionAttributes();
+      if (removed != null)
+      {
+         if (fqn == null)
+         {
+            fqn = getSessionFqn(combinedPath_, sessionData.getRealId());
+         }
+         for (String key : removed)
+         {
+            cacheWrapper_.remove(fqn, key);
+         }
+      }
    }
-   
-   protected boolean getStoreAttributesInSingleKey()
-   {
-      return false;
-   }
 
 }

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	2009-04-14 02:52:12 UTC (rev 87249)
+++ projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/CacheListener.java	2009-04-14 02:52:58 UTC (rev 87250)
@@ -22,8 +22,6 @@
 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;
@@ -123,12 +121,12 @@
          // If we have a version value, compare the version and invalidate if necessary.
          @SuppressWarnings("unchecked")
          Map<Object, Object> data = event.getData();
-         AtomicInteger version = (AtomicInteger) data.get(AbstractJBossCacheService.VERSION_KEY);
+         Integer version = (Integer) data.get(AbstractJBossCacheService.VERSION_KEY);
          if(version != null)
          {
             String realId = getIdFromFqn(fqn, isBuddy);
             String owner = isBuddy ? getBuddyOwner(fqn) : null;
-            AtomicLong timestamp = (AtomicLong) data.get(AbstractJBossCacheService.TIMESTAMP_KEY);
+            Long timestamp = (Long) data.get(AbstractJBossCacheService.TIMESTAMP_KEY);
             if (timestamp == null)
             {
                log_.warn("No timestamp attribute found in " + fqn);
@@ -137,8 +135,8 @@
             {
                // Notify the manager that a session has been updated
                boolean updated = manager_.sessionChangedInDistributedCache(realId, owner, 
-                                                  version.get(), 
-                                                  timestamp.get(), 
+                                                  version.intValue(), 
+                                                  timestamp.longValue(), 
                                                   (DistributableSessionMetadata) data.get(AbstractJBossCacheService.METADATA_KEY));
                if (!updated && !isBuddy)
                {

Deleted: 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	2009-04-14 02:52:12 UTC (rev 87249)
+++ projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/DistributableSessionDataImpl.java	2009-04-14 02:52:58 UTC (rev 87250)
@@ -1,90 +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.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;
-   
-   public 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;
-   }
-
-}

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	2009-04-14 02:52:12 UTC (rev 87249)
+++ projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/FieldBasedJBossCacheService.java	2009-04-14 02:52:58 UTC (rev 87250)
@@ -36,15 +36,15 @@
 import org.jboss.ha.framework.server.PojoCacheManager;
 import org.jboss.ha.framework.server.PojoCacheManagerLocator;
 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.LocalDistributableSessionManager;
+import org.jboss.web.tomcat.service.session.distributedcache.spi.OutgoingDistributableSessionData;
 
 /**
  * DistributedCacheManager impl for ReplicationGranularity.FIELD.
  * 
  * @author Brian Stansberry *
  */
-public class FieldBasedJBossCacheService extends AbstractJBossCacheService
+public class FieldBasedJBossCacheService extends AbstractJBossCacheService<OutgoingDistributableSessionData>
 {
    public static final String ATTRIBUTE = "ATTRIBUTE";
 
@@ -202,12 +202,17 @@
          throw new RuntimeException("Exception occurred in PojoCache find ... ", e);
       }
    }
+
+   public void sessionCreated(String realId)
+   {
+      Fqn<String> fqn = getSessionFqn(combinedPath_, realId);
+      setupSessionRegion(fqn);
+   }
    
    @Override
-   protected void setupSessionRegion(DistributableSession session, Fqn<String> fqn)
+   protected void setupSessionRegion(Fqn<String> fqn)
    {
       getCache().getRegion(fqn, true);
-      session.createdRegionForSession();
       if (log_.isTraceEnabled())
       {
          log_.trace("Created region for session at " + fqn);
@@ -238,12 +243,6 @@
       }
    }
 
-   @Override
-   protected boolean getStoreAttributesInSingleKey()
-   {
-      return false;
-   }
-
    public Map<String, Object> getAttributes(String realId)
    {
       Map<String, Object> attrs = new HashMap<String, Object>();
@@ -262,12 +261,6 @@
          putAttribute(realId, entry.getKey(), entry.getValue());
       }      
    }
-   
-   @Override
-   protected boolean isFieldBased()
-   {
-      return true;
-   }
 
    /**
     * Overrides the superclass to pull in attributes via PojoCache API.
@@ -278,4 +271,10 @@
       return getAttributes(realId);
    }
 
+   @Override
+   protected void storeSessionAttributes(Map<Object, Object> dataMap, OutgoingDistributableSessionData sessionData)
+   {
+      // no-op; attributes are stored individually      
+   }
+
 }

Copied: projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/IncomingDistributableSessionDataImpl.java (from rev 81699, 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/IncomingDistributableSessionDataImpl.java	                        (rev 0)
+++ projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/IncomingDistributableSessionDataImpl.java	2009-04-14 02:52:58 UTC (rev 87250)
@@ -0,0 +1,107 @@
+/*
+ * 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.DistributableSessionMetadata;
+import org.jboss.web.tomcat.service.session.distributedcache.spi.IncomingDistributableSessionData;
+
+/**
+ * Base implementation of {@link DistributableSessionData}.
+ * 
+ * @author Brian Stansberry
+ */
+public class IncomingDistributableSessionDataImpl implements IncomingDistributableSessionData
+{
+   private final int version;
+   private final long timestamp;
+   private final DistributableSessionMetadata metadata;
+   private final Map<String, Object> attributes;
+   
+   public IncomingDistributableSessionDataImpl(Integer version, Long 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.intValue();
+      this.timestamp = timestamp.longValue();
+      this.metadata = metadata;
+      this.attributes = attributes;
+   }
+   
+   public IncomingDistributableSessionDataImpl(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;
+   }
+
+}

Modified: projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/SessionBasedJBossCacheService.java
===================================================================
--- projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/SessionBasedJBossCacheService.java	2009-04-14 02:52:12 UTC (rev 87249)
+++ projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/SessionBasedJBossCacheService.java	2009-04-14 02:52:58 UTC (rev 87250)
@@ -29,11 +29,12 @@
 import org.jboss.metadata.web.jboss.ReplicationGranularity;
 import org.jboss.web.tomcat.service.session.distributedcache.spi.ClusteringNotSupportedException;
 import org.jboss.web.tomcat.service.session.distributedcache.spi.LocalDistributableSessionManager;
+import org.jboss.web.tomcat.service.session.distributedcache.spi.OutgoingSessionGranularitySessionData;
 
 /**
  * DistributedCacheManager impl for ReplicationGranularity.SESSION.
  */
-public class SessionBasedJBossCacheService extends AbstractJBossCacheService
+public class SessionBasedJBossCacheService extends AbstractJBossCacheService<OutgoingSessionGranularitySessionData>
 {   
    private static UnsupportedOperationException UNSUPPORTED = 
       new UnsupportedOperationException("Attribute operations not supported " +
@@ -113,17 +114,15 @@
       Map<String, Object> result = (Map<String, Object>) getUnMarshalledValue(distributedCacheData.get(ATTRIBUTE_KEY));
       return result == null ? Collections.EMPTY_MAP : result;
    }
-   
-   @Override
-   protected boolean isFieldBased()
-   {
-      return false;
-   }
 
    @Override
-   protected boolean getStoreAttributesInSingleKey()
+   protected void storeSessionAttributes(Map<Object, Object> dataMap, OutgoingSessionGranularitySessionData sessionData)
    {
-      return true;
+      Map<String, Object> attrs = sessionData.getSessionAttributes();
+      if (attrs != null)
+      {
+         dataMap.put(ATTRIBUTE_KEY, getMarshalledValue(attrs));
+      }
    }
 
 }




More information about the jboss-cvs-commits mailing list