[jboss-cvs] JBossAS SVN: r95525 - 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
Fri Oct 23 16:50:56 EDT 2009


Author: bstansberry at jboss.com
Date: 2009-10-23 16:50:55 -0400 (Fri, 23 Oct 2009)
New Revision: 95525

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/IncomingDistributableSessionDataImpl.java
   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/Util.java
Log:
[JBCLUSTER]243] Improve handling of unmarshalling problems

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-10-23 20:10:20 UTC (rev 95524)
+++ projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/AbstractJBossCacheService.java	2009-10-23 20:50:55 UTC (rev 95525)
@@ -43,7 +43,6 @@
 import org.jboss.cache.Node;
 import org.jboss.cache.Region;
 import org.jboss.cache.buddyreplication.BuddyManager;
-import org.jboss.cache.config.BuddyReplicationConfig;
 import org.jboss.cache.config.CacheLoaderConfig;
 import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig;
 import org.jboss.cache.pojo.impl.InternalConstant;
@@ -628,8 +627,17 @@
       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 IncomingDistributableSessionDataImpl(version, timestamp, metadata, attrs);
+      IncomingDistributableSessionData result = null;
+      if (includeAttributes)
+      {
+         Map<String, Object> attrs = getSessionAttributes(realId, distributedCacheData);      
+         result = new IncomingDistributableSessionDataImpl(version, timestamp, metadata, attrs);
+      }
+      else
+      {
+         result = new IncomingDistributableSessionDataImpl(version, timestamp, metadata);
+      }
+      return result;
    }
    
    /**
@@ -693,7 +701,7 @@
 //      }
    }
 
-   protected Object getUnMarshalledValue(Object obj)
+   protected Object getUnMarshalledValue(Object obj) throws IOException, ClassNotFoundException
    {
       if (!(obj instanceof SimpleCachableMarshalledValue))
             return obj;
@@ -709,16 +717,6 @@
          mv.setObjectStreamSource(SessionSerializationFactory.getObjectStreamSource());
          return mv.get();
       }
-      catch (IOException e)
-      {
-         log_.error("IOException occurred unmarshalling value ", e);
-         return null;
-      }
-      catch (ClassNotFoundException e)
-      {
-         log_.error("ClassNotFoundException occurred unmarshalling value ", e);
-         return null;
-      }
       finally
       {
          if (switcher != null)

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-10-23 20:10:20 UTC (rev 95524)
+++ projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/AttributeBasedJBossCacheService.java	2009-10-23 20:50:55 UTC (rev 95525)
@@ -57,7 +57,7 @@
    public Object getAttribute(String realId, String key)
    {
       Fqn<String> fqn = getSessionFqn(combinedPath_, realId);
-      return getUnMarshalledValue(cacheWrapper_.get(fqn, key));
+      return unmarshall(realId, key, cacheWrapper_.get(fqn, key));
    }
 
    public void putAttribute(String realId, String key, Object value)
@@ -87,7 +87,7 @@
       {
          log_.trace("Remove attribute from distributed store. Fqn: " + fqn + " key: " + key);
       }
-      return getUnMarshalledValue(cacheWrapper_.remove(fqn, key));
+      return unmarshall(realId, key, cacheWrapper_.remove(fqn, key));
    }
 
    public void removeAttributeLocal(String realId, String key)
@@ -163,7 +163,8 @@
       {
          if (entry.getKey() instanceof String)
          {
-            attrs.put((String) entry.getKey(), getUnMarshalledValue(entry.getValue()));
+            String key = (String) entry.getKey();
+            attrs.put(key, unmarshall(realId, key, entry.getValue()));
          }                
       }
       
@@ -201,5 +202,34 @@
          }
       }
    }
+   
+   /**
+    * Utility to catch checked unmarshalling exceptions and rethrow as 
+    * RuntimeException with a context-appropriate message.
+    * 
+    * @param realId the id of session associated with toUnmarshall
+    * @param key the attribute key associated with toUnmarshall
+    * @param toUnmarshall object to unmarshall
+    * 
+    * @return the unmarshalled object
+    * 
+    * @throws RuntimeException if any exception occurs
+    */
+   private Object unmarshall(String realId, String key, Object toUnmarshall)
+   {
+      try
+      {
+         return getUnMarshalledValue(toUnmarshall);
+      }
+      catch (RuntimeException e)
+      {
+         throw e;
+      }
+      catch (Exception e)
+      {
+         throw new RuntimeException("Caught exception unmarshalling attribute " + key + " for session " +  Util.maskId(realId), e);
+      }
+      
+   }
 
 }

Modified: projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/IncomingDistributableSessionDataImpl.java
===================================================================
--- projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/IncomingDistributableSessionDataImpl.java	2009-10-23 20:10:20 UTC (rev 95524)
+++ projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/IncomingDistributableSessionDataImpl.java	2009-10-23 20:50:55 UTC (rev 95525)
@@ -42,6 +42,22 @@
    private final Map<String, Object> attributes;
    
    public IncomingDistributableSessionDataImpl(Integer version, Long timestamp, 
+                                              DistributableSessionMetadata metadata)
+   {
+      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 = null;
+   }
+   
+   public IncomingDistributableSessionDataImpl(Integer version, Long timestamp, 
                                               DistributableSessionMetadata metadata,
                                               Map<String, Object> attributes)
    {
@@ -51,6 +67,8 @@
          throw new IllegalStateException("timestamp is null");
       if (metadata == null)
          throw new IllegalStateException("metadata is null");
+      if (attributes == null)
+         throw new IllegalStateException("attributes is null");
       
       this.version = version.intValue();
       this.timestamp = timestamp.longValue();

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-10-23 20:10:20 UTC (rev 95524)
+++ projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/SessionBasedJBossCacheService.java	2009-10-23 20:50:55 UTC (rev 95525)
@@ -21,7 +21,6 @@
 */
 package org.jboss.web.tomcat.service.session.distributedcache.impl.jbc;
 
-import java.util.Collections;
 import java.util.Map;
 import java.util.Set;
 
@@ -111,8 +110,18 @@
    @SuppressWarnings("unchecked")
    protected Map<String, Object> getSessionAttributes(String realId, Map<Object, Object> distributedCacheData)
    {
-      Map<String, Object> result = (Map<String, Object>) getUnMarshalledValue(distributedCacheData.get(ATTRIBUTE_KEY));
-      return result == null ? Collections.EMPTY_MAP : result;
+      try
+      {
+         return (Map<String, Object>) getUnMarshalledValue(distributedCacheData.get(ATTRIBUTE_KEY));
+      }
+      catch (RuntimeException e)
+      {
+         throw e;
+      }
+      catch (Exception e)
+      {
+         throw new RuntimeException("Caught exception unmarshalling attribute map for session " +  Util.maskId(realId), e);
+      }
    }
 
    @Override

Modified: projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/Util.java
===================================================================
--- projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/Util.java	2009-10-23 20:10:20 UTC (rev 95524)
+++ projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/Util.java	2009-10-23 20:50:55 UTC (rev 95525)
@@ -128,6 +128,26 @@
       return cm;
    }
    
+   public static String maskId(String realId)
+   {
+      if (realId == null)
+      {
+         return null;
+      }
+      else
+      {
+         int length = realId.length();
+         if (length <= 8)
+         {
+            return realId;
+         }
+         StringBuilder sb = new StringBuilder(realId.substring(0, 2));
+         sb.append("****");
+         sb.append(sb.substring(length - 6, length));
+         return sb.toString();
+      }
+   }
+   
    /**
     * Prevent instantiation.
     */




More information about the jboss-cvs-commits mailing list